slv-api is a JavaScript tool that makes sensor integration with SLV quick and easy. slv-api includes a module that connects to SLV for data retrieval, device integration, and data publishing from sensor devices. slv-api also includes sample programs that illustrate how to perform common operations with the SLV platform. Integration with SLV allows IoT innovators to quickly deploy sensor applications to leading cities and utilities around the world!
Connect to SLV and List Geozones
const slv = require ('./slv_api.js');
//First set the SLV user's authorization credentials
slv.setAuthString('username','password');
//Connect to SLV
slv.connect().then((data) => {
//Retrieve and display a list of Geozones associated with your SLV user account.
slv.getAllGeozones().then((geozones) => {
console.log(geozones);
});
});
List Devices within a Geozone
const slv = require ('./slv_api.js');
const fs = require('fs');
slv.setAuthString('username','password');
slv.connect().then((data) => {
//retrieve devices from SLV Geozone
const GEOZONE_ID = 12345;
//Use the getGeozoneDevices function to retrieve all devices within the supplied Geozone.
slv.getGeozoneDevices(GEOZONE_ID)
.then((data) => {
//Print the JSON data structure listing all devices
console.log("Devices retrieved! " + data);
})
.catch((err) => {console.error("Unable to retrieve devices from geozone: " + err);})
});
Create a New Device in SLV
const slv = require ('./slv_api.js');
const CONTROLLER_ID = 'OSCPController001';
const DEVICE_NAME = 'NewDeviceName';
const CATEGORY = 'parkingPlace';
//Connect to SLV
slv.setAuthString('username','password');
slv.connect().then((data) => {
const GEOZONE_ID = 12345;
//Create a new sensor device
let parkingPlace = {};
parkingPlace["controllerStrId"] = CONTROLLER_ID;
parkingPlace["idOnController"] = DEVICE_NAME;
parkingPlace["userName"] = DEVICE_NAME;
parkingPlace["categoryStrId"] = CATEGORY;
parkingPlace["geoZoneId"] = GEOZONE_ID;
parkingPlace["lat"] = '29.430844254516185';
parkingPlace["lng"] = '-98.49308974533695';
slv.createDevice(parkingPlace)
.then((data) => {
console.log("Device created! " + data);
})
.catch((err) => {console.error("Unable to create new parking place: " + err);})
});
Update Device Data in SLV
slv.createDevice(parkingPlace)
.then((data) => {
console.log("Device created! " + data);
//Send SLV updated values for both measured and static attributes.
let parkingData = {};
parkingData["controllerStrId"] = CONTROLLER_ID;
parkingData["idOnController"] = DEVICE_NAME;
//The valueName element is set to an array of attribute names,
//some of which are static (SerialNumber), and some of which are measured (OccupiedSpaces)
parkingData["valueName"] = ["Manufacturer","SerialNumber","SamplingPeriod","TotalParkingSpaces", "OccupiedSpaces","SpacePercentageAvailable","VehiclesStayLess15Count","VehiclesStayMore15Count","VehiclesStayMore240Count"];
parkingData["value"] = ['ACME','4652','60','100','20','80%','0','15','5'];
slv.sendDeviceValues(parkingData).then((updateResult) => {
console.log("Device " + DEVICE_NAME + " updated: " + updateResult);
})
.catch((err) => {console.error("Unable to update parking place: " + err);})
})