The thingface client library for NodeJS
NPM Package for Thingface Platform
Installation
npm install thingface --save
Code Example
A few lines of code and you're ready to control or monitor your device.
var thingface = ; { ifcommandName === "say" console; } thingface thingface;
API Reference
API is very simple. Have a look to api reference.
thingface.connect(deviceId, deviceSecretKey, host, port, enableSsl)
connect to the thingface device gateway specified by the given host name with current device ID and device secret key.
deviceId
- device IDdeviceSecretKey
- secret key for that devicehost
(optional) - device gateway hostname (default personal.thingface.io)port
(optional) - device gateway port (default 8883 for SSL connection, 1883 for no SSL connection)enableSsl
(optional) - enable SSL connection (default true)
thingface.disconnect()
disconnect from thingface device gateway
thingface.isConnected()
returns true if this client is connected, otherwise it returns false. Use it everytime when you need to check if device is connected or not.
thingface.onConnectionState(eventHandlerFn)
connection state event handling
eventHandlerFn
- a function to handle connection state event
thingface.onCommand(commandHandler[, senderType][, senderId])
subscribe for commands from sender
commandHandler
- a function to handle commandssenderType
(optional) - sender type ('u' - user command, 'd' - device command), if sender type is not provided device will receive commands from every user or devicesenderId
(optional) - sender ID (username or device ID), if sender ID is not provided device will receive commands from every user or device
thingface.sendSensorValue(sensorId, sensorValue)
send sensor value to thingface gateway
sensorId
- sensor ID from the devicesensorValue
- current sensor value (as double type)