millis() and ESP.restart() on ESP-01
Posted: Sun Aug 16, 2015 2:12 am
Hello All,
I'm still completely amazed by the power of this little device and being able to program it using the Arduino IDE just makes it even cooler
Thanks to those making this possible!
Now I have a question. I am building a small project that POST data to a web server every hour.
What I have done so far is working as expected except sometimes.
First the problem: in my SQL DB I should see an entry every hour and that works for quite some time but all of a sudden it starts sending data much faster and goes back to normal. See timestamps:
2015-08-15 21:32:33
2015-08-15 22:32:33
2015-08-15 23:32:33
2015-08-16 00:32:34
2015-08-16 01:32:34
2015-08-16 02:32:34
2015-08-16 03:32:34
2015-08-16 04:32:35
2015-08-16 05:32:35
2015-08-16 06:31:39 <-- going little bit backwards already strange as it worked rock solid for the last 9h but anyways I don't need to be that precise
2015-08-16 07:31:39
2015-08-16 07:37:01 <-- this is where it starts to act weird. why does it send data that quickly after last one?
2015-08-16 08:37:00
Basically the code looks like this:
So what this does is post data right when started and then sleeps for 1h.
I'll keep investigating on my side but I'm kind of stuck and was wondering if someone would have a clue.
Any help will be, of course, much appreciated Thank you!
I'm still completely amazed by the power of this little device and being able to program it using the Arduino IDE just makes it even cooler
Thanks to those making this possible!
Now I have a question. I am building a small project that POST data to a web server every hour.
What I have done so far is working as expected except sometimes.
First the problem: in my SQL DB I should see an entry every hour and that works for quite some time but all of a sudden it starts sending data much faster and goes back to normal. See timestamps:
2015-08-15 21:32:33
2015-08-15 22:32:33
2015-08-15 23:32:33
2015-08-16 00:32:34
2015-08-16 01:32:34
2015-08-16 02:32:34
2015-08-16 03:32:34
2015-08-16 04:32:35
2015-08-16 05:32:35
2015-08-16 06:31:39 <-- going little bit backwards already strange as it worked rock solid for the last 9h but anyways I don't need to be that precise
2015-08-16 07:31:39
2015-08-16 07:37:01 <-- this is where it starts to act weird. why does it send data that quickly after last one?
2015-08-16 08:37:00
Basically the code looks like this:
Code: Select all
//include libraries
#include <ESP8266WiFi.h>
// clock watcher
unsigned long interval = 3600000;
boolean probe_sent = false;
[..]
void loop() {
// if millis() reached interval (1h) restart ESP
if(millis() >= interval) {
ESP.restart();
}
if(!probe_sent) {
// initiate wifi link
// connect to web server
// post information
// set probe_sent to true
// disconnect from AP
// set WIFI_OFF
}
}
So what this does is post data right when started and then sleeps for 1h.
I'll keep investigating on my side but I'm kind of stuck and was wondering if someone would have a clue.
Any help will be, of course, much appreciated Thank you!