Last August I blogged about an idea I had for an equivalent of Twitter, but for short messaging between resource limited microcontrollers.
With a little bit of thought, this could become a very simple means for smart sensor nodes or simple devices to communicate via the Internet of Things.
I had already experimented with simple CSV serial command strings to control an instrument I was developing, which used an Arduino. Typing commands in the serial window, sent data to the serial port of the Arduino, which was then decoded and used to invoke certain action routines to control various functions. This worked well, used a human readable (memorable) set of alphabetical and numeric commands, and used very little firmware overhead to write a simple command interpreter. Easy enough for even my C-skills to cope.
The command interpreter was as rudimentary as a series of switch/case statements that if you receive character "a" do this action, "b" do another action and so on.
So I had character "a" controlling signal amplitude, "b" for setting the brightness of the LEDs, "s" for setting the position (angle) of a R/C servo, and so on.
s,90 would move the servo to its 90 degree position - it really was that simple!
About the same time, I was getting interested in remote sensors and home automation. It dawned on me that my messages were identical to a Pachube CSV feed, and that Pachube could easily be used without modification to get data from one microcontroller to another.
The whole thing would be set up as a Publisher/Subscriber messaging model.
The message would consist of a few characters of data or arguments, separated by commas, which would be broadcast from one device to many subscribers using a Pachube CSV feed as a data exchange mechanism. All of the hard work was done by the Pachube API.
With the advent of low cost hardware, in the form of the Nanode, the need for this message format is now growing, and it is hoped that some ideas can be discussed and tried at the Pachube Internet of Things Hackathon at the end of this week.
For one thing, the messages need to be short, just a few bytes of data to convey the minimum of information necessary to convey sensor readings or command data. In the case of wanting to directly control a remote device, the remote device needs to be alerted that the message is intended for it.
In a similar fashion to Twitter, use of the @ character could be used to indicate that a message is aimed at a particular node. Conveying context in the message could be done purely by the order of the arguments, or by preceding a particular argument with a special character.
Again, borrowing from Twitter, the hash symbol # could be used to precede an argument, to convey that the argument is a particular subject. An example of this might be two Nanodes controlling some sort of central heating system. Let's assume that the relay to control the boiler is controlled by digital output 8. Using #8 could be used from the sending Nanode to signify that it is refering to an object on "number 8" and the next byte could be used to define what state it should be in. This would be a good way to convey 8 bit PWM commands to particular pins of a given Nanode.
The sort of operation we wish to perform on a microcontroller involve the setting and reading of port lines, reading and writing to memory or registers, outputing PWM, making ADC measurements and timing pulses. Additionally we may have a list of high level action routines pre-programmed into the Nanode, which we just want to invoke, on receipt of a certain command. Nano-tweets could be devised to be non-machine specific - a bit like the register based Firmata protocol. A simple command interpreter, written for a given microcontroller, would be all that was needed to handle nano-tweeting. Moving to a different micro would be simple.
For debugging purposes, it may be beneficial if these Nano-Tweets are semi-human readable - so the use of memorable characters or punctuation marks will be useful in achieving clarity of meaning.
Nano-tweets consisting of comma separated arguments can be transmitted down various kinds of network, wired, wireless or ethernet. A nano-tweet originated by a web connected Nanode, published up to Pachube could be echoed by a remote Nanode down it's local serial bus and used to control slave Nanodes connected to that bus.
Over the next few weeks, I need to define the nano-tweet protocol, and write a generic nano-tweet command interpreter, which can be applie dto many different applications.