diff --git a/tools/esp8266/app.cpp b/tools/esp8266/app.cpp index fe0d2d23..2b016014 100644 --- a/tools/esp8266/app.cpp +++ b/tools/esp8266/app.cpp @@ -64,6 +64,12 @@ void app::setup(const char *ssid, const char *pwd, uint32_t timeout) { mSendTicker->attach_ms(interval, std::bind(&app::sendTicker, this)); + // pinout + mEep->read(ADDR_PINOUT, &mSys->Radio.pinCs); + mEep->read(ADDR_PINOUT+1, &mSys->Radio.pinCe); + mEep->read(ADDR_PINOUT+2, &mSys->Radio.pinIrq); + + // mqtt uint8_t mqttAddr[MQTT_ADDR_LEN]; char mqttUser[MQTT_USER_LEN]; @@ -372,6 +378,26 @@ void app::showSetup(void) { } html.replace("{INVERTERS}", String(inv)); + + // pinout + String pinout; + for(uint8_t i = 0; i < 3; i++) { + pinout += ""; + pinout += ""; + } + html.replace("{PINOUT}", String(pinout)); + + if(mSettingsValid) { mEep->read(ADDR_INV_INTERVAL, &interval); html.replace("{INV_INTERVAL}", String(interval)); @@ -530,6 +556,13 @@ void app::saveValues(bool webSend = true) { mEep->write(ADDR_INV_INTERVAL, interval); + // pinout + for(uint8_t i = 0; i < 3; i ++) { + uint8_t pin = mWeb->arg(String(pinArgNames[i])).toInt(); + mEep->write(ADDR_PINOUT + i, pin); + } + + // mqtt uint8_t mqttAddr[MQTT_ADDR_LEN] = {0}; char mqttUser[MQTT_USER_LEN]; @@ -565,3 +598,14 @@ void app::saveValues(bool webSend = true) { "

Error while saving

"); } } + + +//----------------------------------------------------------------------------- +void app::updateCrc(void) { + Main::updateCrc(); + + uint16_t crc; + crc = buildEEpCrc(ADDR_START_SETTINGS, (ADDR_NEXT - ADDR_START_SETTINGS)); + //Serial.println("new CRC: " + String(crc, HEX)); + mEep->write(ADDR_SETTINGS_CRC, crc); +} diff --git a/tools/esp8266/app.h b/tools/esp8266/app.h index 48898dd3..e7ac42ad 100644 --- a/tools/esp8266/app.h +++ b/tools/esp8266/app.h @@ -9,14 +9,19 @@ #include "CircularBuffer.h" #include "hmSystem.h" - #include "mqtt.h" - typedef HmRadio RadioType; typedef CircularBuffer BufferType; typedef HmSystem HmSystemType; +const char* const wemosPins[] = {"D3 (GPIO0)", "TX (GPIO1)", "D4 (GPIO2)", "RX (GPIO3)", + "D2 (GPIO4)", "D1 (GPIO5)", "GPIO6", "GPIO7", "GPIO8", + "GPIO9", "GPIO10", "GPIO11", "D6 (GPIO12)", "D7 (GPIO13)", + "D5 (GPIO14)", "D8 (GPIO15)", "D0 (GPIO16)"}; +const char* const pinNames[] = {"CS", "CE", "IRQ"}; +const char* const pinArgNames[] = {"pinCs", "pinCe", "pinIrq"}; + class app : public Main { public: app(); @@ -42,6 +47,7 @@ class app : public Main { void showMqtt(void); void saveValues(bool webSend); + void updateCrc(void); void dumpBuf(const char *info, uint8_t buf[], uint8_t len) { Serial.print(String(info)); diff --git a/tools/esp8266/defines.h b/tools/esp8266/defines.h index 45632063..bbc47a11 100644 --- a/tools/esp8266/defines.h +++ b/tools/esp8266/defines.h @@ -5,9 +5,9 @@ //------------------------------------- // PINOUT //------------------------------------- -#define RF24_IRQ_PIN 4 -#define RF24_CE_PIN 5 #define RF24_CS_PIN 15 +#define RF24_CE_PIN 2 //5 +#define RF24_IRQ_PIN 0 //4 @@ -25,7 +25,7 @@ //------------------------------------- #define VERSION_MAJOR 0 #define VERSION_MINOR 2 -#define VERSION_PATCH 3 +#define VERSION_PATCH 4 //------------------------------------- @@ -34,13 +34,14 @@ #define SSID_LEN 32 #define PWD_LEN 32 #define DEVNAME_LEN 16 -#define CRC_LEN 2 +#define CRC_LEN 2 // uint16_t #define INV_ADDR_LEN MAX_NUM_INVERTERS * 8 // uint64_t #define INV_NAME_LEN MAX_NUM_INVERTERS * MAX_NAME_LENGTH // char[] #define INV_TYPE_LEN MAX_NUM_INVERTERS * 1 // uint8_t #define INV_INTERVAL_LEN 2 // uint16_t +#define PINOUT_LEN 3 // 3 pins: CS, CE, IRQ #define MQTT_ADDR_LEN 4 // IP #define MQTT_USER_LEN 16 @@ -53,7 +54,12 @@ #define ADDR_SSID ADDR_START #define ADDR_PWD ADDR_SSID + SSID_LEN #define ADDR_DEVNAME ADDR_PWD + PWD_LEN -#define ADDR_INV_ADDR ADDR_DEVNAME + DEVNAME_LEN +#define ADDR_WIFI_CRC ADDR_DEVNAME + DEVNAME_LEN +#define ADDR_START_SETTINGS ADDR_WIFI_CRC + CRC_LEN + +#define ADDR_PINOUT ADDR_START_SETTINGS + +#define ADDR_INV_ADDR ADDR_PINOUT + PINOUT_LEN #define ADDR_INV_NAME ADDR_INV_ADDR + INV_ADDR_LEN #define ADDR_INV_TYPE ADDR_INV_NAME + INV_NAME_LEN #define ADDR_INV_INTERVAL ADDR_INV_TYPE + INV_TYPE_LEN diff --git a/tools/esp8266/hmRadio.h b/tools/esp8266/hmRadio.h index 05264d4a..0ab66484 100644 --- a/tools/esp8266/hmRadio.h +++ b/tools/esp8266/hmRadio.h @@ -52,6 +52,10 @@ class HmRadio { mChanIdx = 1; calcDtuCrc(); + + pinCs = CS_PIN; + pinCe = CE_PIN; + pinIrq = IRQ_PIN; } ~HmRadio() {} @@ -117,7 +121,11 @@ class HmRadio { return valid; } - protected: + uint8_t pinCs; + uint8_t pinCe; + uint8_t pinIrq; + + private: void calcDtuCrc(void) { uint64_t addr = DTU_RADIO_ID; uint8_t tmp[5]; diff --git a/tools/esp8266/html/h/setup_html.h b/tools/esp8266/html/h/setup_html.h index 16db89b7..b905b56b 100644 --- a/tools/esp8266/html/h/setup_html.h +++ b/tools/esp8266/html/h/setup_html.h @@ -1 +1 @@ -String setup_html = "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

Inverter

{INVERTERS}

General

MQTT

 

Home

Update Firmware

AHOY - {VERSION}

"; +String setup_html = "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

Inverter

{INVERTERS}

General

Pinout

{PINOUT}

MQTT

 

Home

Update Firmware

AHOY - {VERSION}

"; diff --git a/tools/esp8266/html/h/style_css.h b/tools/esp8266/html/h/style_css.h index 031d688f..6cc7fc67 100644 --- a/tools/esp8266/html/h/style_css.h +++ b/tools/esp8266/html/h/style_css.h @@ -1 +1 @@ -String style_css = "h1 { margin: 0; padding: 20pt; font-size: 22pt; color: #fff; background-color: #006ec0; display: block; text-transform: uppercase; } html, body { font-family: Arial; margin: 0; padding: 0; } p { text-align: justify; font-size: 13pt; } .des { margin-top: 35px; font-size: 14pt; color: #006ec0; } .subdes { font-size: 13pt; color: #006ec0; margin-left: 7px; } .fw { width: 60px; display: block; float: left; } .color { width: 50px; height: 50px; border: 1px solid #ccc; } .range { width: 300px; } a:link, a:visited { text-decoration: none; font-size: 13pt; color: #006ec0; } a:hover, a:focus { color: #f00; } #content { padding: 15px 15px 60px 15px; } #footer { position: fixed; bottom: 0px; height: 45px; background-color: #006ec0; width: 100%; } #footer p { color: #fff; padding-left: 20px; padding-right: 20px; font-size: 10pt !important; } #footer a { color: #fff; } div.content { background-color: #fff; padding-bottom: 65px; overflow: hidden; } input { padding: 7px; font-size: 13pt; } input.text, input.password { width: 70%; box-sizing: border-box; margin-bottom: 10px; /*float: right;*/ border: 1px solid #ccc; } input.button { background-color: #006ec0; color: #fff; border: 0px; float: right; text-transform: uppercase; } input.cb { margin-bottom: 20px; } label { width: 20%; display: inline-block; font-size: 12pt; padding-right: 10px; margin-left: 10px; } .left { float: left; } .right { float: right; } div.ch { width: 250px; height: 410px; background-color: #006ec0; display: inline-block; margin-right: 20px; margin-bottom: 20px; } div.ch .value, div.ch .info, div.ch .head { color: #fff; display: block; width: 100%; text-align: center; } div.ch .unit { font-size: 19px; margin-left: 10px; } div.ch .value { margin-top: 20px; font-size: 30px; } div.ch .info { margin-top: 3px; font-size: 10px; } div.ch .head { background-color: #003c80; padding: 10px 0 10px 0; } "; +String style_css = "h1 { margin: 0; padding: 20pt; font-size: 22pt; color: #fff; background-color: #006ec0; display: block; text-transform: uppercase; } html, body { font-family: Arial; margin: 0; padding: 0; } p { text-align: justify; font-size: 13pt; } .des { margin-top: 35px; font-size: 14pt; color: #006ec0; } .subdes { font-size: 13pt; color: #006ec0; margin-left: 7px; } .fw { width: 60px; display: block; float: left; } .color { width: 50px; height: 50px; border: 1px solid #ccc; } .range { width: 300px; } a:link, a:visited { text-decoration: none; font-size: 13pt; color: #006ec0; } a:hover, a:focus { color: #f00; } #content { padding: 15px 15px 60px 15px; } #footer { position: fixed; bottom: 0px; height: 45px; background-color: #006ec0; width: 100%; } #footer p { color: #fff; padding-left: 20px; padding-right: 20px; font-size: 10pt !important; } #footer a { color: #fff; } div.content { background-color: #fff; padding-bottom: 65px; overflow: hidden; } input, select { padding: 7px; font-size: 13pt; } input.text, select { width: 70%; box-sizing: border-box; margin-bottom: 10px; border: 1px solid #ccc; } input.btn { background-color: #006ec0; color: #fff; border: 0px; float: right; text-transform: uppercase; } input.cb { margin-bottom: 20px; } label { width: 20%; display: inline-block; font-size: 12pt; padding-right: 10px; margin-left: 10px; } .left { float: left; } .right { float: right; } div.ch { width: 250px; height: 410px; background-color: #006ec0; display: inline-block; margin-right: 20px; margin-bottom: 20px; } div.ch .value, div.ch .info, div.ch .head { color: #fff; display: block; width: 100%; text-align: center; } div.ch .unit { font-size: 19px; margin-left: 10px; } div.ch .value { margin-top: 20px; font-size: 30px; } div.ch .info { margin-top: 3px; font-size: 10px; } div.ch .head { background-color: #003c80; padding: 10px 0 10px 0; } "; diff --git a/tools/esp8266/html/setup.html b/tools/esp8266/html/setup.html index c63c6bbc..0ab66fff 100644 --- a/tools/esp8266/html/setup.html +++ b/tools/esp8266/html/setup.html @@ -28,6 +28,9 @@ +

Pinout (Wemos)

+ {PINOUT} +

MQTT

@@ -43,7 +46,7 @@

 

- + diff --git a/tools/esp8266/html/style.css b/tools/esp8266/html/style.css index acb7ec88..5eb5f7dc 100644 --- a/tools/esp8266/html/style.css +++ b/tools/esp8266/html/style.css @@ -86,20 +86,19 @@ div.content { overflow: hidden; } -input { +input, select { padding: 7px; font-size: 13pt; } -input.text, input.password { +input.text, select { width: 70%; box-sizing: border-box; margin-bottom: 10px; - /*float: right;*/ border: 1px solid #ccc; } -input.button { +input.btn { background-color: #006ec0; color: #fff; border: 0px; diff --git a/tools/esp8266/main.cpp b/tools/esp8266/main.cpp index 1f48531e..2555188d 100644 --- a/tools/esp8266/main.cpp +++ b/tools/esp8266/main.cpp @@ -12,8 +12,9 @@ Main::Main(void) { mUpdater = new ESP8266HTTPUpdateServer(); mUdp = new WiFiUDP(); - mApActive = true; - mSettingsValid = false; + mApActive = true; + mWifiSettingsValid = false; + mSettingsValid = false; snprintf(mVersion, 12, "%d.%d.%d", VERSION_MAJOR, VERSION_MINOR, VERSION_PATCH); @@ -74,21 +75,11 @@ void Main::loop(void) { //----------------------------------------------------------------------------- bool Main::getConfig(void) { bool mApActive = false; - uint16_t crcRd, crcCheck; - uint8_t buf[ADDR_NEXT-ADDR_START]; - // check settings crc - mEep->read(ADDR_START, buf, (ADDR_NEXT-ADDR_START)); - crcCheck = crc16(buf, (ADDR_NEXT-ADDR_START)); - mEep->read(ADDR_SETTINGS_CRC, &crcRd); + mWifiSettingsValid = checkEEpCrc(ADDR_START, ADDR_WIFI_CRC, ADDR_WIFI_CRC); + mSettingsValid = checkEEpCrc(ADDR_START_SETTINGS, (ADDR_NEXT-ADDR_START_SETTINGS), ADDR_SETTINGS_CRC); - if(crcCheck == crcRd) - mSettingsValid = true; - //else - // Serial.println("CRC RD: " + String(crcRd, HEX) + " CRC CHECK: " + String(crcCheck, HEX)); - - - if(mSettingsValid) { + if(mWifiSettingsValid) { mEep->read(ADDR_SSID, mStationSsid, SSID_LEN); mEep->read(ADDR_PWD, mStationPwd, PWD_LEN); mEep->read(ADDR_DEVNAME, mDeviceName, DEVNAME_LEN); @@ -98,6 +89,10 @@ bool Main::getConfig(void) { memset(mStationSsid, 0, SSID_LEN); memset(mStationPwd, 0, PWD_LEN); memset(mDeviceName, 0, DEVNAME_LEN); + + // erase eeprom + uint8_t buf[ADDR_NEXT-ADDR_START_SETTINGS] = {0}; + mEep->write(ADDR_START_SETTINGS, buf, (ADDR_NEXT-ADDR_START_SETTINGS)); } return mApActive; @@ -223,12 +218,9 @@ void Main::saveValues(bool webSend = true) { //----------------------------------------------------------------------------- void Main::updateCrc(void) { uint16_t crc; - uint8_t buf[ADDR_NEXT-ADDR_START]; - - mEep->read(ADDR_START, buf, (ADDR_NEXT-ADDR_START)); - crc = crc16(buf, (ADDR_NEXT-ADDR_START)); + crc = buildEEpCrc(ADDR_START, ADDR_WIFI_CRC); //Serial.println("new CRC: " + String(crc, HEX)); - mEep->write(ADDR_SETTINGS_CRC, crc); + mEep->write(ADDR_WIFI_CRC, crc); } diff --git a/tools/esp8266/main.h b/tools/esp8266/main.h index 1ea082c1..9014b6fb 100644 --- a/tools/esp8266/main.h +++ b/tools/esp8266/main.h @@ -40,8 +40,22 @@ class Main { virtual void saveValues(bool webSend); virtual void updateCrc(void); + inline uint16_t buildEEpCrc(uint32_t start, uint32_t length) { + uint8_t buf[length]; + mEep->read(start, buf, length); + return crc16(buf, length); + } + + bool checkEEpCrc(uint32_t start, uint32_t length, uint32_t crcPos) { + uint16_t crcRd, crcCheck; + crcCheck = buildEEpCrc(start, length); + mEep->read(crcPos, &crcRd); + return (crcCheck == crcRd); + } + char mStationSsid[SSID_LEN]; char mStationPwd[PWD_LEN]; + bool mWifiSettingsValid; bool mSettingsValid; bool mApActive; ESP8266WebServer *mWeb;