Socket
Socket
Sign inDemoInstall

node-sitewhere

Package Overview
Dependencies
119
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    node-sitewhere

node-sitewhere


Version published
Weekly downloads
0
Maintainers
1
Created
Weekly downloads
 

Readme

Source

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.

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
[topic]Stringconfig.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
[level]String'Info'Alert level of content Info
[metadata]StringAlert 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
[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

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
[namespace]String'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.

Keywords

FAQs

Last updated on 02 Jun 2017

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc