From dce7b7e64b145f75288763d3246dd4dc5aea5540 Mon Sep 17 00:00:00 2001 From: Gunnar Skjold Date: Thu, 23 Sep 2021 19:28:55 +0200 Subject: [PATCH] Support for long MQTT username and password --- src/AmsConfiguration.cpp | 33 ++++++++++++++++++++++++++++++++- src/AmsConfiguration.h | 22 +++++++++++++++++++--- web/mqtt.html | 10 +++++----- 3 files changed, 56 insertions(+), 9 deletions(-) diff --git a/src/AmsConfiguration.cpp b/src/AmsConfiguration.cpp index 5f5d83b9..03ce2204 100644 --- a/src/AmsConfiguration.cpp +++ b/src/AmsConfiguration.cpp @@ -534,6 +534,17 @@ bool AmsConfiguration::hasConfig() { return false; } break; + case 86: + configVersion = -1; // Prevent loop + if(relocateConfig86()) { + configVersion = EEPROM_CHECK_SUM; + return true; + } else { + configVersion = 0; + return false; + } + break; + break; case EEPROM_CHECK_SUM: return true; default: @@ -552,7 +563,7 @@ void AmsConfiguration::loadTempSensors() { int address = EEPROM_TEMP_CONFIG_ADDRESS; int c = 0; int storedCount = EEPROM.read(address++); - Serial.print("SEnsors: "); + Serial.print("Sensors: "); Serial.println(storedCount); if(storedCount > 0 && storedCount <= 32) { for(int i = 0; i < storedCount; i++) { @@ -792,6 +803,26 @@ bool AmsConfiguration::loadConfig83(int address) { return ret; } +bool AmsConfiguration::relocateConfig86() { + MqttConfig86 mqtt86; + MqttConfig mqtt; + EEPROM.begin(EEPROM_SIZE); + EEPROM.get(CONFIG_MQTT_START_86, mqtt86); + strcpy(mqtt.host, mqtt86.host); + mqtt.port = mqtt86.port; + strcpy(mqtt.clientId, mqtt86.clientId); + strcpy(mqtt.publishTopic, mqtt86.publishTopic); + strcpy(mqtt.subscribeTopic, mqtt86.subscribeTopic); + strcpy(mqtt.username, mqtt86.username); + strcpy(mqtt.password, mqtt86.password); + mqtt.payloadFormat = mqtt86.payloadFormat; + mqtt.ssl = mqtt86.ssl; + EEPROM.put(CONFIG_MQTT_START, mqtt); + bool ret = EEPROM.commit(); + EEPROM.end(); + return ret; +} + bool AmsConfiguration::save() { EEPROM.begin(EEPROM_SIZE); EEPROM.put(EEPROM_CONFIG_ADDRESS, EEPROM_CHECK_SUM); diff --git a/src/AmsConfiguration.h b/src/AmsConfiguration.h index 25178136..b7f4620c 100644 --- a/src/AmsConfiguration.h +++ b/src/AmsConfiguration.h @@ -4,13 +4,12 @@ #include "Arduino.h" #define EEPROM_SIZE 1024 * 3 -#define EEPROM_CHECK_SUM 86 // Used to check if config is stored. Change if structure changes +#define EEPROM_CHECK_SUM 87 // Used to check if config is stored. Change if structure changes #define EEPROM_CONFIG_ADDRESS 0 #define EEPROM_TEMP_CONFIG_ADDRESS 2048 #define CONFIG_SYSTEM_START 8 #define CONFIG_WIFI_START 16 -#define CONFIG_MQTT_START 224 #define CONFIG_WEB_START 648 #define CONFIG_METER_START 784 #define CONFIG_DEBUG_START 824 @@ -18,6 +17,10 @@ #define CONFIG_DOMOTICZ_START 856 #define CONFIG_NTP_START 872 #define CONFIG_ENTSOE_START 944 +#define CONFIG_MQTT_START 1004 + +#define CONFIG_MQTT_START_86 224 + struct SystemConfig { uint8_t boardType; @@ -35,7 +38,7 @@ struct WiFiConfig { bool mdns; }; // 204 -struct MqttConfig { +struct MqttConfig86 { char host[128]; uint16_t port; char clientId[32]; @@ -47,6 +50,18 @@ struct MqttConfig { bool ssl; }; // 420 +struct MqttConfig { + char host[128]; + uint16_t port; + char clientId[32]; + char publishTopic[64]; + char subscribeTopic[64]; + char username[128]; + char password[256]; + uint8_t payloadFormat; + bool ssl; +}; // 676 + struct WebConfig { uint8_t security; char username[64]; @@ -320,6 +335,7 @@ class AmsConfiguration { bool loadConfig82(int address); bool loadConfig83(int address); + bool relocateConfig86(); int readString(int pAddress, char* pString[]); int readInt(int pAddress, int *pValue); diff --git a/web/mqtt.html b/web/mqtt.html index 7762a687..9fefb1d7 100644 --- a/web/mqtt.html +++ b/web/mqtt.html @@ -9,7 +9,7 @@
MQTT
Host
- +
@@ -25,7 +25,7 @@
MQTT
Client ID
- +
@@ -33,7 +33,7 @@
MQTT
Publish topic
- +
@@ -41,7 +41,7 @@
MQTT
Username
- +
@@ -49,7 +49,7 @@
MQTT
Password
- +