logo elektroda
logo elektroda
X
logo elektroda

How to run the internal RTC on the ESP32 without internet access?

Przybyłek 2907 9
ADVERTISEMENT
Treść została przetłumaczona polish » english Zobacz oryginalną wersję tematu
  • #1 17954400
    Przybyłek
    Level 13  
    I built a 4-temperature logger which creates a CSV file on an internal partition in flash for downloading via the web, the chip works in AP mode and has a small configuration via the web. It is also possible to view the graph via www and google script, I also made graphs via Ajax. Unfortunately the graph only works on the phone because the script loads from the internet, which is about 100KB. When I upload it to the internal memory and read it
    Code: C / C++
    Log in, to see the code
    .
    Unfortunately I achieve about 2KB/s. Which makes the file take a minute to download. Maybe someone has some other idea?

    Let's move on to the 100th issue.
    I need to use an internal RTC for which I found no description in the arduino. I know it is not very accurate. I have a 32.768kHz quartz connected.
    I don't have internet access, the time will be set via the web. It will be added to a CSV file to show indicatively when the measurement was.

    I am writing in Arduino, ESP-IDE I have seen some elaborate example.
    [/code].
    Do you have a problem with Arduino? Ask question. Visit our forum Arduino.
  • ADVERTISEMENT
  • #2 17955234
    khoam
    Level 42  
    Przybyłek wrote:
    I need to use an internal RTC
    .
    Wouldn't the system functions settimeofday() and gettimeofday() from the newlib library (header file <sys/time.h> ) suffice in this case? You have to set the internal RTC every time you reboot the ESP32 if you are not using NTP or an external RTC with battery backup.
  • ADVERTISEMENT
  • #3 17955454
    Przybyłek
    Level 13  
    But this library is standard in the arduino libraries for esp32? This is what I'm referring to.
  • #4 17955552
    khoam
    Level 42  
    Przybyłek wrote:
    But this library is standard in the arduino libraries for esp32? That's what I mean.
    .
    The Arduino HAL library in ESP32 is entirely based on ESP-IDF , which uses, among other things, the system library newlib . In post #2 I gave you functions for writing/reading the internal RTC on the ESP32 such that are the easiest to use in my opinion.

    Functions for setting the time in the Arduino HAL for ESP32 require the availability of the NTP protocol, i.e. internet access.

    In summary, programming with Arduino HAL on ESP32 also means programming with ESP-IDF.
  • #5 17957658
    Przybyłek
    Level 13  
    Thanks a lot I saw something about this, but now with this IDF you have brightened me up, the RTC clock works. And could you advise something else with file uploads?
  • ADVERTISEMENT
  • #6 17957723
    khoam
    Level 42  
    Are you referring to reading and writing to SPIFFS? From what I see in post #1 you are using the SPIFFSFS class from Arduino HAL. It's easy to use and nothing more :) If you want to operate faster on SPIFFS then unfortunately you have to go to the "low level" functions from IDF ( Link ) and then you can use the standard in C File I/O functions (fgets, fputs). It will be much faster.
  • ADVERTISEMENT
  • #7 17958518
    Przybyłek
    Level 13  
    Hmm, but will it do that much? I thought the problem was more on the client.write side and sending a single character.
  • #8 17958534
    khoam
    Level 42  
    Przybyłek wrote:
    Hmm, but will it do that much? I thought the problem was more on the client.write side and sending a single character.
    .
    Without posting a larger snippet of the code that is causing the problems, it is difficult to advise anything.
  • #9 17962530
    Przybyłek
    Level 13  
    But after all, that's all the code in the first post. While checks if the file has finished, file.read read reads a character from the file and increments a pointer to the file and write writes a pointer to the client connected via http on clnt. This while with a 100KB file takes 50s.
  • #10 17962705
    khoam
    Level 42  
    What type/class is the variable file ?
    What type/class does the variable clnt point to?
    How are both variables initialised?

Topic summary

The discussion revolves around implementing an internal Real-Time Clock (RTC) on the ESP32 without internet access. The user has developed a temperature logger that saves data in CSV format but faces challenges with slow file downloads and the need for accurate timekeeping. Responses suggest using the settimeofday() and gettimeofday() functions from the newlib library for RTC management, noting that the internal RTC must be set after each reboot if NTP is unavailable. The conversation also touches on file handling, recommending the use of low-level functions from the ESP-IDF for faster SPIFFS operations, as the current method is inefficient. The user expresses gratitude for the insights and seeks further advice on file uploads.
Summary generated by the language model.
ADVERTISEMENT