Using the new Arduino IDE for ESP8266 and found bugs, report them here

Moderator: igrr

User avatar
By BeeGee
#46438 Not sure if this is a bug or just a limitation, but I could not find any limitation for the maximum trigger time.

I tried to use a ticker to trigger an action in 1 or more hours.

If I use timerEndTimer.attach_ms(onTime*3600000, triggerTimerEnd); it works as long as onTIme is 1 (hour). If I set onTime to 2 (hours) or more the function triggerTimerEnd is never called.

Arduino IDE 1.6.7
Board esp8266 by ESP8266 Community version 2.2.0

Hardware Adafruit HUZZAH ESP8266

Code extract that fails if trigger time is > 1 hour:
Code: Select all#include <Ticker.h>

/**
   triggerTimerEnd
   called by Ticker timerEndTimer
   sets flag timerEndTriggered to true for handling in loop()
   will initiate switching off the aircon after programmed hours
*/
void triggerTimerEnd() {
   timerEndTriggered = true;
}

void setup() {
      .....
}

void loop() {
      .....
      // Start timer to switch off the aircon after "onTime" (default = 1 hour = 60mx60s+1000ms=3600000 milliseconds)
      timerEndTimer.attach_ms(onTime*3600000, triggerTimerEnd); // Doesn't work if more than an hour
      .....
}

Code workaround to get it running:
Code: Select all#include <Ticker.h>

void triggerTimerEnd() {
   timerCounter++;
   if (timerCounter == onTime) {
      timerEndTriggered = true;
      timerCounter = 0;
   }
}

void setup() {
      .....
}

void loop() {
      .....
      // Start timer to switch off the aircon after "onTime" (default = 1 hour = 60mx60s+1000ms=3600000 milliseconds)
      timerEndTimer.attach_ms(3600000, triggerTimerEnd);
      .....
}


The workaround just uses a counter to check if the requested amount of time has passed. This works of course only in my case and if the trigger times are multiples of 1 hour.

More detailed code examples attached:
ticker-test-fail.ino

ticker-test-ok.ino

Full source code available on:
Github repository
You do not have the required permissions to view the files attached to this post.
User avatar
By Barnabybear
#46440 Hi, the ESP can only use 32 bits to measure time, as times are calculated in uS this gives a total of 71 mins.
32 bits = 4,294,967,295 / 1,000,000 = 4,294 Seconds / 60 = 71 Minutes.

The workround as you say is a counter. It realy winds up the poeple using batteries and deep sleep to wake every hour.
User avatar
By BeeGee
#46442
Barnabybear wrote:Hi, the ESP can only use 32 bits to measure time, as times are calculated in uS this gives a total of 71 mins.
32 bits = 4,294,967,295 / 1,000,000 = 4,294 Seconds / 60 = 71 Minutes.

The workround as you say is a counter. It realy winds up the poeple using batteries and deep sleep to wake every hour.


You're rigth, I forgot about the 32bit limit. Strange thou that in ticker.h .attach() is defined as void attach(float seconds, callback_t callback) with the time as float value. However .attach_ms() is defined as void attach_ms(uint32_t milliseconds, callback_t callback). ==> Confusing. And attach() is just calling attach_ms with casting the time from float to uint32 and multiply by 1000.
User avatar
By martinayotte
#46458 We should not confuse between deepSleep() which is in microseconds and os_timer_arm() which is in milliseconds.
Of course, the second is part of Espressif SDK, and maybe under the hood, it is using the same kind of timer with this 32bits microseconds limitation, who knows ...