Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Beta 3.0.2 version fails with ESP32 #105

Closed
bill-orange opened this issue Oct 4, 2019 · 8 comments
Closed

Beta 3.0.2 version fails with ESP32 #105

bill-orange opened this issue Oct 4, 2019 · 8 comments
Labels

Comments

@bill-orange
Copy link

bill-orange commented Oct 4, 2019

I just tested the latest beta on a Wemos ESP32 (probably counterfeit). I get a kernal panic at NTP.begin().

Here's the dump.

Decoding 13 results
0x400d3955: IPAddress::operator==(unsigned char const*) const at C:\Users\William\AppData\Local\Arduino15\packages\esp32\hardware\esp32\1.0.2\cores\esp32/IPAddress.cpp line 51
0x400d2522: NTPClient::getTime() at C:\Users\William\Documents\Arduino\libraries\NtpClientLib\src/NTPClientLib.cpp line 289
0x400d2612: NTPClient::s_getTime() at C:\Users\William\Documents\Arduino\libraries\NtpClientLib\src/NTPClientLib.cpp line 447
0x400d1ca8: now() at C:\Users\William\Documents\Arduino\libraries\Time-master/Time.cpp line 303
0x400d1d55: setSyncProvider(long ()()) at C:\Users\William\Documents\Arduino\libraries\Time-master/Time.cpp line 315
0x400d22c6: NTPClient::begin(String, signed char, bool, signed char, AsyncUDP
) at C:\Users\William\Documents\Arduino\libraries\NtpClientLib\src/NTPClientLib.cpp line 709
0x400d18dd: setup() at C:\Users\William\AppData\Local\Temp\arduino_modified_sketch_446980/NTPClientBasic.ino line 81
0x400d4553: loopTask(void*) at C:\Users\William\AppData\Local\Arduino15\packages\esp32\hardware\esp32\1.0.2\cores\esp32/main.cpp line 14
0x400887b5: vPortTaskWrapper at /Users/ficeto/Desktop/ESP32/ESP32/esp-idf-public/components/freertos/port.c line 355 (discriminator 1)

Here's the test code.

#include <TimeLib.h> //TimeLib library is needed https://github.com/PaulStoffregen/Time
#include <NtpClientLib.h> //Include NtpClient library header
//#include <ESP8266WiFi.h> // ESP8266
#include <WiFi.h> // ESP32

#define YOUR_WIFI_SSID "redacted"
#define YOUR_WIFI_PASSWD "redacted"

int counter = 25;

void setup () {
	Serial.begin (115200);
	Serial.println ();

	//Start WiFi communication
	WiFi.mode (WIFI_STA);
	WiFi.begin (YOUR_WIFI_SSID, YOUR_WIFI_PASSWD);
  while (WiFi.status() != WL_CONNECTED && counter > 0) {
    delay(500);
    counter --;
    Serial.print(".");
  }
  if (counter > 0) {
    Serial.println("");
    Serial.println("WiFi connected");
    Serial.println("");
    Serial.print("Connected to ");
    Serial.println(YOUR_WIFI_SSID);
    Serial.print("IP address: ");
    Serial.println(WiFi.localIP());
    //printWifiStatus(); // print WiFi Info to Screen
    delay(5000);       // need time to read
  }
  else {
    Serial.println("NO WiFi");
    delay(3000);       // need time to read
  }
  Serial.print("IP Address: "); Serial.println(WiFi.localIP());
	// NTP begin with default parameters:
	//   NTP server: pool.ntp.org
	//   TimeZone: UTC
	//   Daylight saving: off
	
	// Start realtime
  Serial.println("test point_1");
  NTP.begin();
  Serial.println("test point_2");
  NTP.setInterval(63);
  while ((year(now()) < 1980) || (year(now()) > 2035)) {
    int i = 0;
    delay (500);
    Serial.print("+");
    i++;
    NTP.setTimeZone (-7);
    NTP.setInterval(63);
    if (i > 20) {
      Serial.println(); Serial.print("..................... no NTP time!");
    }
  }

  Serial.println();
  Serial.println(NTP.getTimeDateString());


}

void loop () {
	//To keep time updated you need to call now() from time to time inside loop
	//in this case getTimeDateString() implies a call to now()
	Serial.println (NTP.getTimeDateString ()); 
	
	delay (1000);
}

Thanks for all the hard work on this stuff.

@gmag11
Copy link
Owner

gmag11 commented Oct 7, 2019

Thank you @bill-orange . I'll try to reproduce it.

@gmag11 gmag11 added the bug label Oct 7, 2019
@bill-orange
Copy link
Author

bill-orange commented Oct 7, 2019

@gmag11 Thanks.

Something else to consider is an enhancement to provide Excel time as well as Unix time. The call would be something like: Serial.println( NTP.getExcelTimeDateString() ). With this function an Excel file could be saved to SPIFFS with the time in Excel format. As I found on another site, the conversion is:

String excelTime = String(now() / 86400 + 25569) + "." + String(long(float(now ()% 86400) * 100000/86400 + 0.5));
The function would be pretty simple, something like:

String getExcelTimeDateString() {
return ( String(now() / 86400 + 25569) + "." + String(long(float(now ()% 86400) * 100000/86400 + 0.5)) );
}

I don't know if there is a big demand for this, but it is something to consider.

@Clickau
Copy link

Clickau commented Oct 17, 2019

It happens to me as well, and I think I identified the cause. On line 291 of NTPClientLib.cpp, you check if the IPAddress is 0. On the esp8266, the == operand takes in the uint32_t address that you compare against, so it's fine. But on the esp32, the == operand takes in const uint8_t* addr, a pointer to the address. So when you pass 0 as the argument, it tries to access the memory at address 0, and fails.

@bill-orange
Copy link
Author

@Clickau Line 289 in my 3.02 version, but, yes, that is probably it.

@jmysu
Copy link

jmysu commented Oct 28, 2019

I managed it by replacing "(uint32_t)(0)" with "INADDR_NONE"!
Line 291 in my 3.02 version!

//if (ntpServerIPAddress == (uint32_t)(0)) {
if (ntpServerIPAddress == INADDR_NONE) {

@bill-orange
Copy link
Author

bill-orange commented Oct 29, 2019

@gmag11 The fix proposed by @jmysu works for me too. I did not test it on an ESP8266.

@davidr99
Copy link

I have also fixed it by changing that line to:

if (((uint32_t)ntpServerIPAddress) == (uint32_t)(0)) {

@gmag11
Copy link
Owner

gmag11 commented Nov 17, 2020

Fixed on 1d81889

@gmag11 gmag11 closed this as completed Nov 17, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

5 participants