Skip to content

SkyNet.im a quick guide

ctlaltdieliet edited this page May 6, 2014 · 2 revisions

What is SkyNet?

SkyNet is a machine to machine instant messaging platform. SkyNet makes it possible that machines with each having its own API can communicate with eachother through SkyNet. You can send messages to your devices and receive messages from your devices. SkyNet uses a very lightweighted protocols. You can connect through MQTT or REST or a websocket. So almost device can connect with SkyNet.

Do I need to install SkyNet?

No, you can add your devices to the free and public cloud service that is provided at http://skynet.im

But if you want your own privat Skynet, you can download the source code at https://github.com/skynetim/skynet and run your own private SkyNet (a combination from nodejs, mongodb and redis) or install it with docker.

How can I connect to SkyNet

That is the great part about SkyNet, anything that can make a MQTT connection or can act like a browser is able to connect. To make it easy, there are some examples:

List of all the commands and their responses

We describe here all the commands you can send to SkyNet through websockets, the REST-API and CoAP API.

Status: check if SkyNet is online

You can ask SkyNet if it is online or not.

  • Rest: curl -X GET http://skynet.im/status

  • CoAP: get coap://skynet.im/status

  • _
Websockets: socket.emit('status',{},on_response) _

    You receive as response: { skynet: 'online' }

Register: adding a new device to SkyNet

For adding a new device to SkyNet you have emit 'register'. Register requires an (empty) argument. Or you can add your own arguments like the type of device you are registering.

  • REST: curl -X POST -d "name=arduino&token=123" http://skynet.im/devices
  • CoAp: coap post -p "name=arduino&token=123" coap://skynet.im/devices
  • WebSockets: socket.emit('register', {"name:arduino&token:123"},on_response)

SkyNet returns the following when you register: [{"uuid":"8e8836d1-cba9-11e3-8fa5-2726ddcf5e29","timestamp":"2014-04-24T12:11:25.245Z","token":"0s0joawcot9c3ow29cudz4e03cui8uxr","channel":"main","online":false,"ipAddress":""}]

You have a unique 36 character UUID and a secret token. You need the token for authentication, API calls, and subscriptions. You also have the timestamp on which you registered the device. The channel is an obsolete argument and will be removed. The device is of course not yet online. It comes online when you send a successful identity and that is why there isn't an ip-address as well. You can choose your own uuid and/or token when you register a device. When the uuid is already by another device SkyNet returns you a random uuid back.

Authenticate: Checking the uuid and the token from a device.

You can check the credentials from a device with the authenticate command.

  • REST: _curl -X GET http://skynet.im/authenticate/81246e80-29fd-11e3-9468-e5f892df566b?token=5ypy4rurayktke29ypbi30kcw5ovfgvi _
  • 
CoAP: coap get coap://skynet.im/authenticate/81246e80-29fd-11e3-9468-e5f892df566b?token=5ypy4rurayktke29ypbi30kcw5ovfgvi
  • WebSockets: socket.emit('identity',{uuid":"81246e80-29fd-11e3-9468-e5f892df566b","token":”5ypy4rurayktke29ypbi30kcw5ovfgvi“
},on_response) You receive: {"uuid":"my_own_uuid","authentication":true} 
or "uuid":"my_own_uuid","authentication":false} With the websockets you can use identity as well.

Identity: Authenticating your device

!This is only for websocket connections! When you connect to SkyNet you get the following response through a websocket you get the following response {"name":"identify","args":[{"socketid":"ADmWF5j9ncMfjSQxWcZU"}]} To authenticate your device you need to send 2 arguments with the identity command. (Note it is identity and not identify)

  1. The uuid
  2. the token This only works with websockets
  • WebSockets: socket.emit('identity', {‘uuid’: 'ad698900-2546-11e3-87fb-c560cb0ca47b', ‘token’: 'zh4p7as90pt1q0k98fzvwmc9rmjkyb9'},on_response) When successful authenticated you receive a status 201 message: {"name":"ready","args":[{"api":"connect","status":201,"socketid":"pjXSteM_CBgoeIGGWcZz","uuid":"my_own_uuid","token":"worst_token_ever"}] When you send a wrong combination from uuid and token SkyNet returns you this: {"name":"notReady","args":[{"api":"connect","status":401,"socketid":"t_B_Ckma8hN8_kDGWcZ3","uuid":"my_own_uuid }]}

Update: Updating your device

You can update the values of the attributes from your device with sending an update. You need to send the uuid and the token.

  • REST: curl -X PUT -d "token=123&color=black&online=true" http://skynet.im/devices/ my_own_uuid

  • COAP: _put -p "token=123&color=black&online=true" coap://skynet.im/devices/ my_own_uuid _
  • Websockets: socket.emit('update',{'uuid':uuid,'token':token,'color':'black'} ,on_response) You receive [{"uuid":"my_own_uuid","color":"black","timestamp":"2014-04-24T13:27:18.036Z"}]

To remove a attribute you send an empty value like

  • REST: curl -X PUT -d "token=123&color= &online=true" http://skynet.im/devices/ my_own_uuid
  • 
COAP: _put -p "token=123&color= &online=true" coap://skynet.im/devices/my_own_uuid _
  • WebSockets socket.emit('update',{'uuid':my_own_uuid,'token':’123’,'color':’'},on_response)


Whoami: Getting all attributes from a device

You can get all the attributes except the token from a device. You only have to send the uuid, you don't need the token.

You receive: [{"channel":"main","ipAddress":"127.0.0.1","online":true,"protocol":"websocket","secure":false,"color":"black","socketId":"PmhAe9HtKFWKyN7q_Zrl","socketid":"SK9SMz1CVA5WPPMCWcaF","type":"pythonExample","uuid":" ad698900-2546-11e3-87fb-c560cb0ca47b”}]

When you use an invalid uuid, you receive a {"uuid":"30ebecc1-b2cb-11e3-a36b-61e66c96102e2","message":"Device not found","code":404}

Message: sending a message to a device.

You use message the messages to a device. Those messages aren't stored as an attribute. It is more like sending a command. You can send to multiple devices. You use an asterisk (*) as uuid or the string all. For describing your device, you use the attributes that you can add an alter with the update command. For storing sensor date you use data. Here are the examples how you send messages to your device.

  • REST: curl -X POST -d '{"devices": "*", "payload": {"yellow":"off"}}' http://skynet.im/messages 
curl -X POST -d '{"devices": ["ad6...47b","2f3...170"], "payload": {"yellow":"off"}}' http://skynet.im/messages 
curl -X POST -d '{"devices": "ad698900-2546-11e3-87fb-c560cb0ca47b", "payload": {"yellow":"off"}}' http://skynet.im/messages
  • CoAP: coap post -p '{"devices": "*", "payload": {"yellow":"off"}}' coap://skynet.im/messages 
coap post -p '{"devices": ["ad6...47b","2f3...170"], "payload": {"yellow":"off"}}' coap://skynet.im/messages 
coap post -p '{"devices": "ad698900-2546-11e3-87fb-c560cb0ca47b", "payload": {"yellow":"off"}}' coap://skynet.im/messages
  • Websockets:socketEmit('message',{"devices":uuid,'payload':{'yellow':’off'}, on_response)

You don't receive any feedback from skynet when you send a message.

The incoming device receives {"name":"message","args":[{"payload":{"light":"red"},"devices":"ad698900-2546-11e3-87fb-c560cb0ca47b","fromUuid":"ad698900-2546-11e3-87fb-c560cb0ca47b"}

Data: saving and reading sensor data to/from your device

For storing sensor data to your device you just sent:

  • REST: _curl -X POST -d "token=123&temperature=78" http://skynet.im/data/0d3a53a0-2a0b-11e3-b09c-ff4de847b2cc _
  • 
CoAP:coap post -p "token=123&temperature=78" coap://skynet.im/data/0d3a53a0-2a0b-11e3-b09c-ff4de847b2cc

  • Websockets: socket.emit('data',{'uuid': 0d3a53a0-2a0b-11e3-b09c-ff4de847b2cc','token':’123’,’temperature’=’78’ },on_response)

When you send the correct credentials you receive a _{"timestamp":"2014-04-25T15:14:22.576Z",”temperature”=”78”,"uuid":"0d3a53a0-2a0b-11e3-b09c-ff4de847b2cc'","api":"data","eventCode":700,"id":"535a7bce1ff66d7c4e01174c"} You also receive a message {name":"message","args":[{"payload":{”temperature”=78,
"uuid":" 0d3a53a0-2a0b-11e3-b09c-ff4de847b2cc“","api":"data"},"devices":"0d3a53a0-2a0b-11e3-b09c-ff4de847b2cc","fromUuid":"my_own_uuid"}]} When you send the wrong credentials, you get a _{"api":"data","result":false} _

You can lookup the last 10 data updates from your device. With setting the limit attribute you can override the number of results that is returned (more/less than 10). You can also can add a start data (start) and/or an end date (finish). 

But even better, you can subscribe to the stream of data updates. So you have a direct update from your device. Retrieving sensor data is not possible through websockets. Getting the last 50 updates from 2014-04-05 till 2014-08-08

Events : Get the 10 last events from your device

You can get the last 10 events from a device by sending an events with the uuid and the token.

You receive : {"events":[{"uuid":""ad698900-2546-11e3-87fb-c560cb0ca47b",","socketid":"rqTAAKlB05_Own5sWcqY","ipAddress":"127.0.0.1","secure":false,"protocol":"websocket","auth":{"uuid":"ad698900-2546-11e3-87fb-c560cb0ca47b","status":201},"fromUuid":{"channel":"main","ipAddress":"127.0.0.1","online":true,"protocol":"websocket","secure":false,"size":"small","socketId":"PmhAe9HtKFWKyN7q_Zrl","socketid":"rqTAAKlB05_Own5sWcqY","type":"pythonExample","uuid":"ad698900-2546-11e3-87fb-c560cb0ca47b"},"timestamp":"2014-04-25T15:19:58.921Z","eventCode":101,"id":"535a7d1e1ff66d7c4e011780"},{"api":"disconnect","socketid":"azEIo8XpIEvuU-ZZWcqX","uuid":"ad698900-2546-11e3-87fb-c560cb0ca47b","fromUuid":{"channel":"main","ipAddress":"127.0.0.1","online":true,"protocol":"websocket","secure":false,"size":"small","socketId":"PmhAe9HtKFWKyN7q_Zrl","socketid":"azEIo8XpIEvuU-ZZWcqX","type":"pythonExample","uuid":"ad698900-2546-11e3-87fb-c560cb0ca47b"},"timestamp":"2014-04-25T15:18:19.261Z","eventCode":102,"id":"535a7cbb1ff66d7c4e01177e"},{"payload":{"uuid":"ad698900-2546-11e3-87fb-c560cb0ca47b","api":"data"},"devices":"ad698900-2546-11e3-87fb-c560cb0ca47b","fromUuid":"ad698900-2546-11e3-87fb-c560cb0ca47b","toUuid":{"channel":"main","ipAddress":"127.0.0.1","online":true,"protocol":"websocket","secure":false,"size":"small","socketId":"PmhAe9HtKFWKyN7q_Zrl","socketid":"azEIo8XpIEvuU-ZZWcqX","type":"pythonExample","uuid":"ad698900-2546-11e3-87fb-c560cb0ca47b"},"timestamp":"2014-04-25T15:18:12.821Z","eventCode":300,"id":"535a7cb41ff66d7c4e01177d"},….."timestamp":"2014-04-25T15:17:47.896Z","eventCode":300,"id":"535a7c9b1ff66d7c4e011776"},{"timestamp":"2014-04-25T15:17:47.873Z","heartbeat":"10","uuid":"ad698900-2546-11e3-87fb-c560cb0ca47b","api":"data","eventCode":700,"id":"535a7c9b1ff66d7c4e011775"},{"uuid":"ad698900-2546-11e3-87fb-c560cb0ca47b","socketid":"-dMHYAPhOh-mRU4lWcqW","ipAddress":"127.0.0.1","secure":false,"protocol":"websocket","auth":{"uuid":"ad698900-2546-11e3-87fb-c560cb0ca47b","status":201},"fromUuid":{"channel":"main","ipAddress":"127.0.0.1","online":true,"protocol":"websocket","secure":false,"size":"small","socketId":"PmhAe9HtKFWKyN7q_Zrl","socketid":"-dMHYAPhOh-mRU4lWcqW","type":"pythonExample","uuid":"ad698900-2546-11e3-87fb-c560cb0ca47b"},"timestamp":"2014-04-25T15:17:47.622Z","eventCode":101,"id":"535a7c9b1ff66d7c4e011773"},{"api":"disconnect","socketid":"heB-lw7wMajHa4kyWcqU","uuid":"ad698900-2546-11e3-87fb-c560cb0ca47b","fromUuid":{"channel":"main","ipAddress":"127.0.0.1","online":true,"protocol":"websocket","secure":false,"size":"small","socketId":"PmhAe9HtKFWKyN7q_Zrl","socketid":"heB-lw7wMajHa4kyWcqU","type":"pythonExample","uuid":"ad698900-2546-11e3-87fb-c560cb0ca47b"},"timestamp":"2014-04-25T15:16:33.911Z","eventCode":102,"id":"535a7c511ff66d7c4e01176c"}]}]

When you send the wrong credentials you receive {'api': 'events', 'result': False})

Subscribe: receive all message that a device receives or sends

You can subscribe to an device as well. Then you get a message everytime a device changes. You need to have the token from the device to subscribe. But if you don’t have the token, you still receive all the messages that the device sends to all devices devices:* or devices:all.

  • REST: curl -X GET http://skynet.im/subscribe/ad698900-2546-11e3-87fb-c560cb0ca47b?token=123

  • CoAP: coap get coap://skynet.im/subscribe/ad698900-2546-11e3-87fb-c560cb0ca47b?token=123 –o


  • Websockets: socket.emit('subscribe', { "uuid": "0d3a53a0-2a0b-11e3-b09c-ff4de847b2cc", "token": "qirqglm6yb1vpldixflopnux4phtcsor", on_response) You receive: _{"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"}, With the wrong credentials you get: _{"api":"subscribe","uuid":"30ebecc1-b2cb-11e3-a36b-61e66c96102e","result":false,"timestamp":"2014-04-26T20:08:58.143Z","eventCode":204,"id":"535c125a1ff66d7c4e017d21"} With the websockets, you can unsubscribe with to no longer follow the device. With the REST and CoAP you just disconnect the stream socket.emit('unsubscribe', {"uuid": "0d3a53a0-2a0b-11e3-b09c-ff4de847b2cc"}, on_response)

      	You receive: 
    

_ {"api":"unsubscribe","socketid":"j3WWX81JwWYzaidRaNA7","_ uuid":"0d3a53a0-2a0b-11e3-b09c-ff4de847b2cc"}

Devices: search a device

This query searches all black devices that are currently online.

  • REST: curl -X GET http://skynet.im/devices?type=drone
  • CoAp: coap get coap://skynet.im/devices?type=drone 
* Websockets: socket.emit("devices", {"color":"black","online":"true"},on_response) It returns: [{"devices":["f828ef20-29f7-11e3-9604-b360d462c699","f1b7fe90-653b-11e3-b2eb-91cf874fce76","GalaxyTab","748dcb11-933b-11e3-b5f9-fd5a85f5ecc3","118d4db1-9340-11e3-b5f9-fd5a85f5ecc3","f65d0339-9add-4e4a-ba49-c0f8463c5296","b389efd1-93fc-11e3-8213-dfc6fa9d6006","4a0da121-9418-11e3-b687-d1f72b2b9e41","d697e531-9420-11e3-a1bc-05c340dd8ee7","e22045f0-942a-11e3-a1bc-05c340dd8ee7"]}] When no devices were found that meet your criteria you receive: _{"error":{"message":"Devices not found","code":404},"timestamp":"2014-04-26T20:40:34.307Z","eventCode":403,"id":"535c19c21ff66d7c4e017ef7"}]

Delete: delete a device

You can remove a device from Skynet with sending the delete command.
 The token is required. This command is not available from the websockets.