1.0.1 • Published 3 years ago

sentilo-client-nodejs v1.0.1

Weekly downloads
-
License
ISC
Repository
github
Last release
3 years ago

Sentilo client library for Node.js v1.0.1

The Sentilo Javascript/Node.js client library code that brings some Sentilo operations that you can include in your own code.

Installation

To install this library via npm, use:

See it at: NPM

Alternatively, use this dependency in your package.json:

Sentilo client configuration options

OptionDescriptionExample value
apiUrlURL of your Sentilo/Thingtia instancehttp://localhost:8081
headers.identity_keytoken of your provider or applicationf7a702ad6....
providerProvider idsamples-provider
sensorSensor Idsample-sensor-nodejs
componentComponent Id, Only used in catalog operations.sample-component
componentTypeType of the component. Only used in catalog operations.generic
sensorDataTypeData type of the sensor. Only used in catalog operations.TEXT
sensorTypeTy of the sensor. Only used in catalog operations.status
sensorUnitUnit of sensor, only used in catalog operations.kW
sensorLocationLat/lon values separated with blank space. Optional41.387015 2.170047

Sentilo client services

MethodDescription
existsSensorInCatalogSearches a sensor in the catalog. Returns boolean
createSensorCreates a sensor in catalog.
publishObservationsPublishes observations.
createAlertsCreates multiple alerts
publishAlarmPublishes Alarm
subscribeOrderSubscribes to a order
subscribeOrderToAllSubscribes to all sensor orders from a provider

_Note: .*Operations.js files expose more API services.

You might as well check Sentilo Node-RED library on Github and on Node-RED

Note that the API documentation is at https://sentilo.readthedocs.io/en/latest/api_docs.html.

Example Usage

const sentilo = require('sentilo');

// Initialize sentilo
const options = {
    apiUrl : 'http://localhost:8081',
    headers : {
           identity_key : 'f7a702ad6b701...'
    },
    provider : 'testApp_provider',
    sensorLocation : '41.387015 2.170047'
};
sentilo.init();

 
// Checks if the sensor exists
const existingSensor = {
     provider: 'testApp_provider',
     sensor: 'TestSensor'
};
sentilo.existsSensorInCatalog(existingSensor);
 
 
// Creates a new sensor
const newSensor = {
     sensor: 'TestNewSensor',
     description: 'TestNewSensorDescription',
     sensorType: 'anemometer',
     sensorDataType: 'JSON',
     component: 'TestGenericSensor',
     componentType : 'generic',
     sensorUnit : 'T',
     sensorLocation : '41.387015 2.170047'
     
}
sentilo.createSensor(newSensor);
 
 
// Send observation to the sensor
const sensorObservation = 'TEST';
sentilo.publishObservations(sensorObservation, newSensor);
 

// Creates a new alert
const newAlert = {
     alerts: [
         {
             id: 'TEST_ALERT_001',
             name: 'TEST_ALERT_001',
             description: 'External test alert 001',
             type: 'EXTERNAL'
         }
     ]
}
sentilo.createAlerts(newAlert);
 

// Publish new alarm associated to the alarm that is registered later
const message = {message: "This is a test alarm over the TEST_ALERT_001"};
let alarmId = newAlert.alerts[0].id;
sentilo.publishAlarm(alarmId, message);
 

// Example of how to subscribe to a sensor order
const endpoint = {endpoint:"http://my-test-server/sentilo/sensor/data/endpoint"};
sentilo.subscribeOrder(endpoint);
 

// Example of how to subscribe to all orders
sentilo.subscribeOrderToAll(endpoint);

You might as well check your example for Raspberry Pi and NodeJS: https://github.com/sentilo/sentilo-client-sample-nodejs

Changelog

v.1.0.1 - Fixed libraries versions, updated README.md file v.1.0.0 - Initial version