node-sitewhere v0.0.3
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.
Kind: global namespace
Param | Type | Description |
---|---|---|
config | Object | Configuration object containing Sitewhere config settings. |
- Sitewhere : object
- instance
- .config : object
- 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>
- .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>
- .mqtt : Object
- instance
sitewhere.config : object
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) |
Sitewhere.mqtt : Object
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>
mqtt.commands : Object
Sitewhere inbound Commands messages Emmitter
Kind: static property of mqtt
mqtt.system : Object
Sitewhare inbound System messages Emmitter
Kind: static property of mqtt
mqtt.disconnect() ⇒ Promise.<mqtt>
Disconnects mqtt client if connected.
Kind: static method of mqtt
Returns: Promise.<mqtt> - Sitewhere.mqtt
mqtt.publish(message, topic) ⇒ Promise.<mqtt>
Publish message.
Kind: static method of mqtt
Returns: Promise.<mqtt> - Sitewhere.mqtt
Param | Type | Default |
---|---|---|
message | String | |
topic | String | config.mqttTopic |
mqtt.subscribe(hardwareId) ⇒ Promise.<mqtt>
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 |
mqtt.unsubscribe(hardwareId) ⇒ Promise.<mqtt>
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 |
mqtt.sendAcknowledge(hardwareId, originatingEventId, response) ⇒ Promise.<mqtt>
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. |
mqtt.sendAlert(hardwareId, type, message, level, metadata) ⇒ Promise.<mqtt>
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 | Warning | Error | Critical (optional, defaults to 'Info') |
metadata | String | Alert metadata (optional) |
mqtt.sendLocation(hardwareId, latitude, longitude, elevation) ⇒ Promise.<mqtt>
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') |
mqtt.sendMeasurements(hardwareId, measurements) ⇒ Promise.<mqtt>
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 |
mqtt.sendRegistration(hardwareId, specificationToken, siteToken) ⇒ Promise.<mqtt>
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 |
Sitewhere.http : Object
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>
http.getEngineConfig(enantId) ⇒ Promise.<EngineConfig>
Get engine config.
Kind: static method of http
Param | Type |
---|---|
enantId | String |
http.engineStart(tenantId) ⇒ Promise
Start Tenant Engine.
Kind: static method of http
Param | Type |
---|---|
tenantId | String |
http.engineStop(tenantId) ⇒ Promise
Stop Tenant Engine.
Kind: static method of http
Param | Type |
---|---|
tenantId | String |
http.getTenants() ⇒ Promise.<Array.Tenant>
Get Sitewhere Tenants.
Kind: static method of http
Returns: Promise.<Array.Tenant> - Array of Tenant objects.
http.getTenant(tenantId) ⇒ Promise.<Tenant>
Get Tenant.
Kind: static method of http
Param | Type |
---|---|
tenantId | String |
http.createTenant(tenant) ⇒ Promise.<Tenant>
Create Tenant.
Kind: static method of http
Param | Type |
---|---|
tenant | Tenant |
http.updateTenant(tenantid, tenant) ⇒ Promise.<Tenant>
Update Tenant.
Kind: static method of http
Param | Type |
---|---|
tenantid | String |
tenant | Tenant |
http.createSite(site) ⇒ Promise.<Site>
Create Site.
Kind: static method of http
Param | Type |
---|---|
site | Site |
http.createZone(siteToken, zone) ⇒ Promise.<Zone>
Create Zone.
Kind: static method of http
Param | Type |
---|---|
siteToken | string |
zone | Zone |
http.createAssetCategory(assetCategory) ⇒ Promise.<AssetCategory>
Create AssetCategory.
Kind: static method of http
Param | Type |
---|---|
assetCategory | AssetCategory |
http.createHardwareAsset(assetCategoryId, hardwareAsset) ⇒ Promise.<HardwareAsset>
Create HardwareAsset.
Kind: static method of http
Param | Type |
---|---|
assetCategoryId | string |
hardwareAsset | HardwareAsset |
http.createPersonAsset(assetCategoryId, personAsset) ⇒ Promise.<PersonAsset>
Create PersonAsset.
Kind: static method of http
Param | Type |
---|---|
assetCategoryId | string |
personAsset | PersonAsset |
http.createLocationAsset(assetCategoryId, locationAsset) ⇒ Promise.<LocationAsset>
Create LocationAsset.
Kind: static method of http
Param | Type |
---|---|
assetCategoryId | string |
locationAsset | LocationAsset |
http.getDeviceSpecifications() ⇒ Promise.<Array.DeviceSpecification>
Get Sitewhere Device Specifications.
Kind: static method of http
Returns: Promise.<Array.DeviceSpecification> - Array of DeviceSpecification objects.
http.createDeviceSpecification(deviceSpec) ⇒ Promise.<DeviceSpec>
Create Device Spec.
Kind: static method of http
Param | Type |
---|---|
deviceSpec | DeviceSpec |
http.getDevices() ⇒ Promise.<Array.Device>
Get Sitewhere Devices.
Kind: static method of http
Returns: Promise.<Array.Device> - Array of Device objects.
http.getUsers() ⇒ Promise.<Array.User>
Get Sitewhere Users.
Kind: static method of http
Returns: Promise.<Array.User> - Array of User objects.
http.getTemplates() ⇒ Promise.<Array.Template>
Get Sitewhere Templates.
Kind: static method of http
Returns: Promise.<Array.Template> - Array of Template objects.
Acknowledge : object
Acknowledge Object
Kind: global namespace
Properties
Name | Type |
---|---|
hardwareId | String |
type | String |
request | AcknowledgeRequest |
Alert : object
Alert Object
Kind: global namespace
Properties
Name | Type |
---|---|
hardwareId | String |
type | String |
request | AlertRequest |
Location : object
Locaton Object
Kind: global namespace
Properties
Name | Type |
---|---|
hardwareId | String |
type | String |
request | LocationRequest |
Measurements : object
Measurements Object
Kind: global namespace
Properties
Name | Type |
---|---|
hardwareId | String |
type | String |
request | MeasurementsRequest |
Registration : object
Registration Object
Kind: global namespace
Properties
Name | Type |
---|---|
hardwareId | String |
type | String |
request | RegistrationRequest |
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.
Kind: global namespace
Param | Type | Description |
---|---|---|
sitewhere | Sitewhere | initialized sitewhere class instance |
hardwareId | String | hardware id of device to associate the command with. |
DeviceCommander.register(namespace, name, fn) ⇒ Promise
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.
});
~AcknowledgeRequest : object
Acknowledge Request Object
Kind: inner namespace
Properties
Name | Type |
---|---|
response | String |
originatingEventId | String |
updateState | String |
eventDate | String |
~AlertRequest : object
Alert Request Object
Kind: inner namespace
Properties
Name | Type |
---|---|
type | String |
level | String |
message | String |
updateState | String |
eventDate | String |
~LocationRequest : object
Locaton Request Object
Kind: inner namespace
Properties
Name | Type |
---|---|
latitude | String |
longitude | String |
elevation | String |
updateState | String |
eventDate | String |
~MeasurementsRequest : object
Measurements Request Object
Kind: inner namespace
Properties
Name | Type |
---|---|
measurements | Object |
updateState | String |
eventDate | String |
~RegistrationRequest : object
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.