ThEngi, scusami ma non avevo visto il tuo disegno, oltretutto ci hai messo pure impegno. Si grazie è proprio quello che succede, ho provato diversi sketch anche con amici ma ho sempre nell'arco della giornata al 70 % minimo meno 1 secondo. Provato anche con istruzione per fare più interrrogazioni al server ma niente. E' la connessione che non è corretta, Testato oltre con wifi di rete anche con router con sim uguale sempre meno 1. Ecco lo sckect e schema, un capolavoro di disegno,

. Ovvio mancano le alimentazioni tutto a 5 vcc e wemos da alimentatore esterno 9 Vcc. provato come già detto anche così : timeClient.setTimeOffset(7200);
// AGGIONAMENTO ORA ========================================
// Setta intervallo di aggiornamento ntp a 5 min
// timeClient.setUpdateInterval(300000);
// Setta intervallo di aggiornamento ntp a 1 min
// ============
//timeClient.setUpdateInterval(60000); //
A questo punto, ecco aiuto, o come risolvere problema, magari a risolvere, oppure come e dove aggiungere ad esempio demtro una variabile: +0.5 o + 1 secondo; tenendo conto che la maggior parte delle giornata sta a meno 1. Grazie
======================inizio sketch
- Codice: Seleziona tutto
#include <LibSerial.h> // Libreria seriale
#include <ESP8266WiFi.h> // per famiglia esp8266
#include <NTPClient.h> // Libreria NTPCLIENT
#include <WiFiUdp.h> // Libreria WiFiUdp
#include <LiquidCrystal_I2C.h> // Libreria I2C LCD
LibSerial MySerial;
#define Pin_Blink 2 // pin 4 di wemos
#define LED_SOLAR 1 // -----> LED SOLAR
// Impostazione diritti di accesso
const char* ssid = "xxx";
const char* password = "yyy";
LiquidCrystal_I2C lcd(0x27, 20, 4);
WiFiUDP ntpUDP;
// NTPClient timeClient(ntpUDP, "pool.ntp.org");
//NTPClient timeClient(ntpUDP, "time.inrim.it");
NTPClient timeClient(ntpUDP, "time.inrim.it"); // 0.it.pool.ntp.org time.inrim.it
String formattedDate; // Data + tempo
String dayStamp;
String timeStamp;
String formattedTime; // solo tempo
//Week Days
String weekDays[7]={"Dom", "Lun", "Mar", "Mer", "Gio", "Ven", "Sab"};
//Month names
String months[12]={"Gen", "Feb", "Mar", "Apr", "Mag", "Giu", "Lug", "Ago", "Set", "Ott", "Nov", "Dic"};
// ----------------------------------------------------------------------------------------------------------------------------------------------
// EXIT_ERROR
// ----------------------------------------------------------------------------------------------------------------------------------------------
String Exit_Error(byte Codice_Errore)
{
switch (Codice_Errore)
{
case 0: return "IDLE_STATUS" ;
case 1: return "NO_SSID_AVAILABLE";
case 2: return "SCAN_COMPLETED";
case 3: return "CONNECTED";
case 4: return "CONNECT_FAILED";
case 5: return "CONNECTION_LOST";
case 6: return "DISCONNECTED";
default: return "CODE UNKNOWN";
}
}
// ----------------------------------------------------------------------------------------------------------------------------------------------
// LOOP
// ----------------------------------------------------------------------------------------------------------------------------------------------
void loop()
{
while(!timeClient.update())
timeClient.forceUpdate();
time_t epochTime = timeClient.getEpochTime(); //
formattedTime = timeClient.getFormattedTime();
formattedDate = timeClient.getFormattedDate();
int splitT = formattedDate.indexOf("T");
dayStamp = formattedDate.substring(0, splitT);
MySerial.Write_Message(formattedTime,false,true);
MySerial.Write_Message(formattedDate,false,true);
MySerial.Write_Message(dayStamp,false,true);
//---------------------------------------------------------
// UPG per Week e MM in chiaro
String weekDay = weekDays[timeClient.getDay()];
MySerial.Write_Message("Week Day: ",false,false);
MySerial.Write_Message(weekDay,false,true);
//Get a time structure per ricostruire la data
struct tm *ptm = gmtime ((time_t *)&epochTime);
int monthDay = ptm->tm_mday; // Giorno
int currentMonth = ptm->tm_mon+1; // Mese
String currentMonthName = months[currentMonth-1];
int Anno = ptm->tm_year+1900; // Anno
MySerial.Write_Other("Month day: ",monthDay,false,false,true);
MySerial.Write_Other("Month: ",currentMonth,false,false,true);
MySerial.Write_Message("Month name: ",false,false);
MySerial.Write_Message(currentMonthName,false,true);
lcd.setCursor(3,0); // CURSORE DATA
lcd.print(weekDay);
lcd.print(" ");
lcd.print(monthDay);
lcd.print(" ");
lcd.print(currentMonthName);
lcd.print(" ");
lcd.print(Anno);
//--------------------------------------------------------------
//timeStamp = formattedDate.substring(splitT+1, formattedDate.length()-1);
lcd.setCursor(6,2); // cursor a c3/r1
lcd.print(formattedTime); // Orario
//delay(1000); // non dovrebbe essere
}
// ----------------------------------------------------------------------------------------------------------------------------------------------
// SETUP
// ----------------------------------------------------------------------------------------------------------------------------------------------
void setup()
{
unsigned long ST_TM_OUT= millis() / 1000; // Setting time start
unsigned long END_TM_OUT = 0x00L;
unsigned long Time_Out = 20;
int Cod_Err; // errore status
int Cod_TM; // Time_out
String MesError;
pinMode(Pin_Blink,OUTPUT);
digitalWrite(Pin_Blink,HIGH);
pinMode (LED_SOLAR,INPUT_PULLUP);
MySerial.Start_Serial(115200,"NTP CLOCK START",true);
lcd.init();
lcd.backlight();
lcd.setCursor(4,0);
lcd.print("Cucciolo: WAIT");
MySerial.Write_Message("Connecting to --> ",true,false);
// String SID = ssid;
// MySerial.Write_Message(SID,false,true);
MySerial.Write_Message(ssid,false,true);
MySerial.Write_Message("Blink durante la connessione",false,true);
WiFi.begin(ssid, password); // Wait for connection
while (WiFi.status() != WL_CONNECTED)
{
digitalWrite(Pin_Blink,HIGH); // Blink for wait
delay(500); // time 500 ms
digitalWrite(Pin_Blink,LOW);
delay(500);
END_TM_OUT = (millis() /1000) - ST_TM_OUT;
// Si connette entro Time_Out ??
if (END_TM_OUT > Time_Out)
{
digitalWrite(Pin_Blink,HIGH);
Cod_Err = WiFi.status();
MesError = Exit_Error(Cod_Err);
MySerial.Write_Other("WIFI status: ",Cod_Err,false,false,true);
MySerial.Write_Message(MesError,false,true);
MySerial.Write_Message("Or Time_out",false,true);
MySerial.Stop_Session(true,false);
while (1)
ESP.wdtFeed();
}
}
// ok connesione
MySerial.Write_Message("WIFI CONNECTED! IP --> ",true,false);
String LP = WiFi.localIP().toString();
MySerial.Write_Message(LP,false,true);
// WiFi.disconnect();
// MySerial.Write_Message("Disconesso" ,true,true);
lcd.setCursor(1,1);
lcd.print(WiFi.localIP());
delay(2000); // ritardo per visualizzazione
lcd.setCursor(0,0);
lcd.clear();
timeClient.begin(); // start client
if (digitalRead(LED_SOLAR) == HIGH)
timeClient.setTimeOffset(3600);
else
// ora solare (7200 per legale)
timeClient.setTimeOffset(7200);
}