Friday, April 25, 2014

Interface to the Internet of Things with SkyNet

The Internet of Things (IoT) refers to the many servers that store data uploaded from various devices (things) connected to the Internet, which can range from weather stations, to home appliances, or a farm animal with a biochip transponder.  Even dancing robotic quad choppers.

There are many services that provide IoT support.  After experimenting with some, I settled on the IoT server.  It provides several simple ways to allow machine to machine communications, including MQTT, REST, and WebSockets.  There are Python and JavaScript libraries to support it.  The API for SkyNet is fairly simple, as is using the REST protocol.  With the curl utility, you can interface to SkyNet from shell commands.

First you need to install the curl program and since I will also be calling this from a C program, I also need the development support.

sudo apt-get install curl libcurl4-gnutls-dev

To create a new device on Skynet, issue the following command (changing the parameters as you see fit)

curl -X POST -d "type=raspberry-pi-example&myvariable=12345"

SkyNet returns a UUID and a security token.  Save this info.  The device id is used to identify the new device and the security token allows a little security so that only someone with the token can update the data for this device.  If you really need to maintain security for the device, be sure to always update it using HTTPS.  If you use HTTP, then the session is not encrypted and someone could intercept the token and use it themselves.  Also, be aware that anyone can read your data.

To update the data for the device, issue this command.  (All one line.)

curl -X PUT -d "token=PUT-YOUR-TOKEN-HERE&myvariable=5678online=true"

To view the data for a device, issue this command.

curl –X GET

The function listed below provides a simple interface to SkyNet, in C, using libcurl.

1 comment:

  1. Hi Ted, I was in Radio Shack ( Monticello Ave in Williamsburg, Va) today (Monday) and was asking the manager/owner there if he knew anyone into the DYI electronics stuff. He told me about you. I have been trying to get a group of people together to form a "Roving Hacker/Maker Space" (see my Craigslist ad at ). Please contact me (use the Craigslist link) if you are interested talking more about it. Thanks, Steve