From 539d4f73c1c7a7f49b2f45270315cc90a52c7503 Mon Sep 17 00:00:00 2001 From: lumapu Date: Tue, 3 May 2022 21:03:03 +0200 Subject: [PATCH] * added config.h for general configuration * added option to compile WiFi SSID + PWD to firmware * added option to configure WiFi access point name and password * added feature to retry connect to station WiFi (configurable timeouts) * updated index.html * added option for factory reset * added info about project on index.html * moved "update" and "home" to footer * fixed #23 HM1200 yield day unit * fixed DNS name of ESP after setup (some commits before) --- tools/esp8266/app.cpp | 24 ++++---- tools/esp8266/app.h | 1 - tools/esp8266/config.h | 42 ++++++++++++++ tools/esp8266/defines.h | 15 +---- tools/esp8266/esp8266.ino | 4 +- tools/esp8266/hmDefines.h | 2 +- tools/esp8266/html/h/hoymiles_html.h | 2 +- tools/esp8266/html/h/index_html.h | 2 +- tools/esp8266/html/h/setup_html.h | 2 +- tools/esp8266/html/h/style_css.h | 2 +- tools/esp8266/html/hoymiles.html | 2 +- tools/esp8266/html/index.html | 15 +++-- tools/esp8266/html/setup.html | 2 + tools/esp8266/html/style.css | 36 +++++------- tools/esp8266/main.cpp | 82 +++++++++++++++++++++++----- tools/esp8266/main.h | 17 +++--- 16 files changed, 166 insertions(+), 84 deletions(-) create mode 100644 tools/esp8266/config.h diff --git a/tools/esp8266/app.cpp b/tools/esp8266/app.cpp index 4621abcd..53b7a93f 100644 --- a/tools/esp8266/app.cpp +++ b/tools/esp8266/app.cpp @@ -39,7 +39,6 @@ void app::setup(const char *ssid, const char *pwd, uint32_t timeout) { 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) { uint64_t invSerial; @@ -154,7 +153,7 @@ void app::loop(void) { mSys->BufCtrl.popBack(); } - if(checkTicker(&mSendTicker, &mSendInterval)) { + if(checkTicker(&mSendTicker, mSendInterval)) { Inverter<> *inv; for(uint8_t i = 0; i < MAX_NUM_INVERTERS; i ++) { inv = mSys->getInverterByPos(i); @@ -168,7 +167,7 @@ void app::loop(void) { // mqtt mMqtt.loop(); - if(checkTicker(&mMqttTicker, &mMqttInterval)) { + if(checkTicker(&mMqttTicker, mMqttInterval)) { mMqtt.isConnected(true); char topic[30], val[10]; for(uint8_t id = 0; id < mSys->getNumInverters(); id++) { @@ -360,11 +359,19 @@ void app::showStatistics(void) { content += String("75: ") + String(mChannelStat[3]) + String("\n");*/ if(!mSys->Radio.isChipConnected()) - content += "WARNING! your NRF24 module can't be reached, check the wiring\n"; + content += "WARNING! your NRF24 module can't be reached, check the wiring and pinout (setup)\n"; if(mShowRebootRequest) content += "INFO: reboot your ESP to apply all your configuration changes!\n"; + if(!mSettingsValid) + content += "INFO: your settings are invalid, please switch to setup to correct this.\n"; + + content += "MQTT: "; + if(!mMqtt.isConnected()) + content += "not "; + content += "connected\n"; + mWeb->send(200, "text/plain", content); } @@ -448,15 +455,6 @@ void app::showLiveData(void) { } -//----------------------------------------------------------------------------- -void app::showMqtt(void) { - String txt = "connected"; - if(!mMqtt.isConnected()) - txt = "not " + txt; - mWeb->send(200, "text/plain", txt); -} - - //----------------------------------------------------------------------------- void app::saveValues(bool webSend = true) { Main::saveValues(false); // general configuration diff --git a/tools/esp8266/app.h b/tools/esp8266/app.h index 65225306..64207d3d 100644 --- a/tools/esp8266/app.h +++ b/tools/esp8266/app.h @@ -47,7 +47,6 @@ class app : public Main { void showStatistics(void); void showHoymiles(void); void showLiveData(void); - void showMqtt(void); void saveValues(bool webSend); void updateCrc(void); diff --git a/tools/esp8266/config.h b/tools/esp8266/config.h new file mode 100644 index 00000000..0e4cdc43 --- /dev/null +++ b/tools/esp8266/config.h @@ -0,0 +1,42 @@ +#ifndef __CONFIG_H__ +#define __CONFIG_H__ + +// fallback WiFi info +#define FB_WIFI_SSID "YOUR_WIFI_SSID" +#define FB_WIFI_PWD "YOUR_WIFI_PWD" + + +// access point info +#define WIFI_AP_SSID "AHOY DTU" +#define WIFI_AP_PWD "esp_8266" + + +//------------------------------------- +// CONFIGURATION - COMPILE TIME +//------------------------------------- +// time in seconds how long the station info (ssid + pwd) will be tried +#define WIFI_TRY_CONNECT_TIME 15 + +// time during the ESP will act as access point on connection failure (to +// station) in seconds +#define WIFI_AP_ACTIVE_TIME 3*60 + +// default device name +#define DEF_DEVICE_NAME "ESP-DTU" + +// number of packets hold in buffer +#define PACKET_BUFFER_SIZE 30 + +// number of configurable inverters +#define MAX_NUM_INVERTERS 3 + +// maximum human readable inverter name length +#define MAX_NAME_LENGTH 16 + +// maximum buffer length of packet received / sent to RF24 module +#define MAX_RF_PAYLOAD_SIZE 64 + +// changes the style of "/setup" page, visualized = nicer +#define LIVEDATA_VISUALIZED + +#endif /*__CONFIG_H__*/ diff --git a/tools/esp8266/defines.h b/tools/esp8266/defines.h index 0dc7a83f..98ba2539 100644 --- a/tools/esp8266/defines.h +++ b/tools/esp8266/defines.h @@ -1,31 +1,22 @@ #ifndef __DEFINES_H__ #define __DEFINES_H__ +#include "config.h" //------------------------------------- -// PINOUT +// PINOUT (Default, can be changed in setup) //------------------------------------- #define RF24_CS_PIN 15 #define RF24_CE_PIN 2 #define RF24_IRQ_PIN 0 -//------------------------------------- -// CONFIGURATION - COMPILE TIME -//------------------------------------- -#define PACKET_BUFFER_SIZE 30 -#define MAX_NUM_INVERTERS 3 -#define MAX_NAME_LENGTH 16 -#define MAX_RF_PAYLOAD_SIZE 64 -#define LIVEDATA_VISUALIZED // show live data pv-module wise or as dump - - //------------------------------------- // VERSION //------------------------------------- #define VERSION_MAJOR 0 #define VERSION_MINOR 3 -#define VERSION_PATCH 3 +#define VERSION_PATCH 4 //------------------------------------- diff --git a/tools/esp8266/esp8266.ino b/tools/esp8266/esp8266.ino index 5f22245e..c418d8a1 100644 --- a/tools/esp8266/esp8266.ino +++ b/tools/esp8266/esp8266.ino @@ -8,13 +8,13 @@ #include #include "app.h" +#include "config.h" app myApp; //----------------------------------------------------------------------------- void setup() { - // AP name, password, timeout - myApp.setup("ESP AHOY", "esp_8266", 15); + myApp.setup(WIFI_AP_SSID, WIFI_AP_PWD, WIFI_TRY_CONNECT_TIME); // TODO: move to HmRadio attachInterrupt(digitalPinToInterrupt(myApp.getIrqPin()), handleIntr, FALLING); diff --git a/tools/esp8266/hmDefines.h b/tools/esp8266/hmDefines.h index 0f2af157..1c27ced3 100644 --- a/tools/esp8266/hmDefines.h +++ b/tools/esp8266/hmDefines.h @@ -146,8 +146,8 @@ const byteAssign_t hm1200assignment[] = { { FLD_F, UNIT_HZ, CH0, CMD84, 1, 2, 100 }, { FLD_PCT, UNIT_PCT, CH0, CMD84, 9, 2, 10 }, { FLD_T, UNIT_C, CH0, CMD84, 11, 2, 10 }, + { FLD_YD, UNIT_WH, CH0, CMDFF, CALC_YD_CH0, 0, 0 }, { FLD_YT, UNIT_KWH, CH0, CMDFF, CALC_YT_CH0, 0, 0 }, - { FLD_YD, UNIT_KWH, CH0, CMDFF, CALC_YD_CH0, 0, 0 }, { FLD_UDC, UNIT_V, CH2, CMDFF, CALC_UDC_CH, CH1, 0 }, { FLD_UDC, UNIT_V, CH4, CMDFF, CALC_UDC_CH, CH3, 0 } }; diff --git a/tools/esp8266/html/h/hoymiles_html.h b/tools/esp8266/html/h/hoymiles_html.h index 594e4b25..8401ebac 100644 --- a/tools/esp8266/html/h/hoymiles_html.h +++ b/tools/esp8266/html/h/hoymiles_html.h @@ -1,4 +1,4 @@ #ifndef __HOYMILES_H__ #define __HOYMILES_H__ -const char hoymiles_html[] PROGMEM = "Index - {DEVICE}

AHOY - {DEVICE}

Home

Every 10 seconds the values are updated

© 2022

AHOY :: {VERSION}

"; +const char hoymiles_html[] PROGMEM = "Index - {DEVICE}

AHOY - {DEVICE}

Every 10 seconds the values are updated

© 2022

Home

AHOY :: {VERSION}

"; #endif /*__HOYMILES_H__*/ diff --git a/tools/esp8266/html/h/index_html.h b/tools/esp8266/html/h/index_html.h index 53eeda89..67dc9144 100644 --- a/tools/esp8266/html/h/index_html.h +++ b/tools/esp8266/html/h/index_html.h @@ -1,4 +1,4 @@ #ifndef __INDEX_H__ #define __INDEX_H__ -const char index_html[] PROGMEM = "Index - {DEVICE}

AHOY - {DEVICE}

Hoymiles
Update

Setup
Reboot

Uptime:

Time:

MQTT:

Statistics:

© 2022

AHOY :: {VERSION}

"; +const char index_html[] PROGMEM = "Index - {DEVICE}

AHOY - {DEVICE}

Visualization

Setup

Uptime:

Time:

Statistics:

This project was started from this (Mikrocontroller.net)discussion.
New updates can be found on Github: https://github.com/grindylow/ahoy

Please report issues using the feature provided by Github.

© 2022

Update Firmware

AHOY :: {VERSION}

Reboot

"; #endif /*__INDEX_H__*/ diff --git a/tools/esp8266/html/h/setup_html.h b/tools/esp8266/html/h/setup_html.h index 95f1236f..1b01ff97 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

ERASE SETTINGS (not WiFi)

Inverter

{INVERTERS}

General

Pinout (Wemos)

{PINOUT}

Radio (NRF24L01+)

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}

Radio (NRF24L01+)

MQTT

 

"; #endif /*__SETUP_H__*/ diff --git a/tools/esp8266/html/h/style_css.h b/tools/esp8266/html/h/style_css.h index cf0488e4..7c4d61d6 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;}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:auto;}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-iv {width:100%;background-color:#32b004;display:inline-block;margin-bottom:20px;padding-bottom:20px;overflow:auto;}div.ch {width:250px;height:550px;background-color:#006ec0;display:inline-block;margin-right:20px;margin-bottom:20px;overflow:auto;}div.ch .value, div.ch .info, div.ch .head, div.ch-iv .value, div.ch-iv .info, div.ch-iv .head {color:#fff;display:block;width:100%;text-align:center;}.subgrp {float:left;width:250px;}div.ch .unit, div.ch-iv .unit {font-size:19px;margin-left:10px;}div.ch .value, div.ch-iv .value {margin-top:20px;font-size:30px;}div.ch .info, div.ch-iv .info {margin-top:3px;font-size:10px;}div.ch .head {background-color:#003c80;padding:10px 0 10px 0;}div.ch-iv .head {background-color:#1c6800;padding:10px 0 10px 0;}div.iv {max-width:1060px;}div.ch:last-child {margin-right:0px !important;}"; +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:13pt;color:#006ec0;}.subdes {font-size:12pt;color:#006ec0;margin-left:7px;}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%;border-top:5px solid #fff;}#footer p, #footer a {color:#fff;padding-left:20px;padding-right:20px;font-size:10pt !important;}div.content {background-color:#fff;padding-bottom:65px;overflow:auto;}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-iv {width:100%;background-color:#32b004;display:inline-block;margin-bottom:20px;padding-bottom:20px;overflow:auto;}div.ch {width:250px;min-height:420px;background-color:#006ec0;display:inline-block;margin-right:20px;margin-bottom:20px;overflow:auto;padding-bottom:20px;}div.ch .value, div.ch .info, div.ch .head, div.ch-iv .value, div.ch-iv .info, div.ch-iv .head {color:#fff;display:block;width:100%;text-align:center;}.subgrp {float:left;width:250px;}div.ch .unit, div.ch-iv .unit {font-size:19px;margin-left:10px;}div.ch .value, div.ch-iv .value {margin-top:20px;font-size:30px;}div.ch .info, div.ch-iv .info {margin-top:3px;font-size:10px;}div.ch .head {background-color:#003c80;padding:10px 0 10px 0;}div.ch-iv .head {background-color:#1c6800;padding:10px 0 10px 0;}div.iv {max-width:1060px;}div.ch:last-child {margin-right:0px !important;}#note {margin:50px 10px 10px 10px;padding-top:10px;width:100%;border-top:1px solid #bbb;}"; #endif /*__STYLE_H__*/ diff --git a/tools/esp8266/html/hoymiles.html b/tools/esp8266/html/hoymiles.html index 4ac61f25..3f4a6256 100644 --- a/tools/esp8266/html/hoymiles.html +++ b/tools/esp8266/html/hoymiles.html @@ -30,12 +30,12 @@

AHOY - {DEVICE}

-

Home

Every 10 seconds the values are updated

diff --git a/tools/esp8266/html/index.html b/tools/esp8266/html/index.html index 3eee3360..ce2f177b 100644 --- a/tools/esp8266/html/index.html +++ b/tools/esp8266/html/index.html @@ -7,7 +7,6 @@