ropg / ezTime

ezTime — pronounced "Easy Time" — is a very easy to use Arduino time and date library that provides NTP network time lookups, extensive timezone support, formatted time and date strings, user events, millisecond precision and more.
MIT License
327 stars 92 forks source link

ezTime for ESP32 Wired Ethernet on Olimex ESP32-POE-ISO Working #167

Open jaseiffert opened 1 year ago

jaseiffert commented 1 year ago

I modified the Preprocessor code to add the libraries it needed for Wired Ethernet. This is for the ETH.h in the arduino-esp32 core.

First of all let me just say I know enough to be dangerous. I'm past beginner just a little with C++ coding with the Arduino Libraries.

I only modified the ezTime.h and ezTime.cpp and those are the only files in the attached zip file.

You can compare these to the original ones and see what I changed. If you are using VS Code and PlatformIO you can just replace the files in the libdeps folder for ezTime if installed or load it and then make the changes.

If you have your code setup like this example, ETH_LAN8720 from arduino-esp32 Ethernet examples then all you need to do is add

include

define NTP_POLLING 3600 // NTP polling interval in seconds (3600 = 1 hour)

// For ezTime before setup() Timezone myTZ; // or your way of doing this.

In the Event for ARDUINO_EVENT_ETH_GOT_IP I put this at the end of what was already there.

    // Wait for ezTime to get its time synchronized
    Serial.println("Waiting for time sync...");
    //setDebug(INFO);
    if(!waitForSync(30)){
        Serial.println("Time out getting time from NTP Server.");
    }

    // Provide official timezone names
    // https://en.wikipedia.org/wiki/List_of_tz_database_time_zones
    myTZ.setLocation(("America/Chicago"));
    Serial.print(F("Date Time:     "));
    Serial.println(myTZ.dateTime());

    // Set NTP polling interval to 6 hours.
    setInterval(NTP_POLLING);

This is what my serial output looks like though I took a few things out that were not needed.

Ethernet MAC: FF:FF:EE:EE:DD:DD IPv4: 192.168.15.103 Gateway: 192.168.15.1 DNS: 192.168.15.1 , FULL_DUPLEX, 100Mbps Waiting for time sync... IPv4: 192.168.15.103 Temp F = 81.81 Hum. % = 34.84 Date Time: Wednesday, 19-Apr-2023 13:32:46 CDT Temp F = 81.84 Hum. % = 35.45

I can't provide support for this so use at your own risk.

Thanks,

Jeffery ezTime.zip