Sunday, November 17, 2013

Bridge communication - Part2

The message size that I need will be well below 266, more in the range of 30 characters or so. So I am continuing without caring why it crashes if we try to send long messages.

In my setup, the Linino side will be the master, sending out commands to the Sketch side. For example a command to set the temperature. Most commands will be accompanied by a value (e.g. the temperature).

Given the messages stay in the Bridge data store after a get, and the Sketch will be likely polling to see if there is a new command I need something to identify if a message is a new one or not. I will just use 1 character in the message, that should change for every new command.

So the message that the Linino side will put looks as follows:
1 message ID char + command + value

I made a C++ class BridgeComm.h that on top of the bridge, offers this functionality. It has a method that can check for a new message, if so it returns true + the null-terminated command and value.

Maybe the Mailbox class that is shipped with the Arduino does similar things, but it was just less time to make it using the Bridge.

For now the command will be 8 characters, the value 16. But that are just consts that can be changed in whatever I need.

My Yun sketch now looks as follows:

#include <Bridge.h>
#include <Console.h>
#include <BridgeComm.h>

BridgeComm bc;
char command_buff[BridgeComm::REQ_CMD_BUFF_LEN];
char value_buff[BridgeComm::REQ_VAL_BUFF_LEN];

void setup() {
  Console.println("Connected to the Console!");

void loop() {
     Console.print("Command received=");
     Console.print(", Value recieved=");

I made a simple Python script that every 2 seconds sends another command (Temp-Max,Temp-Min,Temp) and a temperature value.
The output of the Yun console looks as follows:

Command received=Temp-Max, Value recieved=22.5
Command received=Temp-Min, Value recieved=23.5
Command received=Temp    , Value recieved=24.5
Command received=Temp    , Value recieved=25.5
Command received=Temp    , Value recieved=26.5
Command received=Temp    , Value recieved=27.5
Command received=Temp    , Value recieved=28.5

Another step in the right direction.

No comments:

Post a Comment