Connect to Octoblu and send/receive messages

Create a file called "index.js" with the code below:

var meshblu = require('meshblu');

// Not specifying a UUID/Token auto-registers a new device
var conn = meshblu.createConnection({
    "server": "meshblu.octoblu.com",
    "port": 80
});

conn.on('notReady', function(data){
    console.log('UUID FAILED AUTHENTICATION!');
    console.log(data);
});

conn.on('ready', function(data){
    console.log('UUID AUTHENTICATED!');
    console.log(data);

    setInterval(function(){
        console.log("sending message");
        conn.message({
            "devices": data.uuid,
            "payload": {
                "hello":"world"
            }
        });
    },300);

    conn.on('message', function(data){
        console.log('message received');
        console.log(data);
    });

});

Then run:

node index.js

Here is the example output:

trying ws://meshblu.octoblu.com:80
      UUID AUTHENTICATED!
      { api: 'connect',
      status: 201,
      socketid: 'UMumKQdMAE73j3tXAACr',
      uuid: '5ddfa401-3f62-11e4-9968-a5374769756b',
      token: 'edech445oyt7f1or0c6p5pugovv4pldi' }
      sending message
      message received
      { devices: '5ddfa401-3f62-11e4-9968-a5374769756b',
      payload: { hello: 'world' },
      fromUuid: '5ddfa401-3f62-11e4-9968-a5374769756b' }
      sending message
      message received
      { devices: '5ddfa401-3f62-11e4-9968-a5374769756b',
      payload: { hello: 'world' },
      fromUuid: '5ddfa401-3f62-11e4-9968-a5374769756b' }