Recently, I've been writing an Arduino(Yún) sketch to get RGB values(0-255) from the bridge. I have Bridge.begin()
in the setup and the following in the loop:
Bridge.get("r", r, 4);
Bridge.get("g", g, 4);
Bridge.get("b", b, 4);
Which should get the value from the bridge(1st argument) and set the local variable to it(2nd argument). The local variables r, g and b are defined with char r[4];
(obviously each with the appropriate name). I understand all of this, however there is a problem:
The first Bridge.get()
call always returns \u0001
(Start of heading). I have solved this by adding a dummy bridge get to the beginning of the loop, however this seems weird to me because the first call returns the "Start of heading" in every loop.
Why is this and is there a better way to fix it?
EDIT:
The code is put to the bridge by a python script running on the Linux side of the Yún. The following is shortened because the code that works out the RGB values is fairly long, messy and shouldn't be part of the problem(famous last words :D).
#!/usr/bin/python
from sys import path
path.insert(0, '/usr/lib/python2.7/bridge')
from bridgeclient import BridgeClient
link = BridgeClient()
link.put("r", str(int(r)))
link.put("g", str(int(g)))
link.put("b", str(int(b)))
The arduino code(once again abridged) is as follows:
#include <Process.h>
char r[4];
char g[4];
char b[4];
void setup() {
Bridge.begin();
}
void loop() {
Process colo;
colo.runShellCommand("/mnt/sda1/colours.py");
while (colo.running());
Bridge.get("r", r, 4); //this command(whatever key it’s getting) always returns \u0001
Bridge.get("r", r, 4);
Bridge.get("g", g, 4);
Bridge.get("b", b, 4);
}