Node.js SDK for Borgnix. Provide an MQTT connection with validation.
npm i borgnix-sdk
var borgnixSDK = require('borgnix-sdk')
, dev = new borgnixSDK.Device( DEVICE_UUID, DEIVCE_TOKEN)
dev.connect(function () {
console.log('[INFO] device connected')
dev.send('dev_up')
dev.on('message', function(payload) {
console.log('[MSG]', payload)
dev.disconnect()
})
})
Create a new device with uuid and token.
Connect to borgnix MQTT broker.
Disconnect from borgnix MQTT broker.
Send message to borgnix MQTT broker.
If optionalTopic
is given, the message published can be recieved by a Borgnix device node which has optionalTopic
in subTopic.
Subscribe an additional topic apart from the default topic.
The topic is diffrent from a MQTT topic.
Once subscribed, the device can recieve message sent by a Borgnix device node with topic
in subTopic.
example
dev.subscribe('specialtopic', function (message) {
console.log(message)
})
Unsubscribe a previously subscribed topic.
Fired when the device is connected to Borgnix.
Fired when the device recieve a message under the default topic.