Open communications network & API for the Internet of Things.

MQTT & CoAP NETWORK

Meshblu is a cloud-based MQTT & CoAP-powered network that scales to meet any needs whether the nodes are smart devices, sensors, cloud resources, drones, Arduinos, Raspberry Pis, etc.

REST & WEBSOCKET API

Meshblu is powered by Node.JS and based entirely on its integrated REST API and realtime RPC-style Websocket API with extensible JSON device & messaging.

DEVICE DIRECTORY

Meshblu provides a queriable device directory API for registering and discovering nodes on the Meshblu network. Meshblu also maintains presence for each device making it easy to know what is on/offline.

DEVICE SECURITY

Meshblu issues a unique 36 character UUID and secret token for each device connecting to our network. These device "credentials" are required for authentication, API calls, and subscriptions.

Gateblu

Our Octoblu Gateway allows you to connect smart devices with IP addresses and not-so-smart devices without IP addresses to Meshblu via our software-based hub which supports Mac, Linux, & Windows.


Microblu OS

Our Microblu OS connects your Arduino to Meshblu and awaits Firmata commands to retrieve sensor data or send/remove voltage to/from pins.


NODE.JS NPM MODULE

Node.JS is known for fast, event-driven operations perfect for nodes and devices such as RaspberryPi, Arduino, and Tessel. Our NPM module gets your app up & running quickly!

JAVASCRIPT

Connect to Meshblu from a web browser or mobile device using our SkyNet.JS javascript include file!


PYTHON

Connect to Meshblu from any Python application using realtime Websockets.

Meshblu allows you to query devices such as drones, Hue light bulbs, Belkin wemos, Arduinos, and server nodes that meet your criteria and send IM messages to one or all devices.

You can subscribe to messages being sent to/from devices and their sensor activities.

We now support cloud-to-cloud message routing allowing your private Meshblu cloud to interact with Meshblu.org connected devices (and visa versa) creating a "hybrid" cloud network!

Meshblu in Action


Experiment with Meshblu using our Nodeblu Chrome App!

HTTP(S) REST API

Base URI: http(s)://skynet.im

Most of our API endpoints require authentication credentials (UUID and secret token) passed in the HTTP headers as skynet_auth_uuid and skynet_auth_token respectively. These credentials are generated by registering a device or user with SkyNet via the POST /Devices API (see below). If you would like to associate additional SkyNet devices to the UUID and Token that you created (as a user), you can add an "owner" property to your other devices with the user's UUID as its value.

We support the following device permissions: View/Discover, Send Messages, and Configure. These permissions are manageable by adding UUIDs to whitelists and blacklists arrays with the following names: viewWhitelist, viewBlacklist, sendWhitelist, sendBlacklist, updateWhitelist, updateBlacklist. Note: If your UUID is the same as the "owner" UUID, these permissions are not enforced (you are the owner).


Status

/status
Returns the SkyNet platform status
curl -X GET http://skynet.im/status
{"skynet":"online","timestamp":1381536589633,"eventCode":200,"_id":"5258934d56330f7dd0000009"}

Devices

/devices
Payload: key=value (i.e. type=drone&color=black)
Registers a node or device with SkyNet. SkyNet returns a UUID device id and security token. You can pass any key/value pairs and even override SkyNet's auto-generated UUID and/or token by passing your own uuid and/or token in the payload i.e. uuid=123&token=456
Be sure to make note of your uuid and token as other calls require you to use these as a security check
curl -X POST -d "type=drone&color=black" http://skynet.im/devices
{"type":"drone","color":"black","uuid":"6f72bc60-32d5-11e3-92e2-e94f95fc16a6","timestamp":1381537803046,"token":"4bbd2jm242dl5wmimbwz4rvlu77m0a4i","channel":"main","online":false,"_id":"5258980b56330f7dd000000d"}

/devices?key=value&key=value
Returns an array of device UUIDs based on key/value query criteria
curl -X GET http://skynet.im/devices?type=drone --header "skynet_auth_uuid: {my uuid}" --header "skynet_auth_token: {my token}"
{"devices":["ad698900-2546-11e3-87fb-c560cb0ca47b","2f3113d0-2796-11e3-95ef-e3081976e170"]}

/devices/{uuid}
Returns all information (except the token) of a specific device or node
curl -X GET http://skynet.im/devices/ad698900-2546-11e3-87fb-c560cb0ca47b --header "skynet_auth_uuid: {my uuid}" --header "skynet_auth_token: {my token}"
{"_id":"5241d9140345450000000001","api":"update","armed":true,"channel":"main","deviceDescription":"this is a test","deviceName":"hackboard","key":"777","online":true,"socketid":"fO8dxKEwARUH9Ea--p2C","timestamp":1381536277933,"uuid":"ad698900-2546-11e3-87fb-c560cb0ca47b"}

/devices/{uuid}
Payload: key=value (i.e. type=drone&color=blue&online=true)
Updates a node or device currently registered with SkyNet that you have access to update. You can pass any key/value pairs to update object as well as null to remove a propery (i.e. color=null).
curl -X PUT -d "color=blue&online=true" http://skynet.im/devices/ad698900-2546-11e3-87fb-c560cb0ca47b --header "skynet_auth_uuid: {my uuid}" --header "skynet_auth_token: {my token}"
{"uuid":"ad698900-2546-11e3-87fb-c560cb0ca47b","color":"blue","timestamp":1381537750462}

/devices/{uuid}

Deletes or unregisters a node or device currently registered with SkyNet that you have access to update.
curl -X DELETE http://skynet.im/devices/ad698900-2546-11e3-87fb-c560cb0ca47b --header "skynet_auth_uuid: {my uuid}" --header "skynet_auth_token: {my token}"
{"uuid":"ad698900-2546-11e3-87fb-c560cb0ca47b","timestamp":1381537971074}

localDevices

/localdevices
Returns a list of unclaimed devices that are on the same network as the requesting resource.
curl -X GET http://skynet.im/localdevices --header "skynet_auth_uuid: {my uuid}" --header "skynet_auth_token: {my token}"
{"devices":[{"autoRegister":true,"online":false,"timestamp":"2014-08-05T20:38:31.139Z","ipAddress":"184.98.43.115","protocol":"websocket","secure":false,"uuid":"76537331-1ce0-11e4-861d-89322229e557","channel":"main"},{"autoRegister":true,"online":true,"timestamp":"2014-08-05T16:50:52.492Z","ipAddress":"184.98.43.115","protocol":"websocket","secure":false,"uuid":"a92350c1-1cc0-11e4-861d-89322229e557","channel":"main"}]}

claimDevice

/claimdevice/:uuid
Adds the skynet_auth_uuid as the owner of this device UUID allowing a user or device to claim ownership of another device.
curl -X PUT http://skynet.im/claimdevice/{:uuid} --header "skynet_auth_uuid: {my uuid}" --header "skynet_auth_token: {my token}"
{"updatedExisting":true,"n":1,"connectionId":232,"err":null,"ok":1}

myDevices

/mydevices
Returns all information (including tokens) of all devices or nodes belonging to a user's UUID (identified with an "owner" property and user's UUID i.e. "owner":"0d1234a0-1234-11e3-b09c-1234e847b2cc")
curl -X GET http://skynet.im/mydevices --header "skynet_auth_uuid: {my uuid}" --header "skynet_auth_token: {my token}"
{"devices":[{"owner":"0d1234a0-1234-11e3-b09c-1234e847b2cc","name":"SMS","phoneNumber":"16025551234","uuid":"1c1234e1-xxxx-11e3-1234-671234c01234","timestamp":1390861609070,"token":"1234eg1234zz1tt1234w0op12346bt9","channel":"main","online":false,"_id":"52e6d1234980420c4a0001db"}}]}

Messages

/messages
Send a message to a specific device, array of devices, or all devices subscribing to a UUID on the SkyNet platform
curl -X POST -d '{"devices": "*", "payload": {"yellow":"off"}}' http://skynet.im/messages --header "skynet_auth_uuid: {my uuid}" --header "skynet_auth_token: {my token}"
curl -X POST -d '{"devices": ["ad6...47b","2f3...170"], "payload": {"yellow":"off"}}' http://skynet.im/messages --header "skynet_auth_uuid: {my uuid}" --header "skynet_auth_token: {my token}"
curl -X POST -d '{"devices": "ad698900-2546-11e3-87fb-c560cb0ca47b", "payload": {"yellow":"off"}}' http://skynet.im/messages --header "skynet_auth_uuid: {my uuid}" --header "skynet_auth_token: {my token}"
{"devices":"*","payload":{"yellow":"off"}}

Note: If your SkyNet cloud is connected to SKYNET.im or other private SkyNet clouds, you can send messages across SkyNet clouds by chaining UUIDs together separated by slashes (/) where the first UUID is the target cloud and the second UUID is the device on that cloud.
curl -X POST -d '{"devices": "ad698900-2546-11e3-87fb-c560cb0ca47b/2f3113d0-2796-11e3-95ef-e3081976e170", "message": {"yellow":"off"}}' "http://localhost:3000/messages" --header "skynet_auth_uuid: {my uuid}" --header "skynet_auth_token: {my token}"

Events

/events/{uuid}
Returns last 10 events related to a specific device or node
curl -X GET http://skynet.im/events/ad698900-2546-11e3-87fb-c560cb0ca47b --header "skynet_auth_uuid: {my uuid}" --header "skynet_auth_token: {my token}"
{"events":[{"uuid":"0d3a53a0-2a0b-11e3-b09c-ff4de847b2cc","socketid":"lnHHS06ijWUXEzb01ZRy","timestamp":1382632438785,"eventCode":101,"_id":"52694bf6ad11379eec00003f"},{"uuid":"0d3a53a0-2a0b-11e3-b09c-ff4de847b2cc","socketid":"BuwnWQ_oLmpk5R3m1ZRv","timestamp":1382561240563,"eventCode":101,"_id":"526835d8ad11379eec000017"}]}

Subscribe

/subscribe/{uuid}?token={token}
This is a streaming API that returns device/node messages as they are sent and received. Notice the comma at the end of the response. SkyNet doesn't close the stream.
Note: You can subscribe to UUIDs without knowing the token but this will only allow you to receive broadcast messages from the UUID (devices=* or devices=all)
curl -X GET http://skynet.im/subscribe/ad698900-2546-11e3-87fb-c560cb0ca47b?token=123 --header "skynet_auth_uuid: {my uuid}" --header "skynet_auth_token: {my token}"
{"devices":"0d3a53a0-2a0b-11e3-b09c-ff4de847b2cc","message":{"red":"on"},"timestamp":1388768270795,"eventCode":300,"_id":"52c6ec0e4f67671e44000001"},{"devices":"0d3a53a0-2a0b-11e3-b09c-ff4de847b2cc","message":{"red":"on"},"timestamp":1388768277473,"eventCode":300,"_id":"52c6ec154f67671e44000002"},

IP Address

/ipaddress
Returns the public IP address of the request. This is useful when working with the SkyNet Gateway behind a firewall.
curl -X GET http://skynet.im/ipaddress
{"ipAddress":"70.171.149.205"}

Data

/data/{uuid}
Payload: key=value&key2=value2 (i.e. temperature=78&humity=30)
Stores sensor data for a particular UUID. You can pass any key/value pairs.
curl -X POST -d "wind=12&temperature=78" http://skynet.im/data/0d3a53a0-2a0b-11e3-b09c-ff4de847b2cc --header "skynet_auth_uuid: {my uuid}" --header "skynet_auth_token: {my token}"
{"timestamp":"2014-03-23T18:57:16.093Z","uuid":"0d3a53a0-2a0b-11e3-b09c-ff4de847b2cc","temperature":"78","wind":"12","ipAddress":"127.0.0.1","eventCode":700,"_id":"532f2e8c9c23809e93000002"}


/data/{uuid}
Returns last 10 data updates related to a specific device or node
Optional query parameters include: start (time to start from), finish (time to end), limit (overrides the default 10 updates)
Note: You can make this API stream sensor data by adding stream=true to the querystring. Notice the comma at the end of the response. SkyNet doesn't close the stream.
curl -L -X GET http://skynet.im/data/0d3a53a0-2a0b-11e3-b09c-ff4de847b2cc --header "skynet_auth_uuid: {my uuid}" --header "skynet_auth_token: {my token}"
curl -L -X GET http://skynet.im/data/0d3a53a0-2a0b-11e3-b09c-ff4de847b2cc?stream=true --header "skynet_auth_uuid: {my uuid}" --header "skynet_auth_token: {my token}"
curl -L -X GET --header "skynet_auth_uuid: {my uuid}" --header "skynet_auth_token: {my token}" "http://skynet.im/data/0d3a53a0-2a0b-11e3-b09c-ff4de847b2cc?start=2013-08-06T20:50:21.818Z&finish=2013-08-06T20:60:21.818Z" 
{"data":[{"timestamp":"2014-03-23T18:57:16.093Z","uuid":"0d3a53a0-2a0b-11e3-b09c-ff4de847b2cc","temperature":"78","wind":"12","ipAddress":"127.0.0.1","id":"532f2e8c9c23809e93000001"}]}


CoAP API

Base URI: coap://coap.octoblu.com

Status

/status
Returns the SkyNet platform status
coap get coap://coap.octoblu.com/status
{"skynet":"online","timestamp":1381536589633,"eventCode":200,"_id":"5258934d56330f7dd0000009"}

Devices

/devices?key=value&key=value
Returns an array of device UUIDs based on key/value query criteria
coap get -H "skynet_auth_uuid={:UUID}&skynet_auth_token={:TOKEN}" coap://coap.octoblu.com/devices?type=drone
{"devices":["ad698900-2546-11e3-87fb-c560cb0ca47b","2f3113d0-2796-11e3-95ef-e3081976e170"]}

/devices/{uuid}
Returns all information (except the token) of a specific device or node
coap get -H "skynet_auth_uuid={:UUID}&skynet_auth_token={:TOKEN}" coap://coap.octoblu.com/devices/ad698900-2546-11e3-87fb-c560cb0ca47b
{"_id":"5241d9140345450000000001","api":"update","armed":true,"channel":"main","deviceDescription":"this is a test","deviceName":"hackboard","key":"777","online":true,"socketid":"fO8dxKEwARUH9Ea--p2C","timestamp":1381536277933,"uuid":"ad698900-2546-11e3-87fb-c560cb0ca47b"}

/devices
Payload: key=value (i.e. type=drone&color=black)
Registers a node or device with SkyNet. SkyNet returns a UUID device id and security token. You can pass any key/value pairs and even override SkyNet's auto-generated UUID and/or token by passing your own uuid and/or token in the payload i.e. uuid=123&token=456
coap post -p "type=drone&color=black" -H "skynet_auth_uuid={:UUID}&skynet_auth_token={:TOKEN}" coap://coap.octoblu.com/devices
{"type":"drone","color":"black","uuid":"6f72bc60-32d5-11e3-92e2-e94f95fc16a6","timestamp":1381537803046,"token":"4bbd2jm242dl5wmimbwz4rvlu77m0a4i","channel":"main","online":false,"_id":"5258980b56330f7dd000000d"}

/devices/{uuid}
Payload: token=123&key=value (i.e. token=123&type=drone&color=blue&online=true)
Updates a node or device currently registered with SkyNet. You must pass the token for security but you can pass any key/value pairs to update object as well as null to remove a propery (i.e. color=null).
coap put -p "token=123&color=blue&online=true" -H "skynet_auth_uuid={:UUID}&skynet_auth_token={:TOKEN}" coap://coap.octoblu.com/devices/ad698900-2546-11e3-87fb-c560cb0ca47b
{"uuid":"ad698900-2546-11e3-87fb-c560cb0ca47b","color":"blue","timestamp":1381537750462}

/devices/{uuid}
Payload: token=123
Deletes or unregisters a node or device currently registered with SkyNet. You must pass the token for security.
coap delete -p "token=123" -H "skynet_auth_uuid={:UUID}&skynet_auth_token={:TOKEN}" coap://coap.octoblu.com/devices/ad698900-2546-11e3-87fb-c560cb0ca47b
{"uuid":"ad698900-2546-11e3-87fb-c560cb0ca47b","timestamp":1381537971074}

myDevices

/mydevices/{uuid}
Returns all information (including tokens) of all devices or nodes belonging to a user's UUID (identified with an "owner" property and user's UUID i.e. "owner":"0d1234a0-1234-11e3-b09c-1234e847b2cc")
coap get -H "skynet_auth_uuid={:UUID}&skynet_auth_token={:TOKEN}" coap://coap.octoblu.com/mydevices/0d1234a0-1234-11e3-b09c-1234e847b2cc?token=1234glm6y1234ldix1234nux41234sor
{"devices":[{"owner":"0d1234a0-1234-11e3-b09c-1234e847b2cc","name":"SMS","phoneNumber":"16025551234","uuid":"1c1234e1-xxxx-11e3-1234-671234c01234","timestamp":1390861609070,"token":"1234eg1234zz1tt1234w0op12346bt9","channel":"main","online":false,"_id":"52e6d1234980420c4a0001db"}}]}

Messages

/messages
Send a message to a specific device, array of devices, or all devices subscribing to a UUID on the SkyNet platform
coap post -p '{"devices": "*", "payload": {"yellow":"off"}}' -H "skynet_auth_uuid={:UUID}&skynet_auth_token={:TOKEN}" coap://coap.octoblu.com/messages
coap post -p '{"devices": ["ad6...47b","2f3...170"], "payload": {"yellow":"off"}}' -H "skynet_auth_uuid={:UUID}&skynet_auth_token={:TOKEN}" coap://coap.octoblu.com/messages
coap post -p '{"devices": "ad698900-2546-11e3-87fb-c560cb0ca47b", "payload": {"yellow":"off"}}' coap://skynet.im/messages
{"devices":"*","payload":{"yellow":"off"}}

Events

/events/{uuid}?token={token}
Returns last 10 events related to a specific device or node
coap get -H "skynet_auth_uuid={:UUID}&skynet_auth_token={:TOKEN}" coap://coap.octoblu.com/events/ad698900-2546-11e3-87fb-c560cb0ca47b?token=123
{"events":[{"uuid":"0d3a53a0-2a0b-11e3-b09c-ff4de847b2cc","socketid":"lnHHS06ijWUXEzb01ZRy","timestamp":1382632438785,"eventCode":101,"_id":"52694bf6ad11379eec00003f"},{"uuid":"0d3a53a0-2a0b-11e3-b09c-ff4de847b2cc","socketid":"BuwnWQ_oLmpk5R3m1ZRv","timestamp":1382561240563,"eventCode":101,"_id":"526835d8ad11379eec000017"}]}

Subscribe

/subscribe/{uuid}?token={token}
This is a streaming API that returns device/node messages as they are sent and received. Notice the comma at the end of the response. SkyNet doesn't close the stream.
Note: You can subscribe to UUIDs without knowing the token but this will only allow you to receive broadcast messages from the UUID (devices=* or devices=all)
coap get -H "skynet_auth_uuid={:UUID}&skynet_auth_token={:TOKEN}" coap://coap.octoblu.com/subscribe/ad698900-2546-11e3-87fb-c560cb0ca47b?token=123 -o
{"devices":"0d3a53a0-2a0b-11e3-b09c-ff4de847b2cc","message":{"red":"on"},"timestamp":1388768270795,"eventCode":300,"_id":"52c6ec0e4f67671e44000001"},{"devices":"0d3a53a0-2a0b-11e3-b09c-ff4de847b2cc","message":{"red":"on"},"timestamp":1388768277473,"eventCode":300,"_id":"52c6ec154f67671e44000002"},

IP Address

/ipaddress
Returns the public IP address of the request. This is useful when working with the SkyNet Gateway behind a firewall.
coap get -H "skynet_auth_uuid={:UUID}&skynet_auth_token={:TOKEN}" coap://coap.octoblu.com/ipaddress
{"ipAddress":"70.171.149.205"}

Data

/data/{uuid}
Payload: token=value&key=value (i.e. temperature=78&humity=30)
Stores sensor data for a particular UUID. You can pass any key/value pairs.
coap post -p "token=123&temperature=78" -H "skynet_auth_uuid={:UUID}&skynet_auth_token={:TOKEN}" coap://coap.octoblu.com/data/0d3a53a0-2a0b-11e3-b09c-ff4de847b2cc
{"timestamp":"2014-03-23T18:57:16.093Z","uuid":"0d3a53a0-2a0b-11e3-b09c-ff4de847b2cc","temperature":"78","ipAddress":"127.0.0.1","eventCode":700,"_id":"532f2e8c9c23809e93000002"}


/data/{uuid}?token={token}
Returns last 10 data updates related to a specific device or node
Optional query parameters include: start (time to start from), finish (time to end), limit (overrides the default 10 updates)
Note: You can make this API stream sensor data by adding stream=true to the querystring. Notice the comma at the end of the response. SkyNet doesn't close the stream.
coap get -H "skynet_auth_uuid={:UUID}&skynet_auth_token={:TOKEN}" coap://coap.octoblu.com/data/0d3a53a0-2a0b-11e3-b09c-ff4de847b2cc?token=123
coap get -H "skynet_auth_uuid={:UUID}&skynet_auth_token={:TOKEN}" coap://coap.octoblu.com/data/0d3a53a0-2a0b-11e3-b09c-ff4de847b2cc?token=123&stream=true  -o
{"data":[{"timestamp":"2014-03-23T18:57:16.093Z","uuid":"0d3a53a0-2a0b-11e3-b09c-ff4de847b2cc","temperature":"78","ipAddress":"127.0.0.1","id":"532f2e8c9c23809e93000001"}]}


Note: The CoAP examples are using Matteo Collina's CoAP CLI testing tool.

SkyNet offers a realtime websocket API as well as a Node.JS NPM module to make event-driven IoT development fast and easy. When nodes and devices register with SkyNet, they are assigned a unique id known as a UUID along with a security token. (Note: tokens can be provided by the request rather than having SkyNet assign one for you.)

Upon connecting your node or device to SkyNet, you can query and update devices on the network and send machine-to-machine (M2M) messages in an RPC-style fashion. Here are the basics for a socket.io implementation of using native websockets:

var io = require('socket.io-client')
socket = io.connect('http://skynet.im', {
    port: 80
});

socket.on('connect', function(){
  console.log('Requesting websocket connection to SkyNet');

  socket.on('identify', function(data){
    console.log('Websocket connecting to SkyNet with socket id: ' + data.socketid);
    console.log('Sending device uuid: ad698900-2546-11e3-87fb-c560cb0ca47b');
    socket.emit('identity', {uuid: 'ad698900-2546-11e3-87fb-c560cb0ca47b', socketid: data.socketid, token: 'zh4p7as90pt1q0k98fzvwmc9rmjkyb9'});
  });

  socket.on('notReady', function(data){
    if (data.status == 401){
      console.log('Device not authenticated with SkyNet');
    }
  });
  socket.on('ready', function(data){
    if (data.status == 201){
      console.log('Device authenticated with SkyNet');

      // Send/Receive messages
      socket.emit("message",{
        "devices": ["0d3a53...847b2cc", "11123...44567"],
        "payload": {
          "red":"on"
        }, function (data) {
          console.log(data);
        }
      });
      socket.on('message', function(message){
        console.log('message received', message);
        // { devices: '0d3a53a0-2a0b-11e3-b09c-ff4de847b2cc',
  payload: { red: 'on' },
  fromUuid: '0d3a53a0-2a0b-11e3-b09c-ff4de847b2cc' }
      });

      // Sample SkyNet API calls:
      socket.emit('status', function(data){
        console.log('status received');
        console.log(data);
        // { skynet: 'online' }
      });

      // Subscribe and unsubscribe to a device's messages and events
      socket.emit('subscribe', {
        "uuid": "0d3a53a0-2a0b-11e3-b09c-ff4de847b2cc",
        "token": "qirqglm6yb1vpldixflopnux4phtcsor"
      }, function (data) {
        console.log(data);
        // {"api":"subscribe","socketid":"j3WWX81JwWYzaidRaNA7","fromUuid":"0d3a53a0-2a0b-11e3-b09c-ff4de847b2cc","toUuid":"0d3a53a0-2a0b-11e3-b09c-ff4de847b2cc"}
      });

      socket.emit('unsubscribe', {"uuid": "0d3a53a0-2a0b-11e3-b09c-ff4de847b2cc"}, function (data) {
        console.log(data);
        // {"api":"unsubscribe","socketid":"j3WWX81JwWYzaidRaNA7","uuid":"0d3a53a0-2a0b-11e3-b09c-ff4de847b2cc"}
      });

      // Register device
      socket.emit('register', {
        "type":"drone"
      }, function (data) {
        console.log(data);
        // {"type":"drone","uuid":"b34cc731-b2f2-11e3-a36b-61e66c96102e","timestamp":"2014-03-24T01:22:01.123Z","token":"3k0t96e6n9mjkyb9ncpx8um4bstc5wmi","channel":"main","online":false,"ipAddress":""}
      });


      // Update device
      socket.emit('update', {
        "uuid": "0d3a53a0-2a0b-11e3-b09c-ff4de847b2cc",
        "token": "qirqglm6yb1vpldixflopnux4phtcsor",
        "armed":true
      }, function (data) {
        console.log(data);
        // {"uuid":"0d3a53a0-2a0b-11e3-b09c-ff4de847b2cc","armed":true,"timestamp":"2014-03-24T01:22:01.203Z"}
      });

      // WhoAmI?
      socket.emit('whoami', {"uuid":"0d3a53a0-2a0b-11e3-b09c-ff4de847b2cc"}, function (data) {
        console.log(data);
        // {"armed":true,"channel":"main","color":"blue","ipAddress":"70.171.192.231","online":true,"protocol":"websocket","socketid":"j3WWX81JwWYzaidRaNA7","uuid":"0d3a53a0-2a0b-11e3-b09c-ff4de847b2cc"}
      });

      // Local devices
      socket.emit('localdevices', function (data) {
        console.log(data);
        // {"devices":[{"drone","uuid":"b34cc731-b2f2-11e3-a36b-61e66c96102e","timestamp":"2014-03-24T01:22:01.123Z","token":"3k0t96e6n9mjkyb9ncpx8um4bstc5wmi","channel":"main","online":false,"ipAddress":"184.98.43.115"}]}
      });

      // Claim device
      socket.emit('claimdevice', {"uuid":"76537331-1ce0-11e4-861d-89322229e557"}, function (data) {
        console.log(data);
        // {"results":{"updatedExisting":true,"n":1,"connectionId":232,"err":null,"ok":1}}
      });

      // My devices
      socket.emit('mydevices', {}, function (data) {
        console.log(data);
        // {"devices":[{"drone","uuid":"b34cc731-b2f2-11e3-a36b-61e66c96102e","timestamp":"2014-03-24T01:22:01.123Z","token":"3k0t96e6n9mjkyb9ncpx8um4bstc5wmi","channel":"main","online":false,"ipAddress":"184.98.43.115"}], "eventCode": 403, "fromUuid": "c33e14c0-fd55-11e3-a290-ef9910e207d9", "timestamp": "2014-08-05T23:05:13.834Z"}
      });

      // Receive last 10 device events
      socket.emit('events', {
        "uuid": "0d3a53a0-2a0b-11e3-b09c-ff4de847b2cc",
        "token": "qirqglm6yb1vpldixflopnux4phtcsor"
      }, function (data) {
        console.log(data);
        // {"events":[{"uuid":"0d3a53a0-2a0b-11e3-b09c-ff4de847b2cc","armed":true,"timestamp":"2014-03-24T01:22:01.203Z","fromUuid":{"armed":true,"channel":"main","color":"blue","ipAddress":"70.171.192.231","online":true,"protocol":"websocket","socketid":"j3WWX81JwWYzaidRaNA7","uuid":"0d3a53a0-2a0b-11e3-b09c-ff4de847b2cc"},"eventCode":401,"id":"532f88b90db905bf09055983"}]}
      });

      // Store sensor data for device
      socket.emit('data', {
        "uuid": "f828ef20-29f7-11e3-9604-b360d462c699",
        "token": "syep2lu2d0io1or305llz5u9ijrwwmi",
        "temperature": 55
      }, function (data) {
        console.log(data);
      });

      // Read sensor data from device (optional params: limit, start, finish)
      socket.emit('getdata', {
        "uuid": "f828ef20-29f7-11e3-9604-b360d462c699",
        "token": "syep2lu2d0io1or305llz5u9ijrwwmi",
        "limit": 1
      }, function (data) {
        console.log(data);
      });


    }
  });
});

            

Websocket API commands include: status, register, unregister, update, whoami, devices, subscribe, unsubscribe, authenticate, data, and message. You can send a message to a specific UUID or an array of UUIDs or all nodes on SkyNet.

MQTT API

For your convenience, we also have a skynet-mqtt client node.js npm module.

npm install skynet-mqtt

You must register a device with SkyNet using one of the other APIs (HTTP, COAP, WebSocket) to receive a UUID and token to use with these examples. Our MQTT API does not yet support RPC-style request/response calls.

Here are the basics:

var skynet = require('skynet-mqtt');

var conn = skynet.createConnection({
  "uuid": "xxxxxxxxxxxx-My-UUID-xxxxxxxxxxxxxx",
  "token": "xxxxxxx-My-Token-xxxxxxxxx",
  "qos": 0, // MQTT Quality of Service (0=no confirmation, 1=confirmation, 2=N/A)
  "host": "localhost", // optional - defaults to skynet.im
  "port": 1883  // optional - defaults to 1883
});

conn.on('ready', function(){

  console.log('UUID AUTHENTICATED!');

  //Listen for messages
  conn.on('message', function(message){
    console.log('message received', message);
  });


  // Send a message to another device
  conn.message({
    "devices": "xxxxxxx-some-other-uuid-xxxxxxxxx",
    "payload": {
      "skynet":"online"
    }
  });


  // Broadcast a message to any subscribers to your uuid
  conn.message({
    "devices": "*",
    "payload": {
      "hello":"skynet"
    }
  });


  // Subscribe to broadcasts from another device
  conn.subscribe('xxxxxxx-some-other-uuid-xxxxxxxxx');


  // Log sensor data to skynet
  conn.data({temperature: 75, windspeed: 10});

});

            

Node.JS NPM Module

SkyNet also offers a Node.JS NPM module for making event-driven IoT development fast and easy. You can install the skynet module by running:

npm install skynet

Here's a kitchen-sink sample Node.JS app using the SkyNet NPM module:

var skynet = require('skynet');

var conn = skynet.createConnection({
  "uuid": "ad698900-2546-11e3-87fb-c560cb0ca47b",
  "token": "zh4p7as90pt1q0k98fzvwmc9rmjkyb9",
  "server": "localhost", // optional - defaults to ws://skynet.im
  "port": 3000  // optional - defaults to 80
});

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

  // Register a device
  conn.register({
    "type": "drone"
  }, function (data) {
    console.log(data);

    // Login to SkyNet to fire onready event
    conn.authenticate({
      "uuid": data.uuid,
      "token": data.token
    }, function (data) {
      console.log(data);
    });

  });

});

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

  // Send and receive messages
  conn.message({
    "devices": "*",
    "payload": {
      "red":"on"
    }
  });

  // Subscribe to device/node i/o
  conn.subscribe({
    "uuid": "f828ef20-29f7-11e3-9604-b360d462c699",
    "token": "syep2lu2d0io1or305llz5u9ijrwwmi"
  }, function (data) {
    console.log(data);
  });

  // Unsubscribe to device/node i/o
  conn.unsubscribe({
    "uuid": "f828ef20-29f7-11e3-9604-b360d462c699"
  }, function (data) {
    console.log(data);
  });

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


  // Event triggered when device loses connection to skynet
  conn.on('disconnect', function(data){
    console.log('disconnected from skynet');
  });

  // Register a device
  conn.register({
    // token is optional. skynet will assign one for your device uuid if not present
    "token": "zh4p7as90pt1q0k98fzvwmc9rmjkyb9",
    "type": "drone"
  }, function (data) {
    console.log(data);
  });

  // UnRegister a device
  conn.unregister({
    "uuid": "ad698900-2546-11e3-87fb-c560cb0ca47b",
    "token": "zh4p7as90pt1q0k98fzvwmc9rmjkyb9"
  }, function (data) {
    console.log(data);
  });

  // Update device
  conn.update({
    "uuid":"ad698900-2546-11e3-87fb-c560cb0ca47b",
    "token": "zh4p7as90pt1q0k98fzvwmc9rmjkyb9",
    "armed":true
  }, function (data) {
    console.log(data);
  });

  // WhoAmI?
  conn.whoami({"uuid":"ad698900-2546-11e3-87fb-c560cb0ca47b"}, function (data) {
    console.log(data);
  });

  // Receive an array of device UUIDs based on user defined search criteria
  conn.devices({
    "type":"drone"
  }, function (data) {
    console.log(data);

    // Send hello world to the array of device uuids
    conn.message({
      "devices": data.devices,
      "payload": {
        "hello":"world"
      }
    });

  });

  // Local devices
  conn.localdevices(function (data) {
    console.log(data);
    // {"devices":[{"drone","uuid":"b34cc731-b2f2-11e3-a36b-61e66c96102e","timestamp":"2014-03-24T01:22:01.123Z","token":"3k0t96e6n9mjkyb9ncpx8um4bstc5wmi","channel":"main","online":false,"ipAddress":"184.98.43.115"}]}
  });

  // Claim device
  conn.claimdevice({"uuid":"76537331-1ce0-11e4-861d-89322229e557"}, function (data) {
    console.log(data);
    // {"results":{"updatedExisting":true,"n":1,"connectionId":232,"err":null,"ok":1}}
  });

  // My devices
  conn.mydevices({}, function (data) {
    console.log(data);
    // {"devices":[{"drone","uuid":"b34cc731-b2f2-11e3-a36b-61e66c96102e","timestamp":"2014-03-24T01:22:01.123Z","token":"3k0t96e6n9mjkyb9ncpx8um4bstc5wmi","channel":"main","online":false,"ipAddress":"184.98.43.115"}], "eventCode": 403, "fromUuid": "c33e14c0-fd55-11e3-a290-ef9910e207d9", "timestamp": "2014-08-05T23:05:13.834Z"}
  });


  // SkyNet status
  conn.status(function (data) {
    console.log(data);
  });

  // Receive last 10 device events
  conn.events({
    "uuid": "f828ef20-29f7-11e3-9604-b360d462c699",
    "token": "syep2lu2d0io1or305llz5u9ijrwwmi"
  }, function (data) {
    console.log(data);
  });

  // Store sensor data for device
  conn.data({
    "uuid": "f828ef20-29f7-11e3-9604-b360d462c699",
    "token": "syep2lu2d0io1or305llz5u9ijrwwmi",
    "temperature": 55
  }, function (data) {
    console.log(data);
  });


});


            

SkyNet automatically creates a websocket room for each connect device. This allows apps and other nodes and devices to connect and monitor events and commands. Note: UUID and Token are required to subscribe to device/node events. Here's a sample Node.JS device monitoring script:

script(src="http://code.jquery.com/jquery-1.10.1.min.js")
script(src="/socket.io/socket.io.js")
script.
  // Connect to SkyNet server & port
  var socket = io('ws://skynet.im:80');

  // subscribe to uuid
  socket.emit('subscribe', {
    "uuid": "0d3a53a0-2a0b-11e3-b09c-ff4de847b2cc",
    "token": "qirqglm6yb1vpldixflopnux4phtcsor"
  }, function (data) {
    console.log(data);
  });

  // unsubscribe to uuid
  socket.emit('unsubscribe', {"uuid": "0d3a53a0-2a0b-11e3-b09c-ff4de847b2cc"}, function (data) {
    console.log(data);
  });

  socket.on('identify', function (data) {
    console.log(data);
    $(".activity").prepend(JSON.stringify(data) + '<br />');
  });

  socket.on('message', function (message) {
    console.log('message received', message);
    $(".activity").prepend(JSON.stringify(message) + '<br />');
  });

            


SkyNet.JS Javascript Library

For your convenience, we also have a skynet.js javascript include file that you can use for client-side Web and/or mobile apps. The Javascript API is the exact same as the SkyNet NPM module but there is no need to require 'skynet'. Here are the basics:


<html>
<head>
  <script src="http://skynet.im/js/skynet.js"></script>
  <script>
    var conn = skynet.createConnection({
      "uuid": "ad698900-2546-11e3-87fb-c560cb0ca47b",
      "token": "zh4p7as90pt1q0k98fzvwmc9rmjkyb9",
      "server": "localhost", // optional - defaults to ws://skynet.im
      "port": 3000  // optional - defaults to 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);

      // Send and receive messages
      conn.message({
        "devices": "*",
        "payload": {
          "red":"on"
        }
      });
    });
  </script>
</head>
<body>
  SkyNet client-side app
</body>
</html>

            

Examples

Here are a few examples to get you started. You will need to create your own UUID and token. You can do this by running the following command from your terminal window:

curl -X POST -d "type=example" http://skynet.im/devices

This should return a response from SkyNet with your very own UUID and Token like this one! Please use your own UUID and Token in the examples below.

{"type":"example","ipAddress":"70.171.192.231","uuid":"0cf6c7e1-b2f8-11e3-a36b-61e66c96102e","timestamp":"2014-03-24T02:00:19.038Z","token":"63jous8wnn42huxrdz2456y1ypmk7qfr","channel":"main","online":false}

We will be using the SkyNet and Request NPM modules in the examples below. You can install them using the following terminal commands:

npm install skynet
npm install request

          
var request = require('request');

// Check SkyNet status
request('http://skynet.im/status', function (error, response, body) {
  if (!error && response.statusCode == 200) {
    console.log(body) // Print skynet status.
  }
})

// Subscribe to UUID
// curl -X GET http://skynet.im/subscribe/0d3a53a0-2a0b-11e3-b09c-ff4de847b2cc?token=qirqglm6yb1vpldixflopnux4phtcsor
console.log('Subscribing to UUID: 0d3a53a0-2a0b-11e3-b09c-ff4de847b2cc')
request.get('http://skynet.im/subscribe/0d3a53a0-2a0b-11e3-b09c-ff4de847b2cc',
  {qs: {'token': 'qirqglm6yb1vpldixflopnux4phtcsor'}}
  , function (error, response, body) {
    if (!error && response.statusCode == 200) {
      console.log(body) // Print device activity.
  }
})

// Send message
// curl -X POST -d '{"devices": "0d3a53a0-2a0b-11e3-b09c-ff4de847b2cc", "payload": {"yellow":"off"}}' http://skynet.im/messages
setTimeout(function(){
  request.post('http://skynet.im/messages',
    {form: {'devices':'0d3a53a0-2a0b-11e3-b09c-ff4de847b2cc', 'payload': 'test'}}
    , function (error, response, body) {
      if(response.statusCode == 200){
        console.log(body);
      }
  });
},1000);

      
    
        
var skynet = require('skynet');
var request = require('request');

var conn = skynet.createConnection({
  "uuid": "0d3a53a0-2a0b-11e3-b09c-ff4de847b2cc",
  "token": "qirqglm6yb1vpldixflopnux4phtcsor"
});

conn.on('ready', function(data){
  console.log('Ready');

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

  conn.status(function (data) {
    console.log(data);
  });

  conn.message({
    "devices": "0d3a53a0-2a0b-11e3-b09c-ff4de847b2cc",
    "payload": {
      "hello":"world"
    }
  });

});
      
    
  


<html>
<head>
  <script src="http://skynet.im/js/skynet.js"></script>
  <script>
    var conn = skynet.createConnection({
      "uuid": "0d3a53a0-2a0b-11e3-b09c-ff4de847b2cc",
      "token": "qirqglm6yb1vpldixflopnux4phtcsor"
    });

    conn.on('ready', function(data){
      console.log('Ready');

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

      conn.status(function (data) {
        console.log(data);
      });

      conn.message({
        "devices": "0d3a53a0-2a0b-11e3-b09c-ff4de847b2cc",
        "payload": {
          "hello":"world"
        }
      });

    });
  </script>

</head>
<body>
  Skynet.JS Demo
</body>
</html>


Get in touch