PaulStoffregen / Time

Time library for Arduino
http://playground.arduino.cc/code/time
1.24k stars 665 forks source link

TimeLib do not work with fixe IP address #126

Open azimut2000 opened 5 years ago

azimut2000 commented 5 years ago

Hello,

I have a problem with TimeLib : when i use fixe IP address, i can't access to good time. Here is en exemple that work on ESP8266 and ESP32 : it do the same bug, i allways stay in 1970 when i use fixe IP address.

What do you think of this ? Does someone have found a solution to work fine ?

Thank's for your ideas and answer.

Thierry

Hardware & Software

Board : ESP8266 & ESP32 (Arduino : ???) Arduino IDE version : last version Version info & package name (from Tools > Boards > Board Manager) : 2.5 on ESP8266

Arduino Sketch


#include <ESP8266WiFi.h>            // if ESP8266 plateform
//#include <WiFi.h>                     // if ESP32 plateform
#include <TimeLib.h>      
#include <NtpClientLib.h> 

const char* ssid = "xxxxxxxxxx;                 // SSID
const char* password = "xxxxxxxxxxxxxxxxxx";    // Password

IPAddress MyIP(192,168,1,90);     
IPAddress subnet(255, 255, 0, 0); 
IPAddress gateway(192, 168, 1, 1);
IPAddress myDNS(8, 8, 8, 8);    

void setup() {
  Serial.begin(115200);
  delay(100);
  WiFi.begin(ssid, password);

  // We wait to be connected
  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(".");
  }

  WiFi.config(MyIP, gateway, subnet, myDNS);

  NTP.begin ();
  Serial.println("Nous sommes le " + String(day()) + " " + String(month()) + " " + String(year()));
}
void loop() {
}

Errors or Incorrect Output

When i fixe IP address, i stay in 1970 !!! but OK with DHCP address