From ef3d68d8f04342cd593ef6d9c887bbf5cb77dbf5 Mon Sep 17 00:00:00 2001 From: Bartlomiej Zimon Date: Thu, 11 Jul 2019 17:44:27 +0000 Subject: [PATCH] change length for mqtt username and password fix for #450 Signed-off-by: Bartlomiej Zimon --- esp-link/config.c | 9 ++++++++- esp-link/config.h | 7 ++++--- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/esp-link/config.c b/esp-link/config.c index 7693e7f..e9ad453 100644 --- a/esp-link/config.c +++ b/esp-link/config.c @@ -23,7 +23,7 @@ FlashConfig flashDefault = { .slip_enable = 0, .mqtt_enable = 0, .mqtt_status_enable = 0, .mqtt_timeout = 2, .mqtt_clean_session = 1, .mqtt_port = 1883, .mqtt_keepalive = 60, - .mqtt_old_host = "\0", .mqtt_old_password = "\0", .mqtt_clientid = "\0", + .mqtt_old_host = "\0", .mqtt_old_password = "\0", .mqtt_old_username = "\0", .mqtt_clientid = "\0", .mqtt_username = "\0", .mqtt_password = "\0", .mqtt_status_topic = "\0", .mqtt_host = "\0", .sys_descr = "\0", @@ -161,6 +161,13 @@ bool ICACHE_FLASH_ATTR configRestore(void) { os_memset(flashConfig.mqtt_old_password, 0, 32); } + if (flashConfig.mqtt_username[0] == 0 && flashConfig.mqtt_old_username[0] != 0) { + // the mqtt_username got changed from 32 chars to 64 in a new location + os_printf("Converting old mqtt_username\n"); + os_memcpy(flashConfig.mqtt_password, flashConfig.mqtt_old_username, 32); + os_memset(flashConfig.mqtt_old_username, 0, 32); + } + if (flashConfig.data_bits == 0) { // restore to default 8N1 flashConfig.data_bits = flashDefault.data_bits; diff --git a/esp-link/config.h b/esp-link/config.h index b495dc3..c6a4058 100644 --- a/esp-link/config.h +++ b/esp-link/config.h @@ -23,8 +23,8 @@ typedef struct { uint16_t mqtt_port, mqtt_keepalive; // MQTT Host port, MQTT Keepalive timer char mqtt_old_host[32], // replaced by 64-char mqtt_host below mqtt_clientid[48], - mqtt_username[32], - mqtt_old_password[32], // replaced by 64-char mqtt_password below + mqtt_old_username[32], + mqtt_old_password[32], // replaced by 70-char mqtt_password below mqtt_status_topic[32]; char sys_descr[129]; // system description int8_t rx_pullup; // internal pull-up on RX pin @@ -41,7 +41,8 @@ typedef struct { int8_t data_bits; int8_t parity; int8_t stop_bits; - char mqtt_password[64]; // MQTT password, was 32-char mqtt_old_password + char mqtt_password[70]; // MQTT password, was 32-char mqtt_old_password + char mqtt_username[70]; // MQTT username, was 32-char mqtt_old_username } FlashConfig; extern FlashConfig flashConfig;