Browse Source

Merge pull request #98 from stefan123t/main

fix #88 and #93, clean up #63
MQTT was tested using IP address
pull/102/head
lumapu 3 years ago
committed by GitHub
parent
commit
10771d8f5b
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 40
      tools/esp8266/README.md
  2. 43
      tools/esp8266/app.cpp
  3. 16
      tools/esp8266/config.h
  4. 10
      tools/esp8266/defines.h

40
tools/esp8266/README.md

@ -69,3 +69,43 @@ For now the following inverters should work out of the box:
- `RF24` 1.4.2
- `PubSubClient` 2.8
- `ArduinoJson` 6.19.4
## Changelog
(*) EEPROM changes require settings to be changed, your settings will be overwritten and need to be set again!
- v0.4.24 added fixes for #63, #88, #93. revert #36 (*) EEPROM changes
- v0.4.23 added workflow, fix index.html to load inverter info immediately, changed timestamp to 1 for stand alone ESP #90, Implement MQTT discovery for Home Assistant
- v0.4.22 compiles with PlatformIO
- v0.4.21 reduced warnings
- v0.4.20 improved setup (if no data is in EEprom), improved NRF24 Pinout regarding to #36, Standard Pinout should be now: #36 (comment), add JSON output, fix favicon, improve eeprom default settings (*) EEPROM changes
- v0.4.19 updated debug messages: now 5 different levels are available, fixed CRC loop issue, add fritzing/schematics for Arduino, Raspberry Pi and NodeMCU
- v0.4.18 Creative Commons NC-SA-BY v3.0 license included, tried to increase stability, fix NRF24 CRClength, add debug & documentation links, added variable error messages using #pragma error
- v0.4.17 add printed circuit board layout, more debug output (#retransmits), improved loop counters (*) EEPROM changes
- v0.4.16 request only one inverter per loop (#53 (comment)), mqtt loop interval calculated by # of inverters and inverter request interval, limit maximum number of retries, added feature request #62 (readable names for channels), improved setup page, added javascript to hide / show channel fields (*) EEPROM changes
- v0.4.15 reduced debug messages, fixes after merge
- v0.4.14 added RX channel 40, improved RF24 ISR, reduced AP active time to 60s (will be increase once a client is connected), added `yield` without success -> random reboot (cause 4) (*) EEPROM changes
- v0.4.13 rename to AHOY-DTU, add RX channel 40, update stats on index based on mSendInterval, MQTT Interval, EEPROM CRC settings, fix #56 v0.4.10 ESP8266 stuck in boot loop
- v0.4.12 version skipped ?
- v0.4.11 inverter dependent mqtt (is avail), implemented heap stats #58, inserted 'break' in ISR while loop
- v0.4.10 reduced heap size (>50%) by using 'F()' for (nearly) all static strings, added Wemos D1 case STL files
- v0.4.9 try to fix mqtt and wifi loss issue #52, document libraries (*) EEPROM changes
- v0.4.8 moved mqtt loop out of checkTicker as mentioned in #49, added irritation and efficiency calculations, improved style (*) EEPROM changes
- v0.4.7 version skipped ?
- v0.4.6 version skipped ?
- v0.4.5 fix #38 4-channel inverter current assignment, added last received timestamp in /hoymiles livedata web page #47, improved style.css, improved NTP as described in #46
- v0.4.4 added free heap, mentioned in #24 (added in serial print, status on index and mqtt), fixed #45, AC current by factor 10 too high, fixed failed payload counter
- v0.4.3 fixed #41 HM800 Yield total and Yield day were mixed around. Found issue while comparing to Python version, fixed #43 HM350 channel 2 is displayed in Live-View, added #42 YieldTotal and YieldTotal Day for HM600 - HM800 inverters
- v0.4.2 fix #39 Assignment 2-Channel inverters (HM-600, HM-700, HM-800)
- v0.4.1 multi inverter support, full re transmit included
- v0.4.0 complete payload processed (and crc checked), inverter type is defined by serial number, serial debug can be switched live (using setup), Note: only one inverter is supported for now!
- v0.3.9 fix #26 ticker / interval in app.cpp
- v0.3.8 improved stability (in comparison to 0.3.7), reset wifi AP timout once a client is detected, fix #26 wrong variable reset
- v0.3.7 added rx channel switching, switched to crc8 check for valid packet-payload
- v0.3.6 improved tickers, only one ticker is active, added feature to use the ESP as access point for all the time, added serial features to setup
- v0.3.5 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
- v0.3.4 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)
- v0.3.3 converted to "poor-man-ticker" using millis() for uptime, send and mqtt, added inverter overview, added send count to statistics
- v0.3.2 compile of merge, binary published on https://www.mikrocontroller.net/topic/525778?goto=7051413#7051413
- v0.3.1 fix: doCalculations was not called
- v0.3.0 version 0.3.0, added unit test

43
tools/esp8266/app.cpp

@ -15,11 +15,11 @@
app::app() : Main() {
DPRINTLN(DBG_VERBOSE, F("app::app():Main"));
mSendTicker = 0xffff;
mSendInterval = 0;
mSendInterval = MIN_SEND_INTERVAL;
mMqttTicker = 0xffff;
mMqttInterval = 0;
mMqttInterval = MIN_MQTT_INTERVAL;
mSerialTicker = 0xffff;
mSerialInterval = 0;
mSerialInterval = MIN_SERIAL_INTERVAL;
mMqttActive = false;
mTicker = 0;
@ -65,8 +65,8 @@ void app::setup(uint32_t timeout) {
if(mSettingsValid) {
mEep->read(ADDR_INV_INTERVAL, &mSendInterval);
if(mSendInterval < 5)
mSendInterval = 5;
if(mSendInterval < MIN_SEND_INTERVAL)
mSendInterval = MIN_SEND_INTERVAL;
mSendTicker = mSendInterval;
// inverter
@ -114,17 +114,17 @@ void app::setup(uint32_t timeout) {
// serial console
uint8_t tmp;
mEep->read(ADDR_SER_INTERVAL, &mSerialInterval);
if(mSerialInterval < MIN_SERIAL_INTERVAL)
mSerialInterval = MIN_SERIAL_INTERVAL;
mEep->read(ADDR_SER_ENABLE, &tmp);
mSerialValues = (tmp == 0x01);
mEep->read(ADDR_SER_DEBUG, &tmp);
mSerialDebug = (tmp == 0x01);
if(mSerialInterval < 1)
mSerialInterval = 1;
mSys->Radio.mSerialDebug = mSerialDebug;
// mqtt
uint8_t mqttAddr[MQTT_ADDR_LEN];
char mqttAddr[MQTT_ADDR_LEN];
uint16_t mqttPort;
char mqttUser[MQTT_USER_LEN];
char mqttPwd[MQTT_PWD_LEN];
@ -136,13 +136,10 @@ void app::setup(uint32_t timeout) {
//mEep->read(ADDR_MQTT_INTERVAL, &mMqttInterval);
mEep->read(ADDR_MQTT_PORT, &mqttPort);
char addr[16] = {0};
sprintf(addr, "%d.%d.%d.%d", mqttAddr[0], mqttAddr[1], mqttAddr[2], mqttAddr[3]);
if(mqttAddr[0] > 0) {
mMqttActive = true;
if(mMqttInterval < 1)
mMqttInterval = 10;
if(mMqttInterval < MIN_MQTT_INTERVAL)
mMqttInterval = MIN_MQTT_INTERVAL;
}
else
mMqttInterval = 0xffff;
@ -150,8 +147,7 @@ void app::setup(uint32_t timeout) {
if(0 == mqttPort)
mqttPort = 1883;
mMqtt.setup(addr, mqttTopic, mqttUser, mqttPwd, mqttPort);
mMqtt.setup(mqttAddr, mqttTopic, mqttUser, mqttPwd, mqttPort);
mMqttTicker = 0;
mSerialTicker = 0;
@ -573,14 +569,12 @@ void app::showSetup(void) {
mEep->read(ADDR_SER_DEBUG, &tmp);
html.replace(F("{SER_DBG_CB}"), (tmp == 0x01) ? "checked" : "");
uint8_t mqttAddr[MQTT_ADDR_LEN] = {0};
char mqttAddr[MQTT_ADDR_LEN] = {0};
uint16_t mqttPort;
mEep->read(ADDR_MQTT_ADDR, mqttAddr, MQTT_ADDR_LEN);
mEep->read(ADDR_MQTT_PORT, &mqttPort);
char addr[16] = {0};
sprintf(addr, "%d.%d.%d.%d", mqttAddr[0], mqttAddr[1], mqttAddr[2], mqttAddr[3]);
html.replace(F("{MQTT_ADDR}"), String(addr));
html.replace(F("{MQTT_ADDR}"), String(mqttAddr));
html.replace(F("{MQTT_PORT}"), String(mMqtt.getPort()));
html.replace(F("{MQTT_USER}"), String(mMqtt.getUser()));
html.replace(F("{MQTT_PWD}"), String(mMqtt.getPwd()));
@ -788,7 +782,6 @@ void app::saveValues(bool webSend = true) {
Main::saveValues(false); // general configuration
if(mWeb->args() > 0) {
char *p;
char buf[20] = {0};
uint8_t i = 0;
uint16_t interval;
@ -835,18 +828,12 @@ void app::saveValues(bool webSend = true) {
mEep->write(ADDR_RF24_AMP_PWR, mSys->Radio.AmplifierPower);
// mqtt
uint8_t mqttAddr[MQTT_ADDR_LEN] = {0};
char mqttAddr[MQTT_ADDR_LEN] = {0};
uint16_t mqttPort;
char mqttUser[MQTT_USER_LEN];
char mqttPwd[MQTT_PWD_LEN];
char mqttTopic[MQTT_TOPIC_LEN];
mWeb->arg("mqttAddr").toCharArray(buf, 20);
i = 0;
p = strtok(buf, ".");
while(NULL != p) {
mqttAddr[i++] = atoi(p);
p = strtok(NULL, ".");
}
mWeb->arg("mqttAddr").toCharArray(mqttAddr, MQTT_ADDR_LEN);
mWeb->arg("mqttUser").toCharArray(mqttUser, MQTT_USER_LEN);
mWeb->arg("mqttPwd").toCharArray(mqttPwd, MQTT_PWD_LEN);
mWeb->arg("mqttTopic").toCharArray(mqttTopic, MQTT_TOPIC_LEN);

16
tools/esp8266/config.h

@ -37,6 +37,15 @@
// number of configurable inverters
#define MAX_NUM_INVERTERS 3
// minimum serial interval
#define MIN_SERIAL_INTERVAL 5
// minimum send interval
#define MIN_SEND_INTERVAL 30
// minimum mqtt interval
#define MIN_MQTT_INTERVAL 60
// maximum human readable inverter name length
#define MAX_NAME_LENGTH 16
@ -58,11 +67,4 @@
// changes the style of "/setup" page, visualized = nicer
#define LIVEDATA_VISUALIZED
// comment out to disable any of the debug options here
#define DEBUG_APP
#define DEBUG_HMINVERTER
#define DEBUG_HMRADIO
#define DEBUG_HMSYSTEM
#define DEBUG_HMMAIN
#endif /*__CONFIG_H__*/

10
tools/esp8266/defines.h

@ -12,8 +12,8 @@
// PINOUT (Default, can be changed in setup)
//-------------------------------------
#define RF24_CS_PIN 15
#define RF24_CE_PIN 0
#define RF24_IRQ_PIN 2
#define RF24_CE_PIN 2
#define RF24_IRQ_PIN 0
//-------------------------------------
@ -21,7 +21,7 @@
//-------------------------------------
#define VERSION_MAJOR 0
#define VERSION_MINOR 4
#define VERSION_PATCH 23
#define VERSION_PATCH 24
//-------------------------------------
@ -35,7 +35,7 @@ typedef struct {
// EEPROM
//-------------------------------------
#define SSID_LEN 32
#define PWD_LEN 63
#define PWD_LEN 64
#define DEVNAME_LEN 16
#define CRC_LEN 2 // uint16_t
@ -50,7 +50,7 @@ typedef struct {
#define RF24_AMP_PWR_LEN 1
#define MQTT_ADDR_LEN 4 // IP
#define MQTT_ADDR_LEN 32 // DNS Name
#define MQTT_USER_LEN 16
#define MQTT_PWD_LEN 32
#define MQTT_TOPIC_LEN 32

Loading…
Cancel
Save