Closed hdznrrd closed 8 years ago
Hi, We (SB_Bremen_1) experience similar problems. In our case the SenseBox is still working and accessible via LAN, but does not submit data to the server anymore. After a power cycle it works again. https://opensensemap.org/explore/56b3ca1a2cb6e1e410499cb5
I just took a look at the code and found the culprit: it's millis() overflowing after ~50 days[0].
The following is the code doing the check inside loop()
:
if (millis() - oldTime > postingInterval) {
oldTime = millis();
Once millis() overflows you're done for and the code inside the conditional will never run again.
thanks @hdznrrd for reporting and troubleshooting this bug. thanks @frankolivergloeckner for confirming it.
We will try to find a solution [0] tomorrow.
[0] http://arduino.stackexchange.com/questions/12587/how-can-i-handle-the-millis-rollover
@hdznrrd and @frankolivergloeckner: what do you think about this fix / solution:
We removed the causing if clause from the loop()
and added a sleep()
method to the end.
// millis() rollover fix - http://arduino.stackexchange.com/questions/12587/how-can-i-handle-the-millis-rollover
void sleep(unsigned long ms) { // ms: duration
unsigned long start = millis(); // start: timestamp
for (;;) {
unsigned long now = millis(); // now: timestamp
unsigned long elapsed = now - start; // elapsed: duration
if (elapsed >= ms) // comparing durations: OK
return;
}
}
void loop()
{
// read sensor values and post them and so on...
sleep(postingInterval);
}
Our hardware guy @janwirwahn is not available for 1,5 weeks. When he is back, we will check the fix and roll out an update for all boxes.
The sensebox at shackspace[0] seems to hang up after a prolonged runtime and requires a powercycle to work again. Is this a problem specific to our box or do other boxes show this behavior as well? Shot in the dark: the watchdog timer could be a way to at least fight the symptoms.
[0] https://opensensemap.org/explore/56a0de932cb6e1e41040a68b