-
Notifications
You must be signed in to change notification settings - Fork 75
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use asynchronous UDP library to get non blocking time update #60
Comments
Initial support of asynchronous UDP communication is ready in AsyncUDP branch. There can be many bugs but it is compiling and working in my local setup. |
Notice that for some time, I've moved NTPClientLib.h and .cpp to ESP8266 example folder. I need it so that Visual Studio Intellisense works properly. Move them to src folder for testing if you prefer to. |
Timeout processing is working now, using Ticker library. I've chosen this lib better than timer interrupts because it is available both on ESP8266 and ESP32 Arduino framework. |
It should be noted that
For example, ESPAsyncTCP client code directly uses sdk dns resolution What I am thinking about is maybe do the same? Instead of Edit: Plus, I was running this since yesterday without any issues. Disabled dns server, wrong ntp server ip, wrong dns address - client recovered and is ok so far. |
Good point! I did not think about this. I'll do that. Thanx |
@gmag11 thank You for such an awesome library. |
Hi. No, it is not released in master branch. But you can use it by selecting AsyncUDP branch. https://github.com/gmag11/NtpClient/tree/AsyncUDP |
@Misiu i'll take a look at it again this week. plus fixing minor esp32 example errors, as code paths will be the same for both esp8266 and esp32. By the way... sdk itself does provide sntp (and timelib analogue) support and arduino for both esp8266/32 expose it. have you tried it? |
@mcspr I never used the built-in sntp functions (I didn't know they existed till now 😄 ) |
I used them in older versions. But it was a mess to mantain different code for each platform. By that time esp32 did not include same sntp functions in its sdk, so I decided to get that code out of this library. |
@gmag11 so right now I could use |
(assuming recent esp8266/Arduino + lwip2 is used. my understanding is old sdk/lwip1.4 required manual sync because of some bugs) Quick look at how sntp/time works there, because I was interested how it compared to ntpclient/timelib combo. Initial success is determined by checking if And it will autotrigger sync when network settings change, so i believe it is set-and-forget. No error state to check though, besides initial sync success. edit in the example that @Misiu mentioned, there is cb when time is set: |
Callback functions are available. Check included examples |
So I did real device test of dns resolver with these changes: AsyncUDP...mcspr:async-dns On ESP32 it is broken - if ESP8266 is ok, server on the lan works fine when accessed via hostname. |
Can I get a feedback? Is async branch is relatively safe to use on esp8266? |
Btw not sure why would u waste time for ESP32? It has built in FreeRtos support. So anyone can put sync ntp in a task and dont bother with blocking thread. |
Is there working sample to use? |
@hostmit Like I said, esp8266 works fine for me (knock on wood): So if there is no reason to use asyncudp for esp32, ntpclient should have it's own task to run network requests in the background? |
Thanks. The DNS resolution still blocks the loop :( As for ESP32, I have ntp client updating only once. And yes, in vTask. Since ESP32 has RTC, no need to update more then once. |
AsyncUDP is now included on ESP32 core. I've included this platform on current AsyncNTP code and merged into develop branch. This will be part of future 3.0.0 version. As async DNS is missing it is not ready to be merged on master but you can consider this version as beta if you use IP address for NTP server. I'll start including async DNS resolution now. |
You are completely right. Async dns resolve works on ESP8266 and so does async NTP. With ESP32 async DNS gets the correct IP address but breaks something into lwip library and UDP connect causes code to freeze. Anyway, it seems that as @hostmit said on #60 (comment) , for ESP32, lwip runs on a separate thread so turn DNS solving asynchronous is not so important. I've confirmed this by reducing Then, finally I will leave ESP32 code as it is on develop branch and ESP8266 code as of AsyncDNS branch. I only have to clean code and add precompiler directives to separate achitectures. |
I've published Async version as 3.0.0-beta |
Slightly late comment 😴 I wonder if it is still worth adding additional dependency. ESP8266 client introduce couple of new things:
|
Hey @gmag11 , Is there any example how to use it ? Thank you in advance |
@tokra Maybe you find this video useful https://youtu.be/r2UAmBLBBRM Basically you need to call something like Definition is here After that you can get time with |
@gmag11 thanks for the link but thats not what i meant. I thought, how to use it with Async UDP.. The reason for ASYNC UDP, is that i am using AsyncMQTT client, For now i am using AsyncHttpRequest to worldtimeapi.org (non-NTP solution). But when i saw this I thought I can also use this Async NTP client. |
You do not need to update time every time. If you use my advise on inmediately previous message, ntp will not interfere your code. |
Got it thanks ! |
Now that I have the control of NTP sync procedure, it would be a very nice feature to add non blocking NTP request. This is possible by using ESPAsyncUDP library.
This have a side effect. Using this library would make next versions of NTPClientLib compatible only with ESP8266 and ESP32, as there is no equivalent library for MKR1000 and ArduinoWiFi.
Please add your thoughts and ideas in this issue.
The text was updated successfully, but these errors were encountered: