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 SkyNet.im 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" http://skynet.im/devices

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" http://skynet.im/devices/PUT-YOUR-UUID-HERE

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

curl –X GET http://skynet.im/devices/PUT-YOUR-UUID-HERE

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




6 comments:

  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 http://norfolk.craigslist.org/grp/4418575374.html ). Please contact me (use the Craigslist link) if you are interested talking more about it. Thanks, Steve

    ReplyDelete
  2. Hi Ted, great article!
    I am trying to use a secure connection and as you mention: "If you really need to maintain security for the device, be sure to always update it using HTTPS"

    The thing is I don't seem to find how to do that using SkyNet.im since curl -X uses http and all their urls are http as well (eg: http://skynet.im/devices...)

    Could you enlighten me ?

    ReplyDelete
    Replies
    1. The same URLs are available via HTTPS. Just specify "https://skynet.im/device/..." when you set the URL.
      Example here:
      http://curl.haxx.se/libcurl/c/https.html

      Delete
  3. Hi. I’m trying to create an interface to two pairs of wireless beam break sensors. Ideally, I want to only get an audio alert when one pair is broken before the second pair. This would indicate an entrance event. I don’t want to get alerts on an exit event. Can you help me figure this out?

    ReplyDelete
  4. How far apart (in time) are the signals? Do they overlap? (i.e. is the first signal still active when the second signal becomes active.) If they overlap, it's simple. Monitor the first signal and when it activates, check the second. If the second is active, then it is an exit. If not, then it is an entry.

    If the signals do not overlap, then you need to monitor both and store the time of the signal (using millis() or some similar function.) When the first signal activates, check when the second signal was last active. If it was recent (like seconds ago) then the second one activated first and this is an exit event. If it activated much longer ago, then this is an entry event.

    You will likely have to experiment with the timing settings for your configuration to get it to behave like you want.

    ReplyDelete