I’ve been trying to use a Xenon as a temperature sensor that will wake up every 10 minutes, take a temperature reading from a DS18B20, publish it, and go back to sleep.
It works flawlessly for 1-3 days and then the Xenon will just stop reporting a temperature. I can see that the Xenon does continue to wake up every 10 minutes because the LED starts blinking like it’s connecting to the cloud but it goes back to sleep without ever connecting. Once it’s failed, rebooting will not get the Xenon to work again. The only thing that seems to help is putting the Xenon into safe mode and then re-flashing the firmware. Then it works again for another 1-3 days. That’s why I think the firmware is being damaged somehow
I’ve tried with 2 different Xenons with the same result. I’m using an Argon as a gateway, both devices are on 1.5.2 device OS, but I’ve been struggling with this for months and kept my devices on the latest firmware.
Here is the code I have on the Xenon:
#include "DS18B20"
SYSTEM_MODE(SEMI_AUTOMATIC);
SYSTEM_THREAD(ENABLED);
const int connectionFail = 5000 ;
const int MAXRETRY = 120;
const int sleepTime = 600;
DS18B20 ds18b20(D2, true); //Sets Pin D2 for Temp Sensor and
// this is the only sensor on bus
char szInfo[64];
double celsius;
long wakeTime;
void setup() {
ds18b20.setResolution(12);
}
void loop() {
Particle.connect();
if (waitFor(Particle.connected, connectionFail)) { // if connected to the cloud, process this cycle
getTemp(); // take a measurement every interval, just within Mesh network
if (!isnan(celsius))
{
sprintf(szInfo, "%2.1f", (float)((int)(millis()-wakeTime))/1000);
auto result = Mesh.publish("WorkingTime", szInfo);
if (result)
System.sleep(D6, RISING, sleepTime);
else
{
digitalWrite(D7, HIGH);
delay (1000);
digitalWrite(D7, LOW);
System.sleep(D6, RISING, sleepTime);
}
wakeTime = millis();
}
else
delay(1000);
}
else
System.sleep(D6, RISING, sleepTime); // unable to connect to cloud, go to sleep and try again next time.
}
void getTemp(){
float _temp;
int i = 0;
do {
_temp = ds18b20.getTemperature();
} while (!ds18b20.crcCheck() && MAXRETRY > i++);
if (i < MAXRETRY) {
celsius = _temp;
}
else {
celsius = NAN;
}
sprintf(szInfo, "%2.1f", celsius);
Particle.publish("dsTmp", szInfo);
Mesh.publish("dsTmp", szInfo);
}
Is there anything in my code that could be causing the device to stop working without reflashing? Or is there a bug in the deviceOS?
I don’t really need any mesh functionality for this project and can use all Argons since I can just do everything with cloud publish and subscribe, but the sensor nodes have to be battery powered, and given how much longer it takes an Argon to connect to the cloud compared to the Xenon, I won’t get enough battery life using Argons directly in my sensor nodes.
Thanks