I have been using ThingSpeak for a while now and I decided to create my own API for logging IoT readings. The main reason for this is that ThingSpeak require me to manually set it up for each thing I want to log. I think this is tiresome and not as easy as I want it to be. Also I need one api key for each of my connected things. Last, but not least, I don't know how long my data is my data. They may "pull the plug" at any time and have me pay for the service (something I can easily understand).
Due to the above mentions I decided to create my own API for logging IoT. I had some criteria I wanted to follow:
- Use open source
- Easy to use
- No setup before adding a thing
- Easy to read and understandable URLs
When this was written, I have already implemented what I need. I guess I will add more functionality in the future. Here are some of the API calls and an explanation. I will use an outdoor wireless temperature sensor as an example. The sensor is read from a receiver connected to my server. The server will call the API as described below.
I want to log the outside temperature and humidity. To do this I call the API as follows:
{url}/tweet/outside?temperature=23.5&humidity=35
I do this without setting up the "outside thing" first. The system will recognize "outside" as a thing and "temperature" and "humidity" as properties with values automatically. I may add as many property/value pairs as I want.
To read back the latest reading I will use:
{url}/readtweet/outside
This will return the following json (The date is in Norwegian format):
{ "thing": "outside", "lastupdated": "10:23:49 31.07.2014", "temperature": "23.5", "humidity": "35" }
If I want to read back only the temperature I will use:
{url}/readtweet/outside/temperature
This will return the single value 23.5
Maybe I want to read the 2 latest loggings:
{url}/readtweet/outside/temperature/2
This will return the 2 latest readings in json format, like this:
[ { "thing": "outside", "date": "2014-07-31 10:23:49", "temperature": "23.5" }, { "thing": "outside", "date": "2014-07-31 09:57:25", "temperature": "23.2" } ]
I have also implemented triggers and charts in this API, but more of this later.