diff --git a/tools/esp8266/app.cpp b/tools/esp8266/app.cpp index ebf5142d..6b40cf2c 100644 --- a/tools/esp8266/app.cpp +++ b/tools/esp8266/app.cpp @@ -107,7 +107,6 @@ void app::setup(uint32_t timeout) { mSys->Radio.pinIrq = RF24_IRQ_PIN; } - // nrf24 amplifier power mEep->read(ADDR_RF24_AMP_PWR, &mSys->Radio.AmplifierPower); @@ -122,6 +121,12 @@ void app::setup(uint32_t timeout) { mSerialDebug = (tmp == 0x01); mSys->Radio.mSerialDebug = mSerialDebug; + // ntp + char ntpAddr[NTP_ADDR_LEN]; + uint16_t ntpPort; + mEep->read(ADDR_NTP_ADDR, ntpAddr, NTP_ADDR_LEN); + mEep->read(ADDR_NTP_PORT, &ntpPort); + // TODO set ntpAddr & ntpPort in main // mqtt uint16_t mqttPort; @@ -358,6 +363,7 @@ void app::loop(void) { yield(); if(mSerialDebug) + DPRINTLN(DBG_DEBUG, F("app:loop WiFi WiFi.status ") + String(WiFi.status()) ); DPRINTLN(DBG_INFO, F("Requesting Inverter SN ") + String(iv->serial.u64, HEX)); mSys->Radio.sendTimePacket(iv->radioId.u64, mPayload[iv->id].ts); mRxTicker = 0; @@ -579,6 +585,13 @@ void app::showSetup(void) { mEep->read(ADDR_SER_DEBUG, &tmp); html.replace(F("{SER_DBG_CB}"), (tmp == 0x01) ? "checked" : ""); + char ntpAddr[NTP_ADDR_LEN] = {0}; + uint16_t ntpPort; + mEep->read(ADDR_NTP_ADDR, ntpAddr, NTP_ADDR_LEN); + mEep->read(ADDR_NTP_PORT, &ntpPort); + html.replace(F("{NTP_ADDR}"), String(ntpAddr)); + html.replace(F("{NTP_PORT}"), String(ntpPort)); + char mqttAddr[MQTT_ADDR_LEN] = {0}; uint16_t mqttPort; mEep->read(ADDR_MQTT_ADDR, mqttAddr, MQTT_ADDR_LEN); @@ -837,6 +850,14 @@ void app::saveValues(bool webSend = true) { mSys->Radio.AmplifierPower = mWeb->arg("rf24Power").toInt() & 0x03; mEep->write(ADDR_RF24_AMP_PWR, mSys->Radio.AmplifierPower); + // ntp + char ntpAddr[NTP_ADDR_LEN] = {0}; + uint16_t ntpPort; + mWeb->arg("ntpAddr").toCharArray(ntpAddr, NTP_ADDR_LEN); + ntpPort = mWeb->arg("ntpPort").toInt(); + mEep->write(ADDR_NTP_ADDR, ntpAddr, NTP_ADDR_LEN); + mEep->write(ADDR_NTP_PORT, ntpPort); + // mqtt char mqttAddr[MQTT_ADDR_LEN] = {0}; uint16_t mqttPort; diff --git a/tools/esp8266/defines.h b/tools/esp8266/defines.h index c746930c..6d2d0503 100644 --- a/tools/esp8266/defines.h +++ b/tools/esp8266/defines.h @@ -58,6 +58,9 @@ typedef struct { #define RF24_AMP_PWR_LEN 1 +#define NTP_ADDR_LEN 32 // DNS Name +#define NTP_PORT_LEN 2 // uint16_t + #define MQTT_ADDR_LEN 32 // DNS Name #define MQTT_USER_LEN 16 #define MQTT_PWD_LEN 32 @@ -90,7 +93,10 @@ typedef struct { #define ADDR_INV_INTERVAL ADDR_INV_CH_NAME + INV_CH_CH_NAME_LEN #define ADDR_INV_MAX_RTRY ADDR_INV_INTERVAL + INV_INTERVAL_LEN -#define ADDR_MQTT_ADDR ADDR_INV_MAX_RTRY + INV_MAX_RTRY_LEN +#define ADDR_NTP_ADDR ADDR_INV_MAX_RTRY + INV_MAX_RTRY_LEN +#define ADDR_NTP_PORT ADDR_NTP_ADDR + NTP_ADDR_LEN + +#define ADDR_MQTT_ADDR ADDR_NTP_PORT + NTP_PORT_LEN #define ADDR_MQTT_USER ADDR_MQTT_ADDR + MQTT_ADDR_LEN #define ADDR_MQTT_PWD ADDR_MQTT_USER + MQTT_USER_LEN #define ADDR_MQTT_TOPIC ADDR_MQTT_PWD + MQTT_PWD_LEN diff --git a/tools/esp8266/html/setup.html b/tools/esp8266/html/setup.html index 8988ed3e..a1e0d51c 100644 --- a/tools/esp8266/html/setup.html +++ b/tools/esp8266/html/setup.html @@ -83,6 +83,12 @@ +

NTP Server

+ + + + +

MQTT

diff --git a/tools/esp8266/main.cpp b/tools/esp8266/main.cpp index ffaa0a54..398e02ef 100644 --- a/tools/esp8266/main.cpp +++ b/tools/esp8266/main.cpp @@ -391,8 +391,8 @@ time_t Main::getNtpTime(void) { uint8_t buf[NTP_PACKET_SIZE]; uint8_t retry = 0; - WiFi.hostByName (TIMESERVER_NAME, timeServer); - mUdp->begin(TIME_LOCAL_PORT); + WiFi.hostByName(NTP_SERVER_NAME, timeServer); + mUdp->begin(NTP_LOCAL_PORT); sendNTPpacket(timeServer); diff --git a/tools/esp8266/main.h b/tools/esp8266/main.h index 68f9df5c..416844b5 100644 --- a/tools/esp8266/main.h +++ b/tools/esp8266/main.h @@ -26,9 +26,9 @@ const byte mDnsPort = 53; -/* TIMESERVER CONFIG */ -#define TIMESERVER_NAME "pool.ntp.org" -#define TIME_LOCAL_PORT 8888 +/* NTP TIMESERVER CONFIG */ +#define NTP_SERVER_NAME "pool.ntp.org" +#define NTP_LOCAL_PORT 8888 #define NTP_PACKET_SIZE 48 #define TIMEZONE 1 // Central European time +1