I would like to send my Photon to sleep after it has published a message. The problem is that the dashboard never receives my message.
My loop code:
// Read the volatge of the LiPo
float cellVoltage = batteryMonitor.getVCell();
// Read the State of Charge of the LiPo
float stateOfCharge = batteryMonitor.getSoC();
// Send the Voltage and SoC readings over serial
Serial.println(cellVoltage);
Serial.println(stateOfCharge);
// wait for the cloud connection to be connected or timeout after 10 seconds
if (waitFor(Particle.connected, 10000)) {
bool sent = Particle.publish("Data", String::format("voltage=%.2f;charge=%.0f"), cellVoltage, stateOfCharge)); //data,name=Maraiah internal=29.5,external=13.3 1434055562005000038
Particle.process();
if(sent == true){
System.sleep(pin, RISING, sleep);
}
}
I found the hint with Particle.process(); here but it does not seem to work for me. I don’t like to use a delay because it blocks my code.
The if(sent == true) does not work either.
Without sleep everything works fine.
Is there a new solution for the 0.4.9 firmware?
bool sent = Particle.publish("Data", String::format("voltage=%.2f;charge=%.0f"), cellVoltage, stateOfCharge));
Does this build at all?
The parentheses in this statement don’t seem to match up.
Another option to make sure your publish got delivered is to self-subscribe and place the sleep command into the subscribe handler.
BTW: The return value of Particle.publish() does not tell anything about the actual publication but only if the command has a chance to get executed at all.
Another thing you might consider is that you are not alone there and Data is a rather ubiquitous term, so you might receive events from others who have also used such an all but unique event name
You should either go for a less common term or send as PRIVATE (or both).