From 4c3852cde41e3cd43110808390d5e40158763c3b Mon Sep 17 00:00:00 2001
From: lumapu
Date: Tue, 3 May 2022 23:29:33 +0200
Subject: [PATCH] * fixed erase settings * fixed behavior if no MQTT IP is set
(the system was nearly unusable because of delayed responses) * fixed Station
/ AP WiFi on startup -> more information will be printed to the serial
console * added new ticker for serial value dump
---
tools/esp8266/app.cpp | 54 ++++++++++++++++++++-----------
tools/esp8266/app.h | 3 ++
tools/esp8266/defines.h | 2 +-
tools/esp8266/html/h/index_html.h | 2 +-
tools/esp8266/html/h/setup_html.h | 2 +-
tools/esp8266/html/index.html | 2 +-
tools/esp8266/html/setup.html | 10 +++---
tools/esp8266/main.cpp | 33 ++++++++++++++-----
tools/esp8266/main.h | 12 ++++---
9 files changed, 81 insertions(+), 39 deletions(-)
diff --git a/tools/esp8266/app.cpp b/tools/esp8266/app.cpp
index 53b7a93f..b3fb0e2e 100644
--- a/tools/esp8266/app.cpp
+++ b/tools/esp8266/app.cpp
@@ -7,10 +7,13 @@
//-----------------------------------------------------------------------------
app::app() : Main() {
- mSendTicker = 0xffffffff;
- mSendInterval = 0;
- mMqttTicker = 0xffffffff;
- mMqttInterval = 0;
+ mSendTicker = 0xffffffff;
+ mSendInterval = 0;
+ mMqttTicker = 0xffffffff;
+ mMqttInterval = 0;
+ mSerialTicker = 0xffffffff;
+ mSerialInterval = 0;
+ mMqttActive = false;
mShowRebootRequest = false;
@@ -86,12 +89,17 @@ void app::setup(const char *ssid, const char *pwd, uint32_t timeout) {
char addr[16] = {0};
sprintf(addr, "%d.%d.%d.%d", mqttAddr[0], mqttAddr[1], mqttAddr[2], mqttAddr[3]);
+ mMqttActive = (mqttAddr[0] > 0);
+
if(mMqttInterval < 1000)
mMqttInterval = 1000;
mMqtt.setup(addr, mqttTopic, mqttUser, mqttPwd, mqttPort);
mMqttTicker = 0;
+ mSerialTicker = 0;
+ mSerialInterval = mMqttInterval; // TODO: add extra setting for this!
+
mMqtt.sendMsg("version", mVersion);
}
@@ -166,25 +174,31 @@ void app::loop(void) {
// mqtt
- mMqtt.loop();
- if(checkTicker(&mMqttTicker, mMqttInterval)) {
- mMqtt.isConnected(true);
- char topic[30], val[10];
- for(uint8_t id = 0; id < mSys->getNumInverters(); id++) {
- Inverter<> *iv = mSys->getInverterByPos(id);
- if(NULL != iv) {
- for(uint8_t i = 0; i < iv->listLen; i++) {
- if(0.0f != iv->getValue(i)) {
- snprintf(topic, 30, "%s/ch%d/%s", iv->name, iv->assign[i].ch, fields[iv->assign[i].fieldId]);
- snprintf(val, 10, "%.3f", iv->getValue(i));
- mMqtt.sendMsg(topic, val);
- yield();
+ if(mMqttActive) {
+ mMqtt.loop();
+ if(checkTicker(&mMqttTicker, mMqttInterval)) {
+ mMqtt.isConnected(true);
+ char topic[30], val[10];
+ for(uint8_t id = 0; id < mSys->getNumInverters(); id++) {
+ Inverter<> *iv = mSys->getInverterByPos(id);
+ if(NULL != iv) {
+ for(uint8_t i = 0; i < iv->listLen; i++) {
+ if(0.0f != iv->getValue(i)) {
+ snprintf(topic, 30, "%s/ch%d/%s", iv->name, iv->assign[i].ch, fields[iv->assign[i].fieldId]);
+ snprintf(val, 10, "%.3f", iv->getValue(i));
+ mMqtt.sendMsg(topic, val);
+ yield();
+ }
}
}
}
}
+ }
- // Serial debug
+
+ // Serial debug
+ if(checkTicker(&mSerialTicker, mSerialInterval)) {
+ char topic[30], val[10];
for(uint8_t id = 0; id < mSys->getNumInverters(); id++) {
Inverter<> *iv = mSys->getInverterByPos(id);
if(NULL != iv) {
@@ -230,6 +244,10 @@ void app::showSetup(void) {
html.replace("{DEVICE}", String(mDeviceName));
html.replace("{VERSION}", String(mVersion));
+ if(mApActive)
+ html.replace("{IP}", String("http://192.168.1.1"));
+ else
+ html.replace("{IP}", ("http://" + String(WiFi.localIP().toString())));
String inv;
uint64_t invSerial;
diff --git a/tools/esp8266/app.h b/tools/esp8266/app.h
index 64207d3d..df5074ab 100644
--- a/tools/esp8266/app.h
+++ b/tools/esp8266/app.h
@@ -81,6 +81,9 @@ class app : public Main {
mqtt mMqtt;
uint32_t mMqttTicker;
uint16_t mMqttInterval;
+ bool mMqttActive;
+ uint32_t mSerialTicker;
+ uint16_t mSerialInterval;
};
#endif /*__APP_H__*/
diff --git a/tools/esp8266/defines.h b/tools/esp8266/defines.h
index 98ba2539..131e7742 100644
--- a/tools/esp8266/defines.h
+++ b/tools/esp8266/defines.h
@@ -16,7 +16,7 @@
//-------------------------------------
#define VERSION_MAJOR 0
#define VERSION_MINOR 3
-#define VERSION_PATCH 4
+#define VERSION_PATCH 5
//-------------------------------------
diff --git a/tools/esp8266/html/h/index_html.h b/tools/esp8266/html/h/index_html.h
index 67dc9144..6705332a 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}
Visualization
Setup
Uptime:
Time:
Statistics:
";
+const char index_html[] PROGMEM = "Index - {DEVICE}AHOY - {DEVICE}
Visualization
Setup
Uptime:
Time:
Statistics:
";
#endif /*__INDEX_H__*/
diff --git a/tools/esp8266/html/h/setup_html.h b/tools/esp8266/html/h/setup_html.h
index 1b01ff97..49ef4896 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.
";
+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.
";
#endif /*__SETUP_H__*/
diff --git a/tools/esp8266/html/index.html b/tools/esp8266/html/index.html
index ce2f177b..541caeb1 100644
--- a/tools/esp8266/html/index.html
+++ b/tools/esp8266/html/index.html
@@ -39,7 +39,7 @@
Statistics:
- This project was started from
this (Mikrocontroller.net) discussion.
+ This project was started from
this discussion. (Mikrocontroller.net)
New updates can be found on Github:
https://github.com/grindylow/ahoy
Please report issues using the feature provided by Github.
diff --git a/tools/esp8266/html/setup.html b/tools/esp8266/html/setup.html
index fa0af415..baa84dab 100644
--- a/tools/esp8266/html/setup.html
+++ b/tools/esp8266/html/setup.html
@@ -12,7 +12,7 @@
Enter the credentials to your prefered WiFi station. After rebooting the device tries to connect with this information.
-