From 0188bb763fbda22da6de701b7113e3c9b65bf737 Mon Sep 17 00:00:00 2001 From: Kai Lauterbach Date: Tue, 25 Apr 2023 15:35:04 +0200 Subject: [PATCH] Fixed NTP read and init of tc data block in RAM. --- firmware/config.h | 4 ++-- firmware/firmware.ino | 5 +++-- firmware/timing_control.ino | 16 +++++++++------- 3 files changed, 14 insertions(+), 11 deletions(-) diff --git a/firmware/config.h b/firmware/config.h index 4b4ddd5..f190aec 100644 --- a/firmware/config.h +++ b/firmware/config.h @@ -14,8 +14,8 @@ #define EEPROM_LAST_STATE_ADDRESS 4 // the first "last state" information for the first light #define EEPROM_TIMING_DATA_ADDRESS (EEPROM_LAST_STATE_ADDRESS + LIGHTS_COUNT) // Stored data date per light ELE_USED; HH; MM; CH1; CH2; CH3; CH4; -#define TIME_CHECK_INTERVAL_MS (10000UL) // 600000 +#define TIME_CHECK_INTERVAL_MS (60000UL) // 60 second interval #define MY_NTP_SERVER "de.pool.ntp.org" -#define DISABLE_WEB_CONTROL +//#define DISABLE_WEB_CONTROL diff --git a/firmware/firmware.ino b/firmware/firmware.ino index b07c7d9..db47f65 100644 --- a/firmware/firmware.ino +++ b/firmware/firmware.ino @@ -15,6 +15,7 @@ uint8_t pins[LIGHTS_COUNT] = {12, 15, 13, 14}; IPAddress strip_ip ( 192, 168, 0, 26); // choose an unique IP Adress IPAddress gateway_ip ( 192, 168, 0, 1); // Router IP IPAddress subnet_mask( 255, 255, 255, 0); +IPAddress dns ( 192, 168, 0, 1); //********************************// @@ -190,13 +191,13 @@ void read_eeprom_config() void setup() { - EEPROM.begin(512); + EEPROM.begin(256); Serial.begin(SERIAL_BAUD_RATE); if (EEPROM.read(EEPROM_DYNAMIC_IP_ADDRESS) == 0) { - WiFi.config(strip_ip, gateway_ip, subnet_mask); + WiFi.config(strip_ip, gateway_ip, subnet_mask, dns); } read_eeprom_config(); diff --git a/firmware/timing_control.ino b/firmware/timing_control.ino index 4667a8b..d401337 100644 --- a/firmware/timing_control.ino +++ b/firmware/timing_control.ino @@ -24,13 +24,12 @@ //***********************************// /* Globals */ -uint32_t tc_last_check = 0; +uint32_t tc_last_check = 60000; -const long updateInterval = 60000; const long utcOffsetInSeconds = 3600; WiFiUDP ntpUDP; -NTPClient timeClient(ntpUDP, MY_NTP_SERVER, utcOffsetInSeconds, updateInterval); +NTPClient timeClient(ntpUDP, MY_NTP_SERVER, utcOffsetInSeconds); struct tc_data_st { uint8_t enstate; @@ -42,7 +41,7 @@ struct tc_data_st { uint8_t ch4; }; -struct tc_data_st tc_data[LIGHTS_COUNT]; +struct tc_data_st tc_data[10]; uint8_t example_timer_data_block[] = { // state hour min ch1 ch2 ch3 ch3 @@ -151,16 +150,19 @@ void tc_update() void tc_updateTime() { - if (timeClient.update()) + /**/ + if (timeClient.update() || millis() > (tc_last_check + TIME_CHECK_INTERVAL_MS)) { - Serial.println("TC: Reading time from server..."); - Serial.println(timeClient.getFormattedTime()); + tc_last_check = millis(); + //Serial.println("TC: Read time from server..."); + //Serial.println(timeClient.getFormattedTime()); Serial.print("Local time: "); Serial.print(timeClient.getHours()); Serial.print(":"); Serial.println(timeClient.getMinutes()); } + /**/ } //********************************//