Compare commits

..

2 Commits

Author SHA1 Message Date
Siwat Sirichai 95d968a920 automatic ntp update 2023-09-17 01:12:29 +07:00
Siwat Sirichai 893a7e9203 pre-fram 2023-09-17 00:06:00 +07:00
3 changed files with 32 additions and 15 deletions

View File

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

View File

@ -8,7 +8,8 @@
#include <IRremote.hpp> #include <IRremote.hpp>
#include <daikin_ir.hpp> #include <daikin_ir.hpp>
#include <dhtnew.h> #include <dhtnew.h>
#include "EasyNextionLibrary.h" #include <time.h>
#include <EasyNextionLibrary.h>
#include <lcd.hpp> #include <lcd.hpp>
// Network Connectivity // Network Connectivity
@ -29,6 +30,7 @@ char STATE_REQUEST_TOPIC[40];
const char MQTT_USERNAME[] = "username"; const char MQTT_USERNAME[] = "username";
const char MQTT_PASSWORD[] = "password"; const char MQTT_PASSWORD[] = "password";
#endif #endif
uint8_t utc_offset = 7;
// Inputs // Inputs
#define VINT_COUNT 16 #define VINT_COUNT 16
@ -206,7 +208,6 @@ void setup()
IrSender.begin(IR_SEND_PIN); IrSender.begin(IR_SEND_PIN);
lcd_send_command("boot_state.txt=\"Network Initializing . . .\""); lcd_send_command("boot_state.txt=\"Network Initializing . . .\"");
network_begin(); network_begin();
Serial.println("Initializing MQTT . . .");
lcd_send_command("boot_state.txt=\"IoT Core Initializing . . .\""); lcd_send_command("boot_state.txt=\"IoT Core Initializing . . .\"");
mqtt_connect(); mqtt_connect();
lcd_send_command("boot_state.txt=\"Threads Initializing . . .\""); lcd_send_command("boot_state.txt=\"Threads Initializing . . .\"");
@ -323,14 +324,20 @@ void network_begin()
ETH.setHostname(HOSTNAME); ETH.setHostname(HOSTNAME);
ETH.config(IP, GATEWAY, SUBNET, DNS, DNS); ETH.config(IP, GATEWAY, SUBNET, DNS, DNS);
delay(1000); 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 . . .\""); lcd_send_command("boot_state.txt=\"Ethernet Core Initializing . . .\"");
delay(500); delay(500);
lcd_send_command("boot_state.txt=\"MQTT Core Initializing . . .\""); lcd_send_command("boot_state.txt=\"NTP Core Initializing . . .\"");
delay(1250);
lcd_send_command("boot_state.txt=\"FRAM Initializing . . .\"");
delay(325);
lcd_send_command("boot_state.txt=\"Software Initializing . . .\"");
delay(500); delay(500);
char ntp[19];
MQTT_SERVER.toString().toCharArray(ntp,19);
ESPMega_configNTP(utc_offset*3600,0,ntp);
ESPMega_updateTimeFromNTP();
Serial.println(); Serial.println();
} }
@ -817,9 +824,9 @@ void lcd_refresh()
void lcd_top_bar_update() void lcd_top_bar_update()
{ {
char time_buffer[15]; char time_buffer[15];
//rtctime_t time = ESPMega_getTime(); rtctime_t time = ESPMega_getTime();
//sprintf(time_buffer, "%02d:%02d",time.hours,time.minutes); sprintf(time_buffer, "%02d:%02d",time.hours,time.minutes);
//panel.writeStr("time.txt", time_buffer); panel.writeStr("time.txt", time_buffer);
panel.writeNum("server.pic", standalone ? 4 : 5); panel.writeNum("server.pic", standalone ? 4 : 5);
panel.writeNum("lan.pic", ETH.linkUp() ? 3 : 2); panel.writeNum("lan.pic", ETH.linkUp() ? 3 : 2);
} }
@ -976,7 +983,7 @@ void set_mqtt_server(String address)
void eeprom_ip_update(uint16_t rom_address, uint8_t byte1, uint8_t byte2, uint8_t byte3, uint8_t byte4) void eeprom_ip_update(uint16_t rom_address, uint8_t byte1, uint8_t byte2, uint8_t byte3, uint8_t byte4)
{ {
uint8_t addressblock[4] = {byte1, byte2, byte3, byte4}; uint8_t addressblock[4] = {byte1, byte2, byte3, byte4};
ESPMega_EEPROM.writeBlock(rom_address, addressblock, 4); ESPMega_EEPROM.writeBlockVerify(rom_address, addressblock, 4);
} }
IPAddress eeprom_ip_retrieve(uint16_t rom_address) IPAddress eeprom_ip_retrieve(uint16_t rom_address)
{ {

View File

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