Here’s stripped down code of what I’m working with.
const char* on = "false";
float setTemp = 0.00;
void setup(void) {
Particle.function("setData", setData);
}
void loop(void) {
char tmpData[64];
sprintf(tmpData, "{ \"setTemp\": %2.2f, \"on\": %s }", setTemp, on);
Particle.publish("getData", tmpData);
delay(2000);
}
int setData(String command) {
int loc1 = 0;
loc1 = command.indexOf(",");
setTemp = command.substring(0,loc1).toFloat();
on = command.substring(loc1+1).c_str();
return 1;
}
When I call setData() from the CLI with:
$ particle call PHOTONIDHERE setData "67.25,true"
And then listen to my getData event with:
$ particle subscribe getData PHOTONIDHERE
The value of ‘on’ gets set to ‘P_’ instead of true. But I’ve also seen it set to ‘U’ and ‘t_’:
{"name":"getData","data":"{ \"setTemp\": 67.25, \"on\": P_ }","ttl":"60","published_at":"2015-10-26T14:00:38.795Z","coreid":"..."}
Admittedly, I’m new to C++… Any help is much appreciated!