ESP-Now project I have uses NTP on receiver. I compare Barometric Pressure every 15 minutes to find the differenc from the previous 15 minute period.
For now I am sending readings from the sender every 4.5 Minutes to ensure readings are are available when 15 minute routine runs on the receiver. Really only want one reading 30 seconds before the 15 minute routine runs.
Looking at difference in Barometric Pressure for .20 change (experimental value based on my logs and frequency of occurrence) in Barometric pressure.
Any recommendations on syncing sender and receiver?
I don’t know if this is the best solution, but what you can do is:
- 30 seconds before the 15 minute routine, the receiver sends a message to the sensor node
- when the sensor node receives that message, it sends the reading back to the receiver
- then, the receiver proceeds with its 15 minute routine
I’m not sure if there is a better solution…
Another approach might be:
I am thinking of adding code from this sketch, I use in the receiver : NTP_System_Time.ino
Using this code I would disconnect from NTP time server after setting system time; if statement like:
if((MINUTE % 15) == 0) && ((Seconds) == 30) then send readings, could be added to sender code.
Do NTP time servers require always on connection or can connection to NTP server be disconnected, once system time is set? Reconnection to NTP time server would occur when ESP32 is reset by a deep sleep wakeup.
NTP time servers can be contacted any time you want but remember that using the internal RTC is very inaccurate and can lose/gain minutes every hour. You could use an external 32k crystal to get much more accuracy. Your code seems reliant on the accuracy of the clock.
Thank you Sara and Steve for your responses.
I have logs of ESP32_Sender and ESP32_Receiver with timestamps; after four hours of logging, works.
Querying NTP server one time when bootCount = 0; if clock drift is an issue, then querying NTP time server every 15 minutes can be tasked. When ESP32_Sender wakes from Deepsleep it connects to NTP time server, then disconnects. Should I turn off WiFi at this point? From wakeup to sending readings is taking 17 seconds, readings are sent at 15 Minutes and 0 seconds. ESP32_Receiver waits until 15 minutes and 30 seconds before completing 15 minute routine.
ESP32_Receiver is a merge of ESP32-Now and my exsisting Rain_Gauge –Weather, data logger project based on Asyncwebserver.
After requesting the time you can disconnect the Wi-Fi and it will keep the time in the ESP32 internal clock (it is not necessary, you can keep it connected – but it will consume more power. So, if you want to save power, you should disconnect).
Thanks for sharing your project.