Sunday, June 26, 2011

The "Internet of Things"

On an older post I mentioned that I have migrated the output of the sensors on my weather station to thingspeak. Thingspeak.com is a service that make an API available to you that takes data from your sensors and then makes it available for your (and others if you so desire) use in ways that go from chart building or any other customized way you can think of.

There's a lot of potential in that. For instance, in my case, I used to generate my own charts (this link may not be active at the time you read this) for my weather station. It worked but in a way it was a waste of my time. I spent ma lot of time writing the code to generate the charts(even though I used a graph generating library I still had to prepare the data to be displayed - things like fetching the data from the database, extracting the highest, calculation of averages and things like that). I wanted to concentrate on the hardware, the Arduino programming and the analysis
 of data. For my own applications, this is where thingspeak.com came in.

The idea is simple: make it easy for the user to upload sensor data to a server and then offer tools to manipulate that data while at the same time offering easy ways to make the raw data available in the case the user want to actually do something more customized that what can be done using the tools of the website.

To achieve the above, thingspeak developed an open source API that takes your data and makes it available to you later. Like in any other API, you need to follow a protocol (a way to interact with the API to post and retrieve data).

The API interaction is extremely simple; I was up and running in literally 5 minutes. To start, follow this simple steps (I use PHP to interact with the API, there's some other tutorials to teach you how to do the same with other platforms, including how to do it directly from the Arduino):

1. create an account on the thingspeak.com website.

2. login and go to the channels tab

3. click the "create new channel" button

4. change the channel name to something that makes sense to you and for others (this will later show up on the list of available channels) - in my case I chose "Weather Station Macau SAR, China".

5. go through the list and input other data as you see fit - you can always go back and edit the information. Click on the "Make Public?" check box to make the data public and therefore giving others the chance to use your data on their own projects.

6. then, add your sensors to the Field list. For example, if you have only one sensor that is a temperature sensor, add "Temperature" to the field 1 text box. Then click "Create Channel".


At the end of the steps above you have created a channel that can be thought of as an opening door to your "region" of the thingspeak server. The next step is to use the API to load data to that "region".

To add data do the following (using PHP):

1. on thingspeak.com return to the channels page

2. note the box on the right on the channels page and note the section "Sending Data" and specifically the following line: 
http://api.thingspeak.com/update?key=YOUR_KEY_HERE&field1=0

3. Make a note of the sequence of characters that make up your API keys and identified above as "YOUR_KEY_HERE"

4. on your PHP code add the following lines:
$post_thingspeak = "http://api.thingspeak.com/update?key=YOUR_KEY_HERE&field1=".$temp.""; $response = file_get_contents($post_thingspeak); echo "| thingspeak.com reply: $response"; Above, $temp is the variable that holds the temperature value. Replace "YOUR_KEY_HERE" by the characters that you noted on step 3.

And that is all you need to post to the API. After these steps are complete, it might be useful for debugging purposes to check your channel feed by going to the "Viewing Data" link on the channels page and checking the raw data being sent to the thinkspeak server. By the way this is also how you would access the data to be used on your own applications, but this is a subject for another post.

Hope this helps to cut the time of using the thingspeak.com service using PHP from the 5 minutes it took me to 4 minutes.

Brilliant Manipulated Plastic Balls!

Here's a great project idea, that requires a great deal of work, better to be undertaken as a team. Anyway something of this scale might be a little over kill for most of us, but perhaps something smaller on the same lines could still be quite impressive.

Take a look at the video below and leave some comments in the comments area. The only thing I really don't get about this video is that it shows you the preparation phase (like getting the magnet, getting the electronics inside the balls) but then is quite brief on showing the actual thing working. I would happily take a full 10 minutes or more just looking at the movement of the balls!



INDUCTANCE - Physalia from F5 on Vimeo.

Saturday, June 25, 2011

Weather Station migrated to thingspeak.com

I just migrated the output of my weather station to thingspeak.com. thingspeak is a start to the implementation of an "internet of things", much like the more famous pachube. A fundamental difference is that thingspeak is open source and pachube isn't (I found this article that says pachube is open source, but I can't find the source or anything that talks about the code being open on the pachube website). I'm an open source guy, so I had to go for thingspeak!

The main differences from the previous versions of the weather station software are not many really, basically:


/*Main Changes on this version:
1: Removed connection to LCD (there's a web interface anyway!)
2: Added luminosity sensor
4: Optimized the code a little
5: Cleaned up the code making it easier to read
6: recalculation for rain (5 sec sampling is too fast, 
I never got any rain readings. Increased to 30 seconds)
7: Added a bit more comments to make the sensor setup more clear
*/

The required and revised code has been uploaded to the code page. And checkout the new graphs here.