Line: 1 to 1 | ||||||||
---|---|---|---|---|---|---|---|---|
Exercise 9: RTC and data loggingIntroduction | ||||||||
Line: 6 to 6 | ||||||||
The ESP32 has a real time clock implemented on chip. This will however only work as long as the ESP32 is powered. It may therefore be interesting to employ and external RTC like the DS1307, backed up with a battery, to keep time even when the ESP32 is powered off or in deep sleep mode. Getting the current (GMT) time from the internet is easy when using the ntptime module. We can make use of this to setup our RTC with the correct time. | ||||||||
Changed: | ||||||||
< < | Exercise 1: Set the ESP32 RTC | |||||||
> > | Exercise 1: Set the ESP32 to the current time read from the Internet | |||||||
Changed: | ||||||||
< < | Ask the user for the current date and time and set the real time clock in the ESP32 correspondingly. Read back the time a little later and print it out. Use a parser similar to the one we wrote in session 1, exercise 2, for the calculator to check the user input. | |||||||
> > | The module ntptime allows you to get the current UTC time from the NTP server. It's function settime() sets the time of the ESP32 real time clock. Write a module that connects to the Internet through Wifi and that sets up the ESP32 with the current UTC time
Check with the ESP32 RTC module that the time was correctly set.
Exercise 2: Set the ESP32 RTC manuallyIf you to not have Internet access you can still set up the ESP32 RTC manually. | |||||||
Changed: | ||||||||
< < | The driver for the ESP32 RTC is described in https://docs.micropython.org/en/latest/esp32/quickref.html#real-time-clock-rtc. | |||||||
> > | Ask the user for the current date and time and set the real time clock in the ESP32 correspondingly. Read back the time a little later and print it out. Use a parser similar to the one we wrote in session 1, exercise 2, for the calculator to check the user input. | |||||||
Changed: | ||||||||
< < | Be careful about the parameters passed into rtc.datetime. These are yyyy mm dd ww hh mm ss us where | |||||||
> > | Be careful about the parameters passed into rtc.datetime((currentTime)). currentTime is a Python tuple with the following members: yyyy mm dd ww hh mm ss us where | |||||||
| ||||||||
Line: 33 to 38 | ||||||||
Here is a screen dumps showing a session controlling the ESP32 RTC: | ||||||||
Changed: | ||||||||
< < | Exercise 2: Set the DS1307 RTC | |||||||
> > | Exercise 3: Set the DS1307 RTC | |||||||
Changed: | ||||||||
< < | Do the same thing with the DS1307 RTC
Exercise 3: Get the time from the Internet and setup the RTC | |||||||
> > | The disadvantage of getting the current time from the ESP32 RTC is that time is lost when the ESP32 is powered off. The DS1307 RTC however is batttery backed and time is kept even when the rest of the system is shut down. | |||||||
Changed: | ||||||||
< < | Write a function that connects your ESP32 to the Internet through WiFi. Use the station interface to do so. Find out the IP address the ESP32 can be reached at. Setup system time and print it. | |||||||
> > | Do the same thing with the DS1307 RTC | |||||||
-- Uli Raich - 2020-05-06 |