Open dorkmatt opened 4 years ago
Note that using WiFi on the same board, same SDK/IDE, same 0.8.2 library version (stock ezTime.h defines) works fine (both local and remote NTP pool time sources).
Sample WiFi sketch
#include <ETH.h> // ESP32 ethernet
#include <WiFi.h>
#include <ezTime.h> // https://github.com/ropg/ezTime
/* Local variables */
static bool USE_WIFI = true;
const char* ssid = "mynetworkname";
const char* pass = "mysecretpass";
String LOCAL_NTP_SERVER = "100.64.42.1";
void setup()
{
if (USE_WIFI) {
WiFi.begin(ssid, pass);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
} else if (!USE_WIFI) {
WiFi.onEvent(WiFiEvent);
ETH.begin();
WiFi.mode(WIFI_OFF);
btStop();
}
// setServer(LOCAL_NTP_SERVER);
setDebug(INFO);
waitForSync(25);
}
void loop()
{
events();
if (WiFi.status() == WL_CONNECTED) {
Serial.println("Network online");
testClient("checkip.dyndns.org", 80);
Serial.print("NTP date: ");
Serial.println(UTC.dateTime());
}
delay(10000);
}
WiFi serial messages:
14:27:07.444 -> ESP date: Thursday, 01-Jan-1970 00:00:00 UTC
14:27:07.577 -> [D][WiFiGeneric.cpp:337] _eventCallback(): Event: 0 - WIFI_READY
14:27:07.577 -> [D][WiFiGeneric.cpp:337] _eventCallback(): Event: 2 - STA_START
14:27:07.743 -> [D][WiFiGeneric.cpp:337] _eventCallback(): Event: 4 - STA_CONNECTED
14:27:07.743 -> [D][WiFiGeneric.cpp:337] _eventCallback(): Event: 7 - STA_GOT_IP
14:27:07.743 -> [D][WiFiGeneric.cpp:381] _eventCallback(): STA IP: 100.64.41.31, MASK: 255.255.255.0, GW: 100.64.41.1
14:27:08.075 -> .
14:27:08.075 -> ezTime debug level set to INFO
14:27:08.075 -> Waiting for time sync
14:27:08.307 -> Querying pool.ntp.org ... success (round trip 319 ms)
14:27:08.639 -> Received time: Sunday, 01-Dec-19 22:27:08.732 UTC
14:27:08.639 -> Time is in sync
14:27:08.639 -> Network online
14:27:08.639 ->
14:27:08.639 -> connecting to checkip.dyndns.org
14:27:11.624 -> HTTP/1.1 200 OK
14:27:11.624 -> Content-Type: text/html
14:27:11.624 -> Server: DynDNS-CheckIP/1.2.0
14:27:11.624 -> Connection: close
14:27:11.624 -> Cache-Control: no-cache
14:27:11.624 -> Pragma: no-cache
14:27:11.624 -> Content-Length: 107
14:27:11.624 ->
14:27:11.624 -> <html><head><title>Current IP Check</title></head><body>Current IP Address: 135.x.x.x</body></html>
14:27:11.658 -> closing connection
Compiling w/o EZTIME_ETHERNET
results in the "No network" error.
Compiling w/ EZTIME_ETHERNET
defined, it looks like the initial NTP query begins prior the network being ready (before DHCP lease is issued) and then blocks (never execs loop function).
Compiling w/o EZTIME_ETHERNET
defined and commenting out EZTIME_ETHERNET
conditional under queryNTP seems to make it work with the wired ethernet port. My guess this is due to a slight fluke that WiFi.status() == WL_CONNECTED
when using the wired port.
hello i can't get the library to work with ethernet with an esp8266 with 3.0.0 core. how did you fix that? thanks
HI folks. I.ve been having these issues trying to get a LAN8720 working with my eztime.h enabled sketch. I've tried variations on the above suggestions and was wondering if anyone has any further advice. I've not managed to get eztime to successfully query the pool.ntp.org and return the UTC time. It seems to hung up at that point and never goes beyond.
Using wESP32 (wired ethernet port) with 1.8.10 Arduino IDE and ESP32 SDK 3.2.3, the ethernet portion seems to fail. This may be related to #56 or #52, as DNS never seems to get resolved (though my example shows DNS working correctly for an HTTP connection).
I believe this is due to the use of Ethernet.h library, while these boards use the ESP32 specific Eth.h. I've tried both with and without EZTIME_ETHERNET defined. Also tried both with and without a custom NTP server defined. My guess is the Ethernet.h library is still needed for the UDP packet crafting, but not necessarily for the link state detection?
Sample sketch:
Resulting serial messages: