Change MQTT hostname to 64 chars, fixes #147

pull/163/head
Thorsten von Eicken 9 years ago
parent 6ccca3ef9c
commit dc4fabc7ed
  1. 13
      esp-link/config.c
  2. 3
      esp-link/config.h
  3. 4
      esp-link/main.c
  4. 2
      mqtt/mqtt.c

@ -24,8 +24,9 @@ FlashConfig flashDefault = {
.slip_enable = 0, .mqtt_enable = 0, .mqtt_status_enable = 0, .slip_enable = 0, .mqtt_enable = 0, .mqtt_status_enable = 0,
.mqtt_timeout = 2, .mqtt_clean_session = 1, .mqtt_timeout = 2, .mqtt_clean_session = 1,
.mqtt_port = 1883, .mqtt_keepalive = 60, .mqtt_port = 1883, .mqtt_keepalive = 60,
.mqtt_host = "\0", .mqtt_clientid = "\0", .mqtt_old_host = "\0", .mqtt_clientid = "\0",
.mqtt_username = "\0", .mqtt_password = "\0", .mqtt_status_topic = "\0", .mqtt_username = "\0", .mqtt_password = "\0", .mqtt_status_topic = "\0",
.mqtt_host = "\0",
.sys_descr = "\0", .sys_descr = "\0",
.rx_pullup = 1, .rx_pullup = 1,
.sntp_server = "us.pool.ntp.org\0", .sntp_server = "us.pool.ntp.org\0",
@ -141,8 +142,16 @@ bool ICACHE_FLASH_ATTR configRestore(void) {
flash_pri = 0; flash_pri = 0;
return false; 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)); 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; return true;
} }

@ -21,7 +21,7 @@ typedef struct {
mqtt_timeout, // MQTT send timeout mqtt_timeout, // MQTT send timeout
mqtt_clean_session; // MQTT clean session mqtt_clean_session; // MQTT clean session
uint16_t mqtt_port, mqtt_keepalive; // MQTT Host port, MQTT Keepalive timer 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_clientid[48],
mqtt_username[32], mqtt_username[32],
mqtt_password[32], mqtt_password[32],
@ -37,6 +37,7 @@ typedef struct {
uint8_t mdns_enable; uint8_t mdns_enable;
char mdns_servername[32]; char mdns_servername[32];
int8_t timezone_offset; int8_t timezone_offset;
char mqtt_host[64]; // MQTT host we connect to, was 32-char mqtt_old_host
} FlashConfig; } FlashConfig;
extern FlashConfig flashConfig; extern FlashConfig flashConfig;

@ -116,6 +116,10 @@ void user_rf_pre_init(void) {
// Main routine to initialize esp-link. // Main routine to initialize esp-link.
void user_init(void) { 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 // get the flash config so we know how to init things
//configWipe(); // uncomment to reset the config for testing purposes //configWipe(); // uncomment to reset the config for testing purposes
bool restoreOk = configRestore(); bool restoreOk = configRestore();

@ -629,7 +629,7 @@ void ICACHE_FLASH_ATTR
MQTT_Init(MQTT_Client* client, char* host, uint32 port, uint8_t security, uint8_t sendTimeout, MQTT_Init(MQTT_Client* client, char* host, uint32 port, uint8_t security, uint8_t sendTimeout,
char* client_id, char* client_user, char* client_pass, char* client_id, char* client_user, char* client_pass,
uint8_t keepAliveTime) { uint8_t keepAliveTime) {
DBG_MQTT("MQTT_Init\n"); DBG_MQTT("MQTT_Init, host=%s\n", host);
os_memset(client, 0, sizeof(MQTT_Client)); os_memset(client, 0, sizeof(MQTT_Client));

Loading…
Cancel
Save