Closed GiuseppeELio closed 1 month ago
What you can do
Once the new NTP is settled and a WIFI connection is established by the following lines already available in the FRESCO_TD_PC_V2 code
void getDateTimeFromESP() { String dateTimeStr = ""; // Variable to store received date and time string while (esp8266.available() > 0) { char receivedChar = esp8266.read(); if (receivedChar == '\n') { break; // Break the loop when newline character is received } dateTimeStr += receivedChar; // Append received character to the string } Serial.print("Date and Time from ESP8266: "); Serial.println(dateTimeStr); // Extract date and time components int year, month, day, hour, minute, second; sscanf(dateTimeStr.c_str(), "%d/%d/%d %d:%d:%d", &year, &month, &day, &hour, &minute, &second); Serial.print("Parsed Date and Time: "); **rtc.adjust(DateTime(year, month, day, hour, minute, second));** Serial.println("RTC synchronized with ESP8266 time."); }
The rtc is adjusted and the new rtc settings are directly passed to the following lines
void Wifi_status() { while (esp8266.available() > 0) { char received = esp8266.read(); Serial.print("Received: "); Serial.println(received); if (received == 'C') { wifi_status = "Done"; Serial.println("wifi ok"); // Read and update access point IP apIP = ""; while (esp8266.available() > 0) { char apIPChar = esp8266.read(); if (apIPChar == '\n') { break; } apIP += apIPChar; } Serial.print("Access Point IP: "); Serial.println(apIP); // Read and update local WiFi IP localIP = ""; while (esp8266.available() > 0) { char localIPChar = esp8266.read(); if (localIPChar == '\n') { break; } localIP += localIPChar; } Serial.print("Local WiFi IP: "); Serial.println(localIP); **getDateTimeFromESP()**; } else if (received == 'D') { wifi_status = "Fail"; Serial.println("wifi fail"); // Read and update access point IP apIP = ""; while (esp8266.available() > 0) { char apIPChar = esp8266.read(); if (apIPChar == '\n') { break; } apIP += apIPChar; } Serial.print("Access Point IP: "); Serial.println(apIP); // Read and update local WiFi IP localIP = ""; while (esp8266.available() > 0) { char localIPChar = esp8266.read(); if (localIPChar == '\n') { break; } localIP += localIPChar; } Serial.print("Local WiFi IP: "); Serial.println(localIP); } } }
void RTC_initialization() { if (!rtc.begin()) { Serial.println("Couldn't find RTC"); //while (1); } **rtc.adjust(DateTime((__DATE__), (__TIME__)));** // Use this command in order to set the rigth Date and time on the RTC if (rtc.lostPower()) { Serial.println("RTC lost power, lets set the time!"); //Comment out below lines once you set the date & time. rtc.adjust(DateTime((__DATE__), (__TIME__))); } }
here the sequence is to upload the code with line 908 uncommented and then upload it again with the line 908 commented again.
Following these steps you will solve the problem about Date and time settings. If you solved the problem by replacing the battery, please take your time and check that there aren't possible damage to your probes or the board itself or some external short circuit cause, such as a plug that is not working properly.
Date and time are not correct.
Fresco is showing Date and time not correct both on the Oled Display and on the saved TXT file into the SD card. See the attached pictures about the reported issue