diff --git a/.gitignore b/.gitignore index 8beaceb6..89b7ea7f 100644 --- a/.gitignore +++ b/.gitignore @@ -18,3 +18,4 @@ tools/esp8266/binaries *.suo *.ipch tools/esp8266/.vscode/extensions.json +.DS_Store diff --git a/tools/esp8266/app.cpp b/tools/esp8266/app.cpp index 519e070e..efa3c222 100644 --- a/tools/esp8266/app.cpp +++ b/tools/esp8266/app.cpp @@ -115,7 +115,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); @@ -130,6 +129,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; @@ -416,6 +421,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)); if(iv->devControlRequest){ if(mSerialDebug) @@ -656,6 +662,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); @@ -1010,6 +1023,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 77a0f111..8105593c 100644 --- a/tools/esp8266/defines.h +++ b/tools/esp8266/defines.h @@ -21,7 +21,7 @@ //------------------------------------- #define VERSION_MAJOR 0 #define VERSION_MINOR 5 -#define VERSION_PATCH 1 +#define VERSION_PATCH 2 //------------------------------------- @@ -96,6 +96,9 @@ typedef enum #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 @@ -129,7 +132,10 @@ typedef enum #define ADDR_INV_MAX_RTRY ADDR_INV_INTERVAL + INV_INTERVAL_LEN #define ADDR_INV_PWR_LIM ADDR_INV_MAX_RTRY + INV_MAX_RTRY_LEN -#define ADDR_MQTT_ADDR ADDR_INV_PWR_LIM + INV_PWR_LIM_LEN +#define ADDR_NTP_ADDR ADDR_INV_PWR_LIM + INV_PWR_LIM_LEN //Bugfix #125 +#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/convert.py b/tools/esp8266/html/convert.py old mode 100644 new mode 100755 diff --git a/tools/esp8266/html/h/setup_html.h b/tools/esp8266/html/h/setup_html.h index 22b557af..ae14aab2 100644 --- a/tools/esp8266/html/h/setup_html.h +++ b/tools/esp8266/html/h/setup_html.h @@ -1,4 +1,4 @@ #ifndef __SETUP_HTML_H__ #define __SETUP_HTML_H__ -const char setup_html[] PROGMEM = "Setup - {DEVICE}

Setup

Enter the credentials to your prefered WiFi station. After rebooting the device tries to connect with this information.

WiFi

Device Host Name

ERASE SETTINGS (not WiFi)

Inverter

{INVERTERS}

General

Pinout (Wemos)

{PINOUT}

Radio (NRF24L01+)

MQTT

Serial Console



 

Home

Update Firmware

AHOY - {VERSION}

Factory Reset

Reboot

"; +const char setup_html[] PROGMEM = "Setup - {DEVICE}

Setup

Enter the credentials to your prefered WiFi station. After rebooting the device tries to connect with this information.

WiFi

Device Host Name

ERASE SETTINGS (not WiFi)

Inverter

{INVERTERS}

General

Pinout (Wemos)

{PINOUT}

Radio (NRF24L01+)

NTP Server

MQTT

Serial Console



 

Home

Update Firmware

AHOY - {VERSION}

Factory Reset

Reboot

"; #endif /*__SETUP_HTML_H__*/ 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 26a47605..14ed8667 100644 --- a/tools/esp8266/main.cpp +++ b/tools/esp8266/main.cpp @@ -396,8 +396,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 98e9f01c..8f114f09 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