Home

Awesome

node-meshblu-amqp

AMQP client library for Meshblu

Build Status Code Climate Test Coverage npm version Gitter

Install

npm install meshblu-xmpp

Example Usage

Set-up

var meshblu = require('meshblu-amqp');

var config = {
  'hostname': 'meshblu-amqp.octoblu.com',
  'port': 5672,
  'uuid': '',
  'token': ''
}

var conn = new meshblu(config);

conn.connect(function(data){

}); // conn.connect

Send Message

conn.message({"devices": ["*"], "payload": "duuude"}, function(result){
  console.log('Send Message: ', result);
});

On Message

// Message handler
conn.on('message', function(message){
  console.log('Message Received: ', message);
});

Create Session Token

conn.createSessionToken(config.uuid, {"createdAt": Date.now()},
function(err, result){
  console.log('Create Session Token: ', result);
});

Check status of Meshblu

conn.status(function(err, result){
  console.log('Status:', result);
});

Whoami

conn.whoami(function(err, result){
  console.log('Whoami: ', result);
});

Update

// Update a specific device - you can add arbitrary json
conn.update(config.uuid, { "$set": {"type": "device:generic"}}, function(err, device){
  console.log('Update Device:', device);
});

Register

// Register a new device
conn.register({"type": "device:generic"}, function(err, device){
  console.log('Register Device: ', device);
});

Subscribe

// Subscribe to your own messages to enable recieving them
// conn.unsubscribe takes the same arguments
var subscription = {
  "subscriberUuid" : config.uuid,
  "emitterUuid": config.uuid,
  "type": 'message.received'
};
conn.subscribe(config.uuid, subscription, function(err, result){
  console.log('Subscribe: ', result);
});

Search Devices

// Search for devices by a query
var query = {
  "type": "device:generic"
};
conn.searchDevices(config.uuid, query, function(err, result){
  console.log('Search Devices: ', result);
  console.log(err);
});

Testing

You'll need to add some users to your test rabbitmq instance

rabbitmqctl add_user meshblu judgementday
rabbitmqctl set_permissions meshblu ".*" ".*" ".*"
rabbitmqctl add_user some-uuid some-token
rabbitmqctl set_permissions some-uuid '^(amq\.gen.*|amq\.default|^some-uuid.*)$' '.*' '.*'