Tags:
create new tag
view all tags

Solutions to Exercise 9: Real Time Clock and Data Logging

Exercise 1:

Since connecting to the Internet through WiFi is a very common task, we develop a module doing only this. The module can be put into the /lib directory on the ESP32 (or even better: frozen into the binary of MicroPython) making it available also for later exercises.

Here is a program connecting to the Internet through WiFi. You will have to modify it in order to adapt it to your WiFi SSID and password.

https://iotworkshop.africa/pub/IoT_Course_English/SolutionsToRealTimeClockAndDataLogging/wifi_connect_UCC.py.txt

... and this is how to access it and what it will print as answers:

wifi_connect_print.png

Exercise 2:

Sometimes you may not have access to WiFi but you want to set the time nevertheless. Then the solution to exercise 2 comes in handy:

https://iotworkshop.africa/pub/IoT_Course_English/SolutionsToRealTimeClockAndDataLogging/esp32RTC.py.txt

The exercise sheet already shows how to use the program

Exercise 5: Write "Hello World!" file to the SD card

In the solution I mount the SD card (skipping the OSError EPERM emitted if the card is already mounted). I then check with uos.stat if the data directory already exists and I create it if not. Then I open the hello.txt file for writing and I write "Hello World!" onto the file. I finish writing by closing the file.

In order to be sure everything went ok I re-open the file, this time for reading. I read the content and print it before closing the file again.

sdcardHello.png

I can the connect to the Internet through WiFi and start the ftp server. This allows me to transfer the hello.txt file to the PC and print it there.

uftpd.png

ftpHello.png

Here is the script:

https://iotworkshop.africa/pub/IoT_Course_English/SolutionsToRealTimeClockAndDataLogging/mountSD.py.txt

Exercise 6: Data acquisition and logging with time stamp

This exercise is quite similar to the previous one with the exception that we write real data now. You have already seen how to read out the SHT30 using the SHT3X driver and you can easily get at the time stamp with now = time.time() if you have set up the correct time with ntptime before.

In this case I open the file for writing in append mode and I close it again after having written a new data sample.

sht30Readout.png

I recuperate the data through ftp on the PC side:

ftpSHT30Data.png

Finally I convert the time to a humanly readable form and I compare it to the time seen in MicroPython:

cpythonTime.png

And here is the script:

https://iotworkshop.africa/pub/IoT_Course_English/SolutionsToRealTimeClockAndDataLogging/sht30Readout.py.txt

-- Uli Raich - 2020-05-06

Comments

Topic attachments
I Attachment History Action Size Date Who Comment
PNGpng cpythonTime.png r2 r1 manage 30.1 K 2020-05-27 - 10:23 UliRaich  
Texttxt dayOfWeek.py.txt r1 manage 1.7 K 2020-05-25 - 10:29 UliRaich  
Texttxt esp32RTC.py.txt r2 r1 manage 4.5 K 2020-05-25 - 10:29 UliRaich  
PNGpng ftp.png r1 manage 73.6 K 2020-05-27 - 09:46 UliRaich  
PNGpng ftpHello.png r1 manage 80.1 K 2020-05-27 - 09:56 UliRaich  
PNGpng ftpSHT30Data.png r1 manage 136.3 K 2020-05-27 - 10:19 UliRaich  
PNGpng micropythonTime.png r1 manage 6.9 K 2020-05-27 - 09:46 UliRaich  
Texttxt mountSD.py.txt r1 manage 1.6 K 2020-05-27 - 09:44 UliRaich  
PNGpng sdcardHello.png r1 manage 18.6 K 2020-05-27 - 09:59 UliRaich  
PNGpng sht30Readout.png r1 manage 109.4 K 2020-05-27 - 10:19 UliRaich  
Texttxt sht30Readout.py.txt r1 manage 2.7 K 2020-05-27 - 09:44 UliRaich  
PNGpng uftpd.png r1 manage 6.1 K 2020-05-27 - 09:56 UliRaich  
Texttxt wifi_connect_UCC.py.txt r1 manage 2.0 K 2020-05-25 - 10:29 UliRaich  
PNGpng wifi_connect_print.png r2 r1 manage 42.2 K 2020-05-25 - 11:33 UliRaich  
Edit | Attach | Watch | Print version | History: r3 < r2 < r1 | Backlinks | Raw View | Raw edit | More topic actions
Topic revision: r3 - 2020-05-27 - UliRaich
 
This site is powered by the TWiki collaboration platform Powered by PerlCopyright © 2008-2024 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding TWiki? Send feedback