This is a sample code that uses the Sentilo Nodejs Client Library. The server application file is the server.js file, that imports the library.
First of all it is mandatory to install the local dependencies through npm.
Use the following command:
$ npm install
You must apply a few changes in your code in order to complete the sample configuration.
Follow next steps to configure this sample:
- Download and put in the same directory the Sentilo's Nodejs client library and this sample code
- Edit the server.js file to set your Sentilo instance configurations, and replace the sequences YOUR-SENTILO-INSTANCE-XXX with your custom configurations as it corresponds, such some like this:
var samplesOptions = { host : 'YOUR-SENTILO-INSTANCE-HOST-IP', port : 'YOUR-SENTILO-INSTANCE-HOST-PORT', headers : { identity_key : 'YOUR_SENTILO-INSTANCE-DEFAULT-IDENTITY-KEY' } tokenId : 'YOUR-SENTILO-INSTANCE-IDENTITY-KEY', providerTokenId : 'YOUR-SENTILO-INSTANCE-PROVIDER-IDENTITY-KEY', providerId : 'samples-provider', sensorId : 'sample-sensor-nodejs', componentType : 'generic', sensorDataType : 'TEXT', sensorType : 'status', sensorUnit : '', sensorLocation: '41.4122494 2.2101553' };
Note that the sensor type must already exist.
Once you have imported and initialized the sentilo-client-nodejs library, you can invoke the services that you'll find in the node_modules/sentilo-client-nodejs/sentilo.js file (this is a simple wrapper to the service files):
- init : initialize all library client services
- existsSensorInCatalog : test if is there the sensor in the catalog
- createSensor : create the sensor in the catalog
- publishObservations : publish observations to the Sentilo instance
- createAlerts : create alerts passed as list
- publishAlarm : publish an alarm for an alert
For more information, please look at https://github.com/sentilo/sentilo-client-nodejs, where you'll find all the available services.
Run the sample by typping in bash:
$ node server.js