I have a function to turn on/off diagnostic Publish calls for troubleshooting field devices. I’d rather they be off most of the time and only turn them on as needed.
I have a variable declared as:
bool diagnose = false;
I then have the following published function:
int toggleDiagnose (String command) {
int _command = command.toInt();
if (_command==2186) {
Particle.publish("DiagnosticToggled",PRIVATE);
diagnose = !diagnose;
return 1;
}
else {
return 0;
}
Obviously, in my setup() function, I have the following:
Particle.function("toggleDiag",toggleDiagnose);
In my code (state machine) I have logic similar to this in various state functions:
if (diagnose) {
Particle.publish("fanTurnedOff",PRIVATE);
}
This helps me see what state the application is in. It seems that I can call the toggleDiagnose function once and any additional calls seem to return “Error”.
Also, is there any difference in declaring a variable “bool” vs “boolean”? They both seem to be accepted by the compiler.