diff --git a/tools/esp8266/app.cpp b/tools/esp8266/app.cpp index 0c6c499e..4c81e95d 100644 --- a/tools/esp8266/app.cpp +++ b/tools/esp8266/app.cpp @@ -13,8 +13,8 @@ app::app() : Main() { mMqttTicker = NULL; mMqttEvt = false; - memset(mCmds, 0, sizeof(uint32_t)); - memset(mChannelStat, 0, sizeof(uint32_t)); + memset(mCmds, 0, sizeof(uint32_t)*DBG_CMD_LIST_LEN); + //memset(mChannelStat, 0, sizeof(uint32_t) * 4); mSys = new HmSystemType(); } @@ -30,13 +30,14 @@ app::~app(void) { void app::setup(const char *ssid, const char *pwd, uint32_t timeout) { Main::setup(ssid, pwd, timeout); - mWeb->on("/", std::bind(&app::showIndex, this)); - mWeb->on("/setup", std::bind(&app::showSetup, this)); - mWeb->on("/save", std::bind(&app::showSave, this)); - mWeb->on("/cmdstat", std::bind(&app::showCmdStatistics, this)); - mWeb->on("/hoymiles", std::bind(&app::showHoymiles, this)); - mWeb->on("/livedata", std::bind(&app::showLiveData, this)); - mWeb->on("/mqttstate", std::bind(&app::showMqtt, this)); + mWeb->on("/", std::bind(&app::showIndex, this)); + mWeb->on("/setup", std::bind(&app::showSetup, this)); + mWeb->on("/save", std::bind(&app::showSave, this)); + mWeb->on("/erase", std::bind(&app::showErase, this)); + mWeb->on("/cmdstat", std::bind(&app::showStatistics, this)); + mWeb->on("/hoymiles", std::bind(&app::showHoymiles, this)); + mWeb->on("/livedata", std::bind(&app::showLiveData, this)); + mWeb->on("/mqttstate", std::bind(&app::showMqtt, this)); if(mSettingsValid) { uint16_t interval; @@ -125,13 +126,15 @@ void app::loop(void) { else if(*cmd == 0x02) mCmds[1]++; else if(*cmd == 0x03) mCmds[2]++; else if(*cmd == 0x81) mCmds[3]++; - else if(*cmd == 0x84) mCmds[4]++; - else mCmds[5]++; + else if(*cmd == 0x82) mCmds[4]++; + else if(*cmd == 0x83) mCmds[5]++; + else if(*cmd == 0x84) mCmds[6]++; + else mCmds[7]++; - if(p->sendCh == 23) mChannelStat[0]++; + /*if(p->sendCh == 23) mChannelStat[0]++; else if(p->sendCh == 40) mChannelStat[1]++; else if(p->sendCh == 61) mChannelStat[2]++; - else mChannelStat[3]++; + else mChannelStat[3]++;*/ } } mSys->BufCtrl.popBack(); @@ -319,20 +322,26 @@ void app::showSave(void) { //----------------------------------------------------------------------------- -void app::showCmdStatistics(void) { +void app::showErase() { + eraseSettings(); + showReboot(); +} + + +//----------------------------------------------------------------------------- +void app::showStatistics(void) { String content = "CMDs:\n"; - content += String("0x01: ") + String(mCmds[0]) + String("\n"); - content += String("0x02: ") + String(mCmds[1]) + String("\n"); - content += String("0x03: ") + String(mCmds[2]) + String("\n"); - content += String("0x81: ") + String(mCmds[3]) + String("\n"); - content += String("0x84: ") + String(mCmds[4]) + String("\n"); - content += String("other: ") + String(mCmds[5]) + String("\n"); - - content += "\nCHANNELs:\n"; + for(uint8_t i = 0; i < DBG_CMD_LIST_LEN; i ++) { + content += String("0x") + String(dbgCmds[i], HEX) + String(": ") + String(mCmds[i]) + String("\n"); + } + content += String("other: ") + String(mCmds[DBG_CMD_LIST_LEN]) + String("\n\n"); + + /*content += "\nCHANNELs:\n"; content += String("23: ") + String(mChannelStat[0]) + String("\n"); content += String("40: ") + String(mChannelStat[1]) + String("\n"); content += String("61: ") + String(mChannelStat[2]) + String("\n"); - content += String("75: ") + String(mChannelStat[3]) + String("\n"); + content += String("75: ") + String(mChannelStat[3]) + String("\n");*/ + mWeb->send(200, "text/plain", content); } diff --git a/tools/esp8266/app.h b/tools/esp8266/app.h index c4cabcdd..e666bf20 100644 --- a/tools/esp8266/app.h +++ b/tools/esp8266/app.h @@ -22,6 +22,9 @@ const char* const wemosPins[] = {"D3 (GPIO0)", "TX (GPIO1)", "D4 (GPIO2)", "RX ( const char* const pinNames[] = {"CS", "CE", "IRQ"}; const char* const pinArgNames[] = {"pinCs", "pinCe", "pinIrq"}; +const uint8_t dbgCmds[] = {0x01, 0x02, 0x03, 0x81, 0x82, 0x83, 0x84}; +#define DBG_CMD_LIST_LEN 7 + class app : public Main { public: app(); @@ -42,7 +45,8 @@ class app : public Main { void showIndex(void); void showSetup(void); void showSave(void); - void showCmdStatistics(void); + void showErase(void); + void showStatistics(void); void showHoymiles(void); void showLiveData(void); void showMqtt(void); @@ -65,6 +69,7 @@ class app : public Main { return ret; } + uint8_t mState; bool mKeyPressed; @@ -73,8 +78,8 @@ class app : public Main { Ticker *mSendTicker; bool mFlagSend; - uint32_t mCmds[6]; - uint32_t mChannelStat[4]; + uint32_t mCmds[DBG_CMD_LIST_LEN+1]; + //uint32_t mChannelStat[4]; uint32_t mRecCnt; // mqtt diff --git a/tools/esp8266/defines.h b/tools/esp8266/defines.h index b91fe2d2..c94668cc 100644 --- a/tools/esp8266/defines.h +++ b/tools/esp8266/defines.h @@ -25,7 +25,7 @@ //------------------------------------- #define VERSION_MAJOR 0 #define VERSION_MINOR 2 -#define VERSION_PATCH 5 +#define VERSION_PATCH 6 //------------------------------------- diff --git a/tools/esp8266/hmInverters.h b/tools/esp8266/hmInverters.h index 1da3f62c..df9cc147 100644 --- a/tools/esp8266/hmInverters.h +++ b/tools/esp8266/hmInverters.h @@ -21,7 +21,7 @@ enum {CH0 = 0, CH1, CH2, CH3, CH4}; enum {CMD01 = 0x01, CMD02, CMD03, CMD82 = 0x82, CMD83, CMD84}; enum {INV_TYPE_HM600 = 0, INV_TYPE_HM1200, INV_TYPE_HM400}; -const char* const invTypes[] = {"HM600", "HM1200", "HM400"}; +const char* const invTypes[] = {"HM600", "HM1200 / HM1500", "HM400"}; #define NUM_INVERTER_TYPES 3 typedef struct { @@ -97,7 +97,7 @@ const byteAssign_t hm600assignment[] = { //------------------------------------- -// HM1200, HM1500? +// HM1200, HM1500 //------------------------------------- const byteAssign_t hm1200assignment[] = { { FLD_UDC, UNIT_V, CH1, CMD01, 3, 2, 10 }, diff --git a/tools/esp8266/hmRadio.h b/tools/esp8266/hmRadio.h index 70e710e0..ea0120fc 100644 --- a/tools/esp8266/hmRadio.h +++ b/tools/esp8266/hmRadio.h @@ -79,7 +79,6 @@ class HmRadio { // enable only receiving interrupts mNrf24.maskIRQ(true, true, false); - // Use lo PA level, as a higher level will disturb CH340 serial usb adapter mNrf24.setPALevel(RF24_PA_MAX); mNrf24.startListening(); diff --git a/tools/esp8266/html/h/setup_html.h b/tools/esp8266/html/h/setup_html.h index f4e99a1a..0fb05a10 100644 --- a/tools/esp8266/html/h/setup_html.h +++ b/tools/esp8266/html/h/setup_html.h @@ -1,4 +1,4 @@ #ifndef __SETUP_H__ #define __SETUP_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

Inverter

{INVERTERS}

General

Pinout (Wemos)

{PINOUT}

MQTT

 

Home

Update Firmware

AHOY - {VERSION}

"; +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}

MQTT

 

Home

Update Firmware

AHOY - {VERSION}

"; #endif /*__SETUP_H__*/ diff --git a/tools/esp8266/html/h/style_css.h b/tools/esp8266/html/h/style_css.h index cf8ac694..dc3639c4 100644 --- a/tools/esp8266/html/h/style_css.h +++ b/tools/esp8266/html/h/style_css.h @@ -1,4 +1,4 @@ #ifndef __STYLE_H__ #define __STYLE_H__ -const char style_css[] PROGMEM = "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;}"; +const char style_css[] PROGMEM = "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;}a.erase {background-color:#006ec0;color:#fff;padding:7px;display:inline-block;margin-top:30px;float:right;}#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;margin:10px 0 30px;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;}"; #endif /*__STYLE_H__*/ diff --git a/tools/esp8266/html/setup.html b/tools/esp8266/html/setup.html index 0ab66fff..b78608f3 100644 --- a/tools/esp8266/html/setup.html +++ b/tools/esp8266/html/setup.html @@ -22,6 +22,9 @@ + + ERASE SETTINGS (not WiFi) +

Inverter

{INVERTERS}

General

diff --git a/tools/esp8266/html/style.css b/tools/esp8266/html/style.css index 5eb5f7dc..21d5340f 100644 --- a/tools/esp8266/html/style.css +++ b/tools/esp8266/html/style.css @@ -57,6 +57,15 @@ a:hover, a:focus { color: #f00; } +a.erase { + background-color: #006ec0; + color: #fff; + padding: 7px; + display: inline-block; + margin-top: 30px; + float: right; +} + #content { padding: 15px 15px 60px 15px; } @@ -103,6 +112,7 @@ input.btn { color: #fff; border: 0px; float: right; + margin: 10px 0 30px; text-transform: uppercase; } diff --git a/tools/esp8266/main.cpp b/tools/esp8266/main.cpp index 61b2075c..746c11e7 100644 --- a/tools/esp8266/main.cpp +++ b/tools/esp8266/main.cpp @@ -90,9 +90,8 @@ bool Main::getConfig(void) { 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)); + // erase application settings except wifi settings + eraseSettings(); } return mApActive; diff --git a/tools/esp8266/main.h b/tools/esp8266/main.h index 9014b6fb..6e096789 100644 --- a/tools/esp8266/main.h +++ b/tools/esp8266/main.h @@ -53,6 +53,17 @@ class Main { return (crcCheck == crcRd); } + void eraseSettings(void) { + uint8_t buf[64] = {0}; + uint16_t addr = ADDR_START_SETTINGS, end; + do { + end = addr += 64; + if(end > (ADDR_SETTINGS_CRC + 2)) + end = (ADDR_SETTINGS_CRC + 2 - addr); + mEep->write(ADDR_START_SETTINGS, buf, (ADDR_NEXT-ADDR_START_SETTINGS)); + } while(addr < ADDR_START_SETTINGS); + } + char mStationSsid[SSID_LEN]; char mStationPwd[PWD_LEN]; bool mWifiSettingsValid;