The Javascript SDK to enable messaging on your devices
$ npm install barracks-messenger-sdk
var BarracksMessenger = require('../src/index').BarracksMessenger;
var barracksMessenger = new BarracksMessenger({
apiKey: 'Your user API key',
unitId: 'The unique device identifier'
});
Your user API key you can be found on the Account page of the Barracks application.
barracksMessenger.connect({
onConnect: function() {
// Do something when your device connects to MQTT
},
onError: function(err) {
// Do something when an error occurs
},
onClose: function() {
// Do something when the connection is closed
},
onReconnect: function() {
// Do somethings when the device attempts to reconnect
}
});
barracksMessenger.subscribe(function (messageReceived) {
// Do something with a message when you retrieve it
}, { qos: 1 });
A message object has 5 properties :
- payload : String
- retained : boolean
- topic : String
- length : int
- qos : 0 or 1
barracksMessenger.end();
- Website and Documentation
- Github Organization for other official SDKs