I’m having some weird issues with Particle.connect() timeouts, sleep, and subsequent publish. On rev. 0.7.0
The photon starts out without connecting because in the actual application there would be some code running that would decide whether or not to connect to the cloud.
The following code is designed to:
- timeout the Particle.connect()
- sleep for “sleepIntervalTimeOut”
- resume from where execution left off
- take a measurement of WiFi RSSI, and publish it
- wait 8 seconds to let publish do its thing
- disconnect from cloud, then shut off wifi
- sleep normal interval, sleepIntervalNormal
What happens is that upon powerup,
- timeout, white led flash and sleep
- on wakeup, code continues and automatically connects to cloud and publishes, however it publishes “0” instead of the expected -127 to -1 reading
- goes back to sleep
- wakes up and repeats cycle-- however now all subsequent cloud connections do not publish anything!
Thanks in advance.
SYSTEM_MODE(SEMI_AUTOMATIC);
SYSTEM_THREAD(ENABLED);
String sleep_test;
const int MAX_TIME_TO_CONNECT_MS = 50; //wait time for wiFi/cloud connect (millis)
const int sleepIntervalTimeOut = 15; //sleep time if cloud connect timed out (s)
const int sleepIntervalNormal = 10; //normal time between measurements (s)
int wifiStrength;
void setup() {
pinMode(D3, INPUT);
}
void loop() {
publishData();
System.sleep(D3,RISING,sleepIntervalNormal);
}
void publishData() {
Particle.connect();
if (!waitFor(Particle.connected, MAX_TIME_TO_CONNECT_MS)) {
System.sleep(D3,RISING,sleepIntervalTimeOut);
}
wifiStrength = WiFi.RSSI();
sleep_test = String(wifiStrength);
Particle.publish("sleep_test", sleep_test, PRIVATE);
delay(8000);
Particle.disconnect();
WiFi.off();
}