Problema connessione ESP8266

Ciao a tutti, ho rilevato un prb durante la connessione wifi della scheda ESP8266:
Se configuro SSID e Pass funziona tutto compresa la ricezione dell'orario dal server ntp ("pool.ntp.org")

Se configuro anche, in modo statico, staticIP ,gateway e subnet non mi riceve più l'orario dal server.

Avete idea del perchè?
questo è il codice che stò provando:

#include <SPI.h>
#include <ESP8266WiFi.h>
#include <WiFiClient.h>
#include <ESP8266WebServer.h>
#include <ESP8266mDNS.h>

#define STASSID "NETGEAR"
#define STAPSK  "nichiren"

const char* ssid = STASSID;
const char* password = STAPSK;

String HeaderPage = "<!DOCTYPE html><html><head><meta http-equiv='refresh' content='60'><style> header { background: linear-gradient(to right, #1e5799 0%,#7db9e8 100%); color: #fff; padding:10px; text-align: center; vertical-align: middle; } body{ padding:15px; color: #5e5e5e; font-family: Helvetica,Arial,sans-serif; font-variant: small-caps; font-size:1em; text-align: center; } footer { background: linear-gradient(to left, #1e5799 0%,#7db9e8 100%); color: #fff; padding:10px; text-align: right; vertical-align: bottom; } h2 {  padding:10px; text-align: center; vertical-align: middle; font-size:2em; } </style></head><body><header>:: LOLIN WeMos D1 mini Pro ::</header>";
String FooterPage = "<footer>powerd by gfsoftware.net
CC licence</footer></body></html>";
String rootPageBody1 = "<h2>";
String rootPageBody2 = "";
String rootPageBody3 = "</h2>";
String rootWebPage;

ESP8266WebServer server(80);

int timezone = 2;
int dst = 0;
unsigned long previousMillis = 0;  // will store last time LED was updated
const long interval = 1000;  // interval at which to blink (milliseconds)

//const int chipSelect = D8;

//IPAddress 
IPAddress staticIP(192,168,1,100);
IPAddress gateway(192,168,1,1);
IPAddress subnet(255,255,255,0);
//IPAddress dns;



int contaled = 0;

void composeWebPage() {
  time_t now = time(nullptr);
  rootPageBody2 = ctime(&now);
  rootWebPage = HeaderPage;
  rootWebPage += rootPageBody1;
  rootWebPage += rootPageBody2;
  rootWebPage += rootPageBody3;
  rootWebPage += FooterPage;
}

void handleRoot() {
  digitalWrite(LED_BUILTIN, LOW);
  composeWebPage();
  server.send(200, "text/html", rootWebPage);
  digitalWrite(LED_BUILTIN, HIGH);
}

void handleNotFound(){
  digitalWrite(LED_BUILTIN, LOW);
  String message = "File Not Found";
  message += "URI: ";
  message += server.uri();
  message += "nMethod: ";
  message += (server.method() == HTTP_GET)?"GET":"POST";
  message += "nArguments: ";
  message += server.args();
  message += "n";
  for (uint8_t i=0; i<server.args(); i++){
    message += " " + server.argName(i) + ": " + server.arg(i) + "n";
  }
  server.send(404, "text/plain", message);
  digitalWrite(LED_BUILTIN, HIGH);
}


void setup(void){
  pinMode(LED_BUILTIN, OUTPUT);
  digitalWrite(LED_BUILTIN, HIGH);
  Serial.begin(115200);
  Serial.println();
  Serial.println("Avvio configurazione del WiFi...");
  WiFi.hostname("Fontana 1.0");
  Serial.println("Fontana 1.0");
  
  //WiFi.config(staticIP, subnet, gateway); //
  
  WiFi.begin(ssid, password);
  Serial.println(ssid);
  Serial.println(password);

  // Wait for connection
  Serial.print("Wait for wifi connection");
  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(".");
  }
  Serial.println("");
  Serial.print("Connected to ");
  Serial.println(ssid);
  Serial.print("IP address: ");
  Serial.println(WiFi.localIP());
  Serial.print("Gateway address: ");
  Serial.println(WiFi.gatewayIP());
  
  if (MDNS.begin("esp8266")) {
    Serial.println("MDNS responder started");
  }
  

  server.on("/", handleRoot);



  server.on("/inline", [](){
    server.send(200, "text/plain", "this works as well");
  });

  server.onNotFound(handleNotFound);

  server.begin();
  Serial.println("HTTP server started");
  configTime(timezone* 3600, dst * 0, "pool.ntp.org", "time.nist.gov");
  Serial.println("\nWaiting for time");
  while (!time(nullptr)) {
    Serial.print(".");
    delay(1000);
  }
}

void loop(void){
  
  if (contaled < 10){
    digitalWrite(LED_BUILTIN, LOW);
    contaled ++;
  }else{
    digitalWrite(LED_BUILTIN, HIGH);
  }

  
  Serial.println();
  server.handleClient();
  digitalWrite(LED_BUILTIN, HIGH);
  unsigned long currentMillis = millis();
  //if (currentMillis - previousMillis > interval) {
    //previousMillis = currentMillis; //save the last time you blinked the LED
    time_t now = time(nullptr);
    Serial.println(ctime(&now));

    delay(1000);
  //}
}

All'inizio del SetUp c'è una riga commentata che dovrebbe impostare la configurazione statica della connessione wifi.
Ho provato anche ad inserire solo lo staticIP ma non funziona...
Help!! Grazie

Ciao,
prova a mettere anche questa riga:

....
WiFi.mode(WIFI_STA);
WiFi.config(staticIP, gateway, subnet);
...

Alan

non è cambiato niente, se uso la riga
WiFi.config(staticIP, gateway, subnet);
non mi dà l'ora corrente ma un orario tipo 1 genn 1970

Prova magari ad aggiungere anche il DNS

Alan

Per ora ho risolto con il DHCP Statico sul router