0.0.3 • Published 7 years ago

node-sitewhere v0.0.3

Weekly downloads
2
License
MIT
Repository
github
Last release
7 years ago

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

ParamTypeDescription
configObjectConfiguration object containing Sitewhere config settings.

sitewhere.config : object

Options Object

Kind: instance namespace of Sitewhere
Properties

NameTypeDefaultDescription
urlstring"http://localhost:8080/sitewhere/api"Sitewhere API URL
usernamestring"admin"Sitewhere API Username
passwordstring"password"Sitewhere API Password
mqttServerstring"localhost"hostname/ip of MQTT Server (i.e 1.2.3.4 or mqtt.example.com)
mqttPortstring1883Port for MQTT Server
tenantAuthenticationTokenstring"sitewhere1234567890"Tenant AuthenticationToken that defaults to the "default" tenant included with sitewhere install (optional)
mqttPrefixTopicstring"Sitewhere"Default Topic Prefix that is used to construct mqttTopic, mqttCommandsTopicPrefix, mqttSystemTopicPrefix if not speficied in config (optional)
mqttTopicstring"mqttPrefixTopic+'/input/json'"Default Sitewhere publish topic (optional)
mqttCommandsTopicPrefixstring"mqttPrefixTopic+'/commands/'"Used to subscribe to device Sitewhere 'commands' topic (optional)
mqttSystemTopicPrefixstring"mqttPrefixTopic+'/system/'"Used to subscribe to Sitewhere 'system' topic (optional)

Sitewhere.mqtt : Object

Mqtt Object

Kind: static property of Sitewhere

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

ParamTypeDefault
messageString
topicStringconfig.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

ParamType
hardwareIdString

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

ParamType
hardwareIdString

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

ParamTypeDescription
hardwareIdStringDevice Hardware ID
originatingEventIdStringOriginating Event ID that is being acknowledged
responseStringResponse 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

ParamTypeDefaultDescription
hardwareIdStringDevice Hardware ID
typeStringAlert type (short name)
messageStringAlert message
levelString'Info'Alert level of content InfoWarningErrorCritical (optional, defaults to 'Info')
metadataStringAlert 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

ParamTypeDefaultDescription
hardwareIdStringDevice Hardware ID
latitudeStringLatitude
longitudeStringLongitude
elevationString'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

ParamTypeDescription
hardwareIdStringDevice Hardware ID
measurementsObjectObject 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

ParamTypeDescription
hardwareIdStringDevice Hardware ID
specificationTokenStringDevice Specification Token
siteTokenStringSite Token for site under which device is created

Sitewhere.http : Object

Http Object

Kind: static property of Sitewhere

http.getEngineConfig(enantId) ⇒ Promise.<EngineConfig>

Get engine config.

Kind: static method of http

ParamType
enantIdString

http.engineStart(tenantId) ⇒ Promise

Start Tenant Engine.

Kind: static method of http

ParamType
tenantIdString

http.engineStop(tenantId) ⇒ Promise

Stop Tenant Engine.

Kind: static method of http

ParamType
tenantIdString

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

ParamType
tenantIdString

http.createTenant(tenant) ⇒ Promise.<Tenant>

Create Tenant.

Kind: static method of http

ParamType
tenantTenant

http.updateTenant(tenantid, tenant) ⇒ Promise.<Tenant>

Update Tenant.

Kind: static method of http

ParamType
tenantidString
tenantTenant

http.createSite(site) ⇒ Promise.<Site>

Create Site.

Kind: static method of http

ParamType
siteSite

http.createZone(siteToken, zone) ⇒ Promise.<Zone>

Create Zone.

Kind: static method of http

ParamType
siteTokenstring
zoneZone

http.createAssetCategory(assetCategory) ⇒ Promise.<AssetCategory>

Create AssetCategory.

Kind: static method of http

ParamType
assetCategoryAssetCategory

http.createHardwareAsset(assetCategoryId, hardwareAsset) ⇒ Promise.<HardwareAsset>

Create HardwareAsset.

Kind: static method of http

ParamType
assetCategoryIdstring
hardwareAssetHardwareAsset

http.createPersonAsset(assetCategoryId, personAsset) ⇒ Promise.<PersonAsset>

Create PersonAsset.

Kind: static method of http

ParamType
assetCategoryIdstring
personAssetPersonAsset

http.createLocationAsset(assetCategoryId, locationAsset) ⇒ Promise.<LocationAsset>

Create LocationAsset.

Kind: static method of http

ParamType
assetCategoryIdstring
locationAssetLocationAsset

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

ParamType
deviceSpecDeviceSpec

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

NameType
hardwareIdString
typeString
requestAcknowledgeRequest

Alert : object

Alert Object

Kind: global namespace
Properties

NameType
hardwareIdString
typeString
requestAlertRequest

Location : object

Locaton Object

Kind: global namespace
Properties

NameType
hardwareIdString
typeString
requestLocationRequest

Measurements : object

Measurements Object

Kind: global namespace
Properties

NameType
hardwareIdString
typeString
requestMeasurementsRequest

Registration : object

Registration Object

Kind: global namespace
Properties

NameType
hardwareIdString
typeString
requestRegistrationRequest

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

ParamTypeDescription
sitewhereSitewhereinitialized sitewhere class instance
hardwareIdStringhardware 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

ParamTypeDefault
namespaceString'Default'
nameString
fnfunction

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

NameType
responseString
originatingEventIdString
updateStateString
eventDateString

~AlertRequest : object

Alert Request Object

Kind: inner namespace
Properties

NameType
typeString
levelString
messageString
updateStateString
eventDateString

~LocationRequest : object

Locaton Request Object

Kind: inner namespace
Properties

NameType
latitudeString
longitudeString
elevationString
updateStateString
eventDateString

~MeasurementsRequest : object

Measurements Request Object

Kind: inner namespace
Properties

NameType
measurementsObject
updateStateString
eventDateString

~RegistrationRequest : object

Registration Request Object

Kind: inner namespace
Properties

NameType
hardwareIdString
specificationTokenString
siteTokenString

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.