greetings everyone... so i have a nextion NX3224K024 and ESP32S.. im trying to learn how to use nextion by sending a simple date and time text to show it on nextion display... the problem is the nextion didn't receive the data from esp (as i think)... for the nextion display i already design it with nextion editor and it works fine... here's the code im using to show date and time with NTP way..
#include <WiFi.h>
#include "time.h"
#include "esp_sntp.h"
#include <EasyNextionLibrary.h>
// WiFi credentials
const char *ssid = "Mod edit SSID redacted";
const char *password = "Mod edit password redacted";
// NTP servers and timezone configuration
const char *ntpServer1 = "pool.ntp.org";
const char *ntpServer2 = "time.nist.gov";
const long gmtOffset_sec = 25200; // GMT+7 for WIB (Western Indonesia Time)
const int daylightOffset_sec = 0;
// EasyNextion text objects for date and time display
EasyNex myNex(Serial2);
char datestr[10];
char timestr[10];
// char tDO[6];
// char tpH[6];
// char tTemp[6];
void printLocalTime() {
struct tm timeinfo;
if (!getLocalTime(&timeinfo)) {
Serial.println("No time available (yet)");
return;
}
// Format date as string (e.g., "24/07/2024")
strftime(datestr, sizeof(datestr), "%d/%m/%y", &timeinfo);
// Format time as string (e.g., "15:30:45")
strftime(timestr, sizeof(timestr), "%H:%M:%S", &timeinfo);
// Print to Serial (for debugging)
Serial.println(datestr);
Serial.println(timestr);
// Update Nextion display with current date and time
myNex.writeStr("page0.t2", timestr);
myNex.writeStr("page0.t1", datestr);
}
// Callback function (gets called when time adjusts via NTP)
void timeavailable(struct timeval *t) {
Serial.println("Got time adjustment from NTP!");
printLocalTime();
}
void setup() {
Serial.begin(115200);
// Initialize Serial communication for Nextion
Serial2.begin(9600, SERIAL_8N1, 17, 16); // TX = GPIO17, RX = GPIO16
myNex.begin(9600);
// Connect to WiFi
Serial.printf("Connecting to %s ", ssid);
WiFi.begin(ssid, password);
// Optional: Configure NTP server via DHCP
esp_sntp_servermode_dhcp(1);
// Wait for WiFi connection
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println(" CONNECTED");
// Set notification callback function for time sync
sntp_set_time_sync_notification_cb(timeavailable);
// Configure time with NTP servers
configTime(gmtOffset_sec, daylightOffset_sec, ntpServer1, ntpServer2);
// Optionally, set timezone with daylight saving rules
// configTzTime(time_zone, ntpServer1, ntpServer2);
}
void loop() {
delay(1000);
printLocalTime(); // Update time every 5 seconds
// Handle Nextion events
myNex.NextionListen();
}
i also tried to change library from ITEAD to easynextionlib just in case there's something wrong with the library but there's no result ... the RX TX pins also seems right (im using GPIO16 as RX and GPIO17 as TX) the page and text in nextion also seems correct with the code i provided... i also did try change baudrate from 9600 to 115200....
its already a week with no results T_T