From dc4fabc7ed759db318dd56f0191907c53cac3c31 Mon Sep 17 00:00:00 2001 From: Thorsten von Eicken Date: Sun, 19 Jun 2016 12:47:01 -0700 Subject: [PATCH] Change MQTT hostname to 64 chars, fixes #147 --- esp-link/config.c | 15 ++++++++++++--- esp-link/config.h | 11 ++++++----- esp-link/main.c | 4 ++++ mqtt/mqtt.c | 2 +- 4 files changed, 23 insertions(+), 9 deletions(-) diff --git a/esp-link/config.c b/esp-link/config.c index 026d139..1af160a 100644 --- a/esp-link/config.c +++ b/esp-link/config.c @@ -24,8 +24,9 @@ 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_host = "\0", .mqtt_clientid = "\0", - .mqtt_username= "\0", .mqtt_password = "\0", .mqtt_status_topic = "\0", + .mqtt_old_host = "\0", .mqtt_clientid = "\0", + .mqtt_username = "\0", .mqtt_password = "\0", .mqtt_status_topic = "\0", + .mqtt_host = "\0", .sys_descr = "\0", .rx_pullup = 1, .sntp_server = "us.pool.ntp.org\0", @@ -141,8 +142,16 @@ bool ICACHE_FLASH_ATTR configRestore(void) { flash_pri = 0; return false; } - // copy good one into global var and return + // copy good one into global var os_memcpy(&flashConfig, flash_pri == 0 ? &ff0.fc : &ff1.fc, sizeof(FlashConfig)); + // convert old config + if (flashConfig.mqtt_host[0] == 0 && flashConfig.mqtt_old_host[0] != 0) { + // the mqtt_host got changed from 32 chars to 64 in a new location + os_printf("Converting old mqtt_host\n"); + os_memcpy(flashConfig.mqtt_host, flashConfig.mqtt_old_host, 32); + os_memset(flashConfig.mqtt_old_host, 0, 32); + } else os_printf("mqtt_host is '%s'\n", flashConfig.mqtt_host); + return true; } diff --git a/esp-link/config.h b/esp-link/config.h index c3da742..341d7e1 100644 --- a/esp-link/config.h +++ b/esp-link/config.h @@ -21,7 +21,7 @@ typedef struct { mqtt_timeout, // MQTT send timeout mqtt_clean_session; // MQTT clean session uint16_t mqtt_port, mqtt_keepalive; // MQTT Host port, MQTT Keepalive timer - char mqtt_host[32], + char mqtt_old_host[32], // replaced by 64-char mqtt_host below mqtt_clientid[48], mqtt_username[32], mqtt_password[32], @@ -30,13 +30,14 @@ typedef struct { int8_t rx_pullup; // internal pull-up on RX pin char sntp_server[32]; char syslog_host[32]; - uint16_t syslog_minheap; // min. heap to allow queuing - uint8_t syslog_filter, // min. severity - syslog_showtick, // show system tick (µs) - syslog_showdate; // populate SYSLOG date field + uint16_t syslog_minheap; // min. heap to allow queuing + uint8_t syslog_filter, // min. severity + syslog_showtick, // show system tick (µs) + syslog_showdate; // populate SYSLOG date field uint8_t mdns_enable; char mdns_servername[32]; int8_t timezone_offset; + char mqtt_host[64]; // MQTT host we connect to, was 32-char mqtt_old_host } FlashConfig; extern FlashConfig flashConfig; diff --git a/esp-link/main.c b/esp-link/main.c index ba2cf8d..5994e65 100644 --- a/esp-link/main.c +++ b/esp-link/main.c @@ -116,6 +116,10 @@ void user_rf_pre_init(void) { // Main routine to initialize esp-link. void user_init(void) { + // uncomment the following three lines to see flash config messages for troubleshooting + //uart_init(115200, 115200); + //logInit(); + //os_delay_us(100000L); // get the flash config so we know how to init things //configWipe(); // uncomment to reset the config for testing purposes bool restoreOk = configRestore(); diff --git a/mqtt/mqtt.c b/mqtt/mqtt.c index bf785f6..74710bc 100644 --- a/mqtt/mqtt.c +++ b/mqtt/mqtt.c @@ -629,7 +629,7 @@ void ICACHE_FLASH_ATTR MQTT_Init(MQTT_Client* client, char* host, uint32 port, uint8_t security, uint8_t sendTimeout, char* client_id, char* client_user, char* client_pass, uint8_t keepAliveTime) { - DBG_MQTT("MQTT_Init\n"); + DBG_MQTT("MQTT_Init, host=%s\n", host); os_memset(client, 0, sizeof(MQTT_Client));