Code: Select all
/
// initialize timer
//
ESP8266
os_timer_t secTimer;
void timerDisplayTime(void *pArg) {
displayTime();
}
ESP32
void IRAM_ATTR resetModule() {
portENTER_CRITICAL_ISR(&timerMux);
void timerDisplayTime(void *pArg);
displayTime(); // serial2 output to Nextion
portEXIT_CRITICAL_ISR(&timerMux);
}
ESP8266
Setup()
os_timer_setfn(&secTimer, timerDisplayTime, NULL);
if (timeServerConnected)
os_timer_arm(&secTimer, 1000, true);
ESP32
timer = timerBegin(0, 80, true); //timer 0, div 80 MHZ
timerAttachInterrupt(timer, &resetModule, true); //attach callback
timerAlarmWrite(timer, 1000000, true); //set time in us
if (timeServerConnected)
timerAlarmEnable(timer); //enable interrupt
ESP8266
void loop() {
if (!timeServerConnected) {
getTimeFromServer();
if (timeServerConnected)
os_timer_arm(&secTimer, 1000, true);
}
ESP32
Void loop(){
if (!timeServerConnected) {
getTimeFromServer();
if (timeServerConnected){
portENTER_CRITICAL(&timerMux);
portEXIT_CRITICAL(&timerMux);
}