automatic ntp update

This commit is contained in:
Siwat Sirichai 2023-09-17 01:12:29 +07:00
parent 893a7e9203
commit 95d968a920
3 changed files with 28 additions and 11 deletions

View File

@ -12,7 +12,7 @@
platform = espressif32
board = wt32-eth01
framework = arduino
lib_deps = siwats/ESPMegaPROR3@^1.2.1
lib_deps = siwats/ESPMegaPROR3@^1.2.2
knolleary/PubSubClient@^2.8
ivanseidel/ArduinoThread@^2.1.1
arduino-libraries/Arduino_BuiltIn@^1.0.0

View File

@ -8,7 +8,8 @@
#include <IRremote.hpp>
#include <daikin_ir.hpp>
#include <dhtnew.h>
#include "EasyNextionLibrary.h"
#include <time.h>
#include <EasyNextionLibrary.h>
#include <lcd.hpp>
// Network Connectivity
@ -29,6 +30,7 @@ char STATE_REQUEST_TOPIC[40];
const char MQTT_USERNAME[] = "username";
const char MQTT_PASSWORD[] = "password";
#endif
uint8_t utc_offset = 7;
// Inputs
#define VINT_COUNT 16
@ -206,7 +208,6 @@ void setup()
IrSender.begin(IR_SEND_PIN);
lcd_send_command("boot_state.txt=\"Network Initializing . . .\"");
network_begin();
Serial.println("Initializing MQTT . . .");
lcd_send_command("boot_state.txt=\"IoT Core Initializing . . .\"");
mqtt_connect();
lcd_send_command("boot_state.txt=\"Threads Initializing . . .\"");
@ -323,14 +324,20 @@ void network_begin()
ETH.setHostname(HOSTNAME);
ETH.config(IP, GATEWAY, SUBNET, DNS, DNS);
delay(1000);
lcd_send_command("boot_state.txt=\"Ethernet Core Initializing \"");
delay(500);
lcd_send_command("boot_state.txt=\"Ethernet Core Initializing . \"");
delay(500);
lcd_send_command("boot_state.txt=\"Ethernet Core Initializing . . \"");
delay(500);
lcd_send_command("boot_state.txt=\"Ethernet Core Initializing . . .\"");
delay(500);
lcd_send_command("boot_state.txt=\"MQTT Core Initializing . . .\"");
delay(1250);
lcd_send_command("boot_state.txt=\"FRAM Initializing . . .\"");
delay(325);
lcd_send_command("boot_state.txt=\"Software Initializing . . .\"");
lcd_send_command("boot_state.txt=\"NTP Core Initializing . . .\"");
delay(500);
char ntp[19];
MQTT_SERVER.toString().toCharArray(ntp,19);
ESPMega_configNTP(utc_offset*3600,0,ntp);
ESPMega_updateTimeFromNTP();
Serial.println();
}

View File

@ -1,13 +1,23 @@
#ifndef USER_CODE
#define USER_CODE
#include <ESPMegaPRO.h>
void user_pre_init() {
}
void user_init() {
}
void user_loop() {
}
void virtual_interrupt_user_callback(int pin, int state) {
//Automation: Light Switch
}
void timer_tick_callback() {
//Automation: Night Light
}
}
#endif