Of course most robust way of adding timestamp using a real time clock (RTC) module with ESP32. However, RTC modules will need a display and buttons to set the correct time. To just get a timestamp, total thing will get more complicated. Obviously, from Arduino UNO to ESP32 has internal clock which are actually usable for ordinary works. But when we are already connected to the internet (we means ESP32), then fetching the time will give approximate closer value of event, such as button press. In real life, button press and fetching the time will have few seconds to few minutes time difference. But that is closest to the actual event for projects such as sending email or SMS after an event.

Advertisement

---

NTP stands for Network Time Protocol, a standard Internet Protocol (IP) for synchronizing the computer/server to some reference over a network. So the protocol can be used to synchronize all the networked devices to Coordinated Universal Time (UTC) within 50 milliseconds over the public Internet.

There are libaries for Arduino to have NTP client in easy way :

Vim

1

https://github.com/taranais/NTPClient/

I beleive that this repository (and code) is far more useful for ESP32 :