Hi All,
I implemented a gateway to receive IR and RF signals to control Philips Hue lamps
and
and convert some IR commands to RF.
I have some problem in generating the command to be sent to the server.
I need to create a message like:
{
on: true,
bri: 150,
hue: 65,
sat: 20
}
I create two functions.
- setHue(int hueID, String command) that send the proper command to the light
- setHue( int hueID, boolean on, int hueBri, long hueHue, long hueSat)
to concatenate the 4 parameters (on/off, bri, hue, sat)
The first function works only if the command is very short
If I run the function setHue with a short command everything is fine,
otherways Arduino doesn't boot.
//This works
setHue(1, "{ \"on\":true}");
//This doesn't work (but compiles with no problems)
setHue(1, "{ \"on\":true, \"hue\": 168, \"bri\": 24975, \"sat\": 253}");
Here is the code for the other function
boolean SetHue(int hueID, boolean on, int hueBri, long hueHue, long hueSat)
{
String hueCmd="{";
if(on==1){
hueCmd = hueCmd + "\n \"on\":true";
if(hueHue>0){
hueCmd = hueCmd + ",\n \"hue\": " + String(hueHue);
}
if(hueBri>0){
hueCmd = hueCmd + ",\n \"bri\": " + String(hueBri);
}
if(hueSat>0){
hueCmd = hueCmd + ",\n \"sat\": " + String(hueSat) ;
}
hueCmd = hueCmd + "}";
}
else
{
hueCmd = "{\"on\":false}";
}
return SetHue(hueID, hueCmd);
}
Here is the complete source code
~~http://pastebin.com/Zv31F6hf~~
Attached you can find the complete source code
IR_RF.ino (6.97 KB)