Support for long MQTT username and password

This commit is contained in:
Gunnar Skjold
2021-09-23 19:28:55 +02:00
parent 7627d6c369
commit dce7b7e64b
3 changed files with 56 additions and 9 deletions

View File

@@ -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);

View File

@@ -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 @@ private:
bool loadConfig82(int address);
bool loadConfig83(int address);
bool relocateConfig86();
int readString(int pAddress, char* pString[]);
int readInt(int pAddress, int *pValue);