BlynkTimer vs Ticker

Hi There,

I’m just wondering what would be benefits/advantages of using one or the other? TickerScheduler or BlynkTimer.

I’m currently using BlynkTimer to read a RS485 device but The read RS485 is a blocking function with 2000ms timeout and expecting some WDT problems, specially when the Blynk Provisioning stays in Config mode for a long time.

I don’t know anything about Ticker or TickerSchedualer… but BlynkTimer (based on SimpleTimer) is well documented in this forum and thus the probable better choice for Blynk applications.

And I suspect that neither will help avoid any timing issues from a Bbocking function… blocking is blocking.

1 Like

Thanjs just thought I could use both function. Ie. When BlynkTimer is blocked the Ticker would keep running

Why would BlynkTimer be blocked?? It is not dependent on a server connection, or even a WiFi connection…

It is based on SimpleTimer… a regular Arduino based timing library.

http://playground.arduino.cc/Code/SimpleTimer

As stated in the documentation…

http://docs.blynk.cc/#blynk-firmware-blynktimer

I have used Ticker in one of my projects. Actually it is still there and it is working, but then switched to SimpleTimer as a more flexible tool, or just using own timing routines. Personally I would avoid using both. It’s a bit like having two the same sensors and using different library to each :stuck_out_tongue:

@Gunner I need to remind myself, but AFAIK the Ticker doesn’t need pooling, like the SimpleTimer do. I have used it to count short periods of time, but as I said - don’t remember it well already.

I have no idea why but when reading RS485 it blocks the Virtual Write during timeout and it becomes laggeg.

And Provisioning Library uses Ticker to blink the LED.

I have no idea how you are reading that device… but if it is like every other serial device, then it tends to want ALL the devices attention while it waits for an incoming byte (generally using while() )… and that is always a bad thing for any timing as it is a blocking process.

It is not the SimpleTimer “who” blocks the virtualWrite, it’s the opposite! :wink: But disturbing the virtualWrite is not a good idea, as it might break the comm.

Yes, just checked/reminded myself and Ticker doesn’t need pooling. So it is somewhat deeper in the core than SimpleTimer .

Thought so and that’s why I considered using another option to blink Blynk LED.

As far as I understand, ticker would set flags and call for functions in the main loop.

Thanks for all the inputs

Ticker is specifically for the ESP environment, isn’t it? Thus will work more integrally… but still, a blocking command will probably block it as it would any other process…

I don’t think it’s going to make any difference if you use Blynk Timer or Ticker, as soon as either one of them triggers the function to read your sensor (and that sensor blocks the execution of the code) you’re going to get the same result.

Pete.

1 Like

Yes, sure!

Hmmm… this wasn’t that simply as I remember it. I recall I had a WDT resets, which I managed to “connect” with Ticker library. I had to avoid any blocking code, and it wasn’t that easy. This was one of the reason i dropped Ticker, but then - for a simple tasks like switching the output it might be very useful. A Ticker alone might have changed since, as well as the ESP core did…

In ticker library:
os_timer_arm();
os_timer_setfn();
os_timer_disarm();

which are parts of ESP core. So it MIGHT be they are resistant to blocking from our code…

Or meet the WDT reset :stuck_out_tongue:

I’ll try it and will share the results.

I have the RS485 Device disconnected at the moment and ESP8266 reads every 15s with a 2s timeout. Didn’t face any WDT yet, has been running for few days now.