Regulars will realise that I am busy finding ways of getting low cost web enabled Arduino based boards to talk to each other.
The solution that I stumbled upon is to use a Pachube feed as a message depository, and have other ethernet enabled Arduinos subscribe to this feed and take action based on the CSV data returned from the feed.
Suppose we have a command string B,5,100,200,50 which is used to set the brightness levels of a RGB LED to 100,200,and 50 respectively. The preceding letter "B" identifies this as a Brightness setting command and 5 is the sub-address of the Arduino board which we want to execute this command.
So a controlling, web enabled Arduino can publish the B,5,100,200,50 command to a Pachube feed in the form of a CSV string, and other web enabled Arduinos will subscribe to this feed, retrieve the CSV string, decode the command - and Arduino 5 will act on the message, setting its PWM outputs accordingly.
It's a fairly trivial example, but it does illustrate how a simple message can be passed from one controlling device to another using Pachube as a message brokerage service. The advantage of using Pachube is that it provides a certain level of security by way of it's API-key, and the low overhead of getting CSV data to and from Pachube makes the method applicable to the limited resources of a small microcontroller.
It occurred to me that this pub-sub model of messaging between micros is a scaled down version of what Twitter offers and the messages from the web enabled sensors are "Tweet like". Just to be topical, and to give it a name, I'm going to call this "micro twitting" with the message being known as a u-twit. (Homage to YouTube and indirectly my programming abilities). It was going to be called micro-tweet, but someone has already nabbed that name!
The contents of the message can either take the form of instructional and numerical command, or numerical sensor data. The exact nature and context of the message contents can be signified by a message type identifier.
A command interpreter running on the Arduino, identifies the message type, and any data content and acts accordingly. If in the case that the message is not intended for the web-connected master device, then it can be passed on, unchanged to the serial port and on to the local network of slaves.
Any Arduino hardware running a micro-twit interpreter can be connected to the serial bus and decode and act upon the message. It might be possible to use the system of hash-tags and @, as used in Twitter to identify subjects and publishers/users.
The pieces started falling into place with the assistance of John Crouchley's Pachube GET sketch implemented on an Ardunio with NuElectronics ethernet shield. John enthusiastically produced this at the drop of a hat, realising that I was wishing to do something similar.
I've now got John's sketch running on one Arduio/NuElectronics shield, printing out the CSV data sent to my Pachube feed by my ATmega328/ENC28J60 combo board.
Slowly the pieces are coming together :-)
No comments:
Post a Comment