node-sitewhere
Library and inline docs in progress and subject to change...
Example:
const Sitewhere = require('node-sitewhere');
let config = {
url: 'http://localhost:8080/sitewhere/api',
username: 'admin',
password: 'password',
mqttServer: 'localhost',
mqttPort: '1883'
};
let sitewhere = new Sitewhere(config);
sitewhere.mqtt.connect()
.then(mqtt => mqtt.sendAlert('DEVICE001', 'Test', 'This is a test.'))
.catch(err => console.log(err.message));
sitewhere.http.getTenants()
.then(tenants => console.log(tenants))
.catch(err => console.log(err.message));
Objects
-
Sitewhere :
object
-
Creates an instance of Sitewhere class.
-
Acknowledge :
object
-
Acknowledge Object
-
Alert :
object
-
Alert Object
-
Location :
object
-
Locaton Object
-
Measurements :
object
-
Measurements Object
-
Registration :
object
-
Registration Object
-
DeviceCommander :
object
-
Creates an instance of DeviceCommander class.
This utility class attempts to extend some of the basic API features of node-sitewhere to allow the creation, execution, and response acknowlegement of Sitewhere to Device to Sitewhere communications over MQTT.
object
Sitewhere : Creates an instance of Sitewhere class.
Kind: global namespace
Param | Type | Description |
---|---|---|
config | Object |
Configuration object containing Sitewhere config settings. |
-
Sitewhere :
object
-
instance
-
.config :
object
-
.config :
-
static
-
.mqtt :
Object
-
.commands :
Object
-
.system :
Object
-
.disconnect() ⇒
Promise.<mqtt>
-
.publish(message, [topic]) ⇒
Promise.<mqtt>
-
.subscribe(hardwareId) ⇒
Promise.<mqtt>
-
.unsubscribe(hardwareId) ⇒
Promise.<mqtt>
-
.sendAcknowledge(hardwareId, originatingEventId, response) ⇒
Promise.<mqtt>
-
.sendAlert(hardwareId, type, message, [level], [metadata]) ⇒
Promise.<mqtt>
-
.sendLocation(hardwareId, latitude, longitude, [elevation]) ⇒
Promise.<mqtt>
-
.sendMeasurements(hardwareId, measurements) ⇒
Promise.<mqtt>
-
.sendRegistration(hardwareId, specificationToken, siteToken) ⇒
Promise.<mqtt>
-
.commands :
-
.http :
Object
-
.getEngineConfig(enantId) ⇒
Promise.<EngineConfig>
-
.engineStart(tenantId) ⇒
Promise
-
.engineStop(tenantId) ⇒
Promise
-
.getTenants() ⇒
Promise.<Array.Tenant>
-
.getTenant(tenantId) ⇒
Promise.<Tenant>
-
.createTenant(tenant) ⇒
Promise.<Tenant>
-
.updateTenant(tenantid, tenant) ⇒
Promise.<Tenant>
-
.createSite(site) ⇒
Promise.<Site>
-
.createZone(siteToken, zone) ⇒
Promise.<Zone>
-
.createAssetCategory(assetCategory) ⇒
Promise.<AssetCategory>
-
.createHardwareAsset(assetCategoryId, hardwareAsset) ⇒
Promise.<HardwareAsset>
-
.createPersonAsset(assetCategoryId, personAsset) ⇒
Promise.<PersonAsset>
-
.createLocationAsset(assetCategoryId, locationAsset) ⇒
Promise.<LocationAsset>
-
.getDeviceSpecifications() ⇒
Promise.<Array.DeviceSpecification>
-
.createDeviceSpecification(deviceSpec) ⇒
Promise.<DeviceSpec>
-
.getDevices() ⇒
Promise.<Array.Device>
-
.getUsers() ⇒
Promise.<Array.User>
-
.getTemplates() ⇒
Promise.<Array.Template>
-
.getEngineConfig(enantId) ⇒
-
.mqtt :
-
instance
object
sitewhere.config : Options Object
Kind: instance namespace of Sitewhere
Properties
Name | Type | Default | Description |
---|---|---|---|
url | string |
"http://localhost:8080/sitewhere/api" |
Sitewhere API URL |
username | string |
"admin" |
Sitewhere API Username |
password | string |
"password" |
Sitewhere API Password |
mqttServer | string |
"localhost" |
hostname/ip of MQTT Server (i.e 1.2.3.4 or mqtt.example.com) |
mqttPort | string |
1883 |
Port for MQTT Server |
tenantAuthenticationToken | string |
"sitewhere1234567890" |
Tenant AuthenticationToken that defaults to the "default" tenant included with sitewhere install (optional) |
mqttPrefixTopic | string |
"Sitewhere" |
Default Topic Prefix that is used to construct mqttTopic, mqttCommandsTopicPrefix, mqttSystemTopicPrefix if not speficied in config (optional) |
mqttTopic | string |
"mqttPrefixTopic+'/input/json'" |
Default Sitewhere publish topic (optional) |
mqttCommandsTopicPrefix | string |
"mqttPrefixTopic+'/commands/'" |
Used to subscribe to device Sitewhere 'commands' topic (optional) |
mqttSystemTopicPrefix | string |
"mqttPrefixTopic+'/system/'" |
Used to subscribe to Sitewhere 'system' topic (optional) |
Object
Sitewhere.mqtt : Mqtt Object
Kind: static property of Sitewhere
-
.mqtt :
Object
-
.commands :
Object
-
.system :
Object
-
.disconnect() ⇒
Promise.<mqtt>
-
.publish(message, [topic]) ⇒
Promise.<mqtt>
-
.subscribe(hardwareId) ⇒
Promise.<mqtt>
-
.unsubscribe(hardwareId) ⇒
Promise.<mqtt>
-
.sendAcknowledge(hardwareId, originatingEventId, response) ⇒
Promise.<mqtt>
-
.sendAlert(hardwareId, type, message, [level], [metadata]) ⇒
Promise.<mqtt>
-
.sendLocation(hardwareId, latitude, longitude, [elevation]) ⇒
Promise.<mqtt>
-
.sendMeasurements(hardwareId, measurements) ⇒
Promise.<mqtt>
-
.sendRegistration(hardwareId, specificationToken, siteToken) ⇒
Promise.<mqtt>
-
.commands :
Object
mqtt.commands : Sitewhere inbound Commands messages Emmitter
Kind: static property of mqtt
Object
mqtt.system : Sitewhare inbound System messages Emmitter
Kind: static property of mqtt
Promise.<mqtt>
mqtt.disconnect() ⇒ Disconnects mqtt client if connected.
Kind: static method of mqtt
Returns: Promise.<mqtt>
- Sitewhere.mqtt
Promise.<mqtt>
mqtt.publish(message, [topic]) ⇒ Publish message.
Kind: static method of mqtt
Returns: Promise.<mqtt>
- Sitewhere.mqtt
Param | Type | Default |
---|---|---|
message | String |
|
[topic] | String |
config.mqttTopic |
Promise.<mqtt>
mqtt.subscribe(hardwareId) ⇒ Subscribe to MQTT topics for commands and system events by Hardware ID
Kind: static method of mqtt
Returns: Promise.<mqtt>
- Sitewhere.mqtt
Param | Type |
---|---|
hardwareId | String |
Promise.<mqtt>
mqtt.unsubscribe(hardwareId) ⇒ Unsubscribe to MQTT topics for commands and system events by Hardware ID
Kind: static method of mqtt
Returns: Promise.<mqtt>
- Sitewhere.mqtt
Param | Type |
---|---|
hardwareId | String |
Promise.<mqtt>
mqtt.sendAcknowledge(hardwareId, originatingEventId, response) ⇒ Send MQTT Acknowledge to Sitewhere. Can also accept Acknowledge object as only argument.
Kind: static method of mqtt
Returns: Promise.<mqtt>
- Sitewhere.mqtt object
Param | Type | Description |
---|---|---|
hardwareId | String |
Device Hardware ID |
originatingEventId | String |
Originating Event ID that is being acknowledged |
response | String |
Response message to send back to Sitewhere. |
Promise.<mqtt>
mqtt.sendAlert(hardwareId, type, message, [level], [metadata]) ⇒ Send MQTT Alert to Sitewhere. Can also accept Alert object as only argument.
Kind: static method of mqtt
Returns: Promise.<mqtt>
- Sitewhere.mqtt object
Param | Type | Default | Description |
---|---|---|---|
hardwareId | String |
Device Hardware ID | |
type | String |
Alert type (short name) | |
message | String |
Alert message | |
[level] | String |
'Info' |
Alert level of content Info |
[metadata] | String |
Alert metadata (optional) |
Promise.<mqtt>
mqtt.sendLocation(hardwareId, latitude, longitude, [elevation]) ⇒ Send MQTT Location to Sitewhere. Can also accept Location object as only argument.
Kind: static method of mqtt
Returns: Promise.<mqtt>
- Sitewhere.mqtt object
Param | Type | Default | Description |
---|---|---|---|
hardwareId | String |
Device Hardware ID | |
latitude | String |
Latitude | |
longitude | String |
Longitude | |
[elevation] | String |
'0' |
Elevation (optional, defaults to '0') |
Promise.<mqtt>
mqtt.sendMeasurements(hardwareId, measurements) ⇒ Send MQTT Measuments to Sitewhere. Can also accept Measurements object as only argument.
Kind: static method of mqtt
Returns: Promise.<mqtt>
- Sitewhere.mqtt object
Param | Type | Description |
---|---|---|
hardwareId | String |
Device Hardware ID |
measurements | Object |
Object containing key / value pairs |
Promise.<mqtt>
mqtt.sendRegistration(hardwareId, specificationToken, siteToken) ⇒ Send MQTT Registration to Sitewhere. Can also accept Registration object as only argument.
Kind: static method of mqtt
Returns: Promise.<mqtt>
- Sitewhere.mqtt object
Param | Type | Description |
---|---|---|
hardwareId | String |
Device Hardware ID |
specificationToken | String |
Device Specification Token |
siteToken | String |
Site Token for site under which device is created |
Object
Sitewhere.http : Http Object
Kind: static property of Sitewhere
-
.http :
Object
-
.getEngineConfig(enantId) ⇒
Promise.<EngineConfig>
-
.engineStart(tenantId) ⇒
Promise
-
.engineStop(tenantId) ⇒
Promise
-
.getTenants() ⇒
Promise.<Array.Tenant>
-
.getTenant(tenantId) ⇒
Promise.<Tenant>
-
.createTenant(tenant) ⇒
Promise.<Tenant>
-
.updateTenant(tenantid, tenant) ⇒
Promise.<Tenant>
-
.createSite(site) ⇒
Promise.<Site>
-
.createZone(siteToken, zone) ⇒
Promise.<Zone>
-
.createAssetCategory(assetCategory) ⇒
Promise.<AssetCategory>
-
.createHardwareAsset(assetCategoryId, hardwareAsset) ⇒
Promise.<HardwareAsset>
-
.createPersonAsset(assetCategoryId, personAsset) ⇒
Promise.<PersonAsset>
-
.createLocationAsset(assetCategoryId, locationAsset) ⇒
Promise.<LocationAsset>
-
.getDeviceSpecifications() ⇒
Promise.<Array.DeviceSpecification>
-
.createDeviceSpecification(deviceSpec) ⇒
Promise.<DeviceSpec>
-
.getDevices() ⇒
Promise.<Array.Device>
-
.getUsers() ⇒
Promise.<Array.User>
-
.getTemplates() ⇒
Promise.<Array.Template>
-
.getEngineConfig(enantId) ⇒
Promise.<EngineConfig>
http.getEngineConfig(enantId) ⇒ Get engine config.
Kind: static method of http
Param | Type |
---|---|
enantId | String |
Promise
http.engineStart(tenantId) ⇒ Start Tenant Engine.
Kind: static method of http
Param | Type |
---|---|
tenantId | String |
Promise
http.engineStop(tenantId) ⇒ Stop Tenant Engine.
Kind: static method of http
Param | Type |
---|---|
tenantId | String |
Promise.<Array.Tenant>
http.getTenants() ⇒ Get Sitewhere Tenants.
Kind: static method of http
Returns: Promise.<Array.Tenant>
- Array of Tenant objects.
Promise.<Tenant>
http.getTenant(tenantId) ⇒ Get Tenant.
Kind: static method of http
Param | Type |
---|---|
tenantId | String |
Promise.<Tenant>
http.createTenant(tenant) ⇒ Create Tenant.
Kind: static method of http
Param | Type |
---|---|
tenant | Tenant |
Promise.<Tenant>
http.updateTenant(tenantid, tenant) ⇒ Update Tenant.
Kind: static method of http
Param | Type |
---|---|
tenantid | String |
tenant | Tenant |
Promise.<Site>
http.createSite(site) ⇒ Create Site.
Kind: static method of http
Param | Type |
---|---|
site | Site |
Promise.<Zone>
http.createZone(siteToken, zone) ⇒ Create Zone.
Kind: static method of http
Param | Type |
---|---|
siteToken | string |
zone | Zone |
Promise.<AssetCategory>
http.createAssetCategory(assetCategory) ⇒ Create AssetCategory.
Kind: static method of http
Param | Type |
---|---|
assetCategory | AssetCategory |
Promise.<HardwareAsset>
http.createHardwareAsset(assetCategoryId, hardwareAsset) ⇒ Create HardwareAsset.
Kind: static method of http
Param | Type |
---|---|
assetCategoryId | string |
hardwareAsset | HardwareAsset |
Promise.<PersonAsset>
http.createPersonAsset(assetCategoryId, personAsset) ⇒ Create PersonAsset.
Kind: static method of http
Param | Type |
---|---|
assetCategoryId | string |
personAsset | PersonAsset |
Promise.<LocationAsset>
http.createLocationAsset(assetCategoryId, locationAsset) ⇒ Create LocationAsset.
Kind: static method of http
Param | Type |
---|---|
assetCategoryId | string |
locationAsset | LocationAsset |
Promise.<Array.DeviceSpecification>
http.getDeviceSpecifications() ⇒ Get Sitewhere Device Specifications.
Kind: static method of http
Returns: Promise.<Array.DeviceSpecification>
- Array of DeviceSpecification objects.
Promise.<DeviceSpec>
http.createDeviceSpecification(deviceSpec) ⇒ Create Device Spec.
Kind: static method of http
Param | Type |
---|---|
deviceSpec | DeviceSpec |
Promise.<Array.Device>
http.getDevices() ⇒ Get Sitewhere Devices.
Kind: static method of http
Returns: Promise.<Array.Device>
- Array of Device objects.
Promise.<Array.User>
http.getUsers() ⇒ Get Sitewhere Users.
Kind: static method of http
Returns: Promise.<Array.User>
- Array of User objects.
Promise.<Array.Template>
http.getTemplates() ⇒ Get Sitewhere Templates.
Kind: static method of http
Returns: Promise.<Array.Template>
- Array of Template objects.
object
Acknowledge : Acknowledge Object
Kind: global namespace
Properties
Name | Type |
---|---|
hardwareId | String |
type | String |
request | AcknowledgeRequest |
object
Alert : Alert Object
Kind: global namespace
Properties
Name | Type |
---|---|
hardwareId | String |
type | String |
request | AlertRequest |
object
Location : Locaton Object
Kind: global namespace
Properties
Name | Type |
---|---|
hardwareId | String |
type | String |
request | LocationRequest |
object
Measurements : Measurements Object
Kind: global namespace
Properties
Name | Type |
---|---|
hardwareId | String |
type | String |
request | MeasurementsRequest |
object
Registration : Registration Object
Kind: global namespace
Properties
Name | Type |
---|---|
hardwareId | String |
type | String |
request | RegistrationRequest |
object
DeviceCommander : Creates an instance of DeviceCommander class.
This utility class attempts to extend some of the basic API features of node-sitewhere to allow the creation, execution, and response acknowlegement of Sitewhere to Device to Sitewhere communications over MQTT.
Kind: global namespace
Param | Type | Description |
---|---|---|
sitewhere | Sitewhere |
initialized sitewhere class instance |
hardwareId | String |
hardware id of device to associate the command with. |
Promise
DeviceCommander.register([namespace], name, fn) ⇒ Register a function to a Sitewhere command by namespace and name.
Namespace and name must match a Sitewhere Device Spec command. In the Device Spec Commmand, an optional parameter "args" of type "String" may be defined. When executing the command from Sitewhere, the args string should be a comma seperated string of values. Each value will be passed to the function as individual "string" arguments. The function may return a value or a promise. The returned value/promise will display in sitehwere under "Command Responses". If the function does not produce a return value, or if the return value is not either of type object or type string, the "Command Response" will show "Auto acknowleged".
Note: You must set Tenant Configuration/Device Communication/Device Command Routing/Specification Mapping Router to use a default destination of "json" or create a new mapping for each Device Specification(s) that your devices are assigned to. This mapping should specify a "Destination ID" of "json".
Kind: static method of DeviceCommander
Param | Type | Default |
---|---|---|
[namespace] | String |
'Default' |
name | String |
|
fn | function |
Example
const Sitewhere = require('node-sitewhere');
const DeviceCommander = require('node-sitewhere/device-commander');
let sitewhere = new Sitewhere();
let device001 = new DeviceCommander(sitewhere, 'DEVICE001');
device001.register('Add3', function(a, b, c) {
// sitewhere command would use namespace Default (or blank)
// sitewhere command would use name "Add3"
// sitewhere command would have string parameter "args"
// when executing the command args could be "5,4,3"
return a + b + c;
// sitewhere Command Response should should show 12.
});
object
~AcknowledgeRequest : Acknowledge Request Object
Kind: inner namespace
Properties
Name | Type |
---|---|
response | String |
originatingEventId | String |
updateState | String |
eventDate | String |
object
~AlertRequest : Alert Request Object
Kind: inner namespace
Properties
Name | Type |
---|---|
type | String |
level | String |
message | String |
updateState | String |
eventDate | String |
object
~LocationRequest : Locaton Request Object
Kind: inner namespace
Properties
Name | Type |
---|---|
latitude | String |
longitude | String |
elevation | String |
updateState | String |
eventDate | String |
object
~MeasurementsRequest : Measurements Request Object
Kind: inner namespace
Properties
Name | Type |
---|---|
measurements | Object |
updateState | String |
eventDate | String |
object
~RegistrationRequest : Registration Request Object
Kind: inner namespace
Properties
Name | Type |
---|---|
hardwareId | String |
specificationToken | String |
siteToken | String |
License
The MIT License (MIT)
Copyright (c) 2016-2017
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.