0

My Arduino (actually an ESP32-based Adafruit HUZZAH32) is running as a wifi server. Its main job is to service GET requests from a user, and to periodically turn devices on and off based on the commands implicit in those GETs.

It needs to keep an accurate time/date - in order to turn devices on/off as directed. My cheap real-time clock is off a couple seconds or more per day. So I figure I'll use code such as the example at:

https://randomnerdtutorials.com/esp32-ntp-client-date-time-arduino-ide/

... in which the Arduino creates a client to get the time from an NTP server. Once a day (e.g. checking for the RTC time to be 00:00hrs in my "loop"), I'll adjust the RTC using NTP.

Looking around, it sounds like this is ok, for the Arduino to act as a client, as long as it's not actively servicing a client (the user's GET requests). Do I have that right ? Need I worry that a user might be sending a GET when that happens ?

2

There is no problem with running multiple servers and use multiple clients with the WiFi library of the ESP32 core for Arduino as it is not a problem with most of the WiFi libraries for Arduino (some can't run servers (TinyGsm) or can run only one server (WiFiEsp(AT)).

But you don't need a WiFiClient for NTP time. First because NTP runs on UDP and second because the ESP32 SDK provides SNTP and the ESP32 core for Arduino wraps it in functions presented in the ESP32 examples library's SimpleTime example.

  • I have used the code in the SimpleTime example and it works like a charm. Thanks. I'm simply going to call getLocalTime once a day and reset my RTC. I don't care if I'm off by a few seconds, just don't want those to accumulate over many days. – RustyShackleford Aug 25 at 17:15
  • I was mildly concerned I could get into an infinite loop - RTC is running fast, when time of day for adjusting via SNTP comes, it gets reset to slightly earlier time, and then hits the adjustment time again. But that's just silly - it doesn't get retarded much at all the second time. – RustyShackleford Aug 25 at 17:23
  • what for the RTC? ESP32 has built in RTC and updates it over SNTP – Juraj Aug 25 at 17:38
  • I am using cheap ($4.95) PCF8523 w/ battery. – RustyShackleford Aug 25 at 21:10
  • I did not know about one on ESP32 (Adafruit's doc for HUZZAH32 does not mention it). It appears to require an external crystal for any kind of reasonable accuracy, and doesn't maintain if ESP32 is off. Of course, if I usually am wifi-connected and with SNTP, maybe that doesn't matter. – RustyShackleford Aug 25 at 21:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.