From e79524ed8e9be69af9cfc5d83bd327471c224d05 Mon Sep 17 00:00:00 2001 From: Tobias Blum Date: Sun, 5 Nov 2017 01:12:51 +0100 Subject: [PATCH] Fix for empty intopic? https://github.com/toblum/McLighting/issues/52 --- Arduino/McLighting/McLighting.ino | 4 ++-- Arduino/McLighting/definitions.h | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Arduino/McLighting/McLighting.ino b/Arduino/McLighting/McLighting.ino index 6d9deb1..040b800 100644 --- a/Arduino/McLighting/McLighting.ino +++ b/Arduino/McLighting/McLighting.ino @@ -300,8 +300,8 @@ void setup() { // *************************************************************************** #ifdef ENABLE_MQTT if (mqtt_host != "" && String(mqtt_port).toInt() > 0) { - String(String(HOSTNAME) + "/in").toCharArray(mqtt_intopic, strlen(HOSTNAME) + 4); - String(String(HOSTNAME) + "/out").toCharArray(mqtt_outtopic, strlen(HOSTNAME) + 5); + snprintf(mqtt_intopic, sizeof mqtt_intopic, "%s/in", HOSTNAME); + snprintf(mqtt_outtopic, sizeof mqtt_outtopic, "%s/out", HOSTNAME); DBG_OUTPUT_PORT.printf("MQTT active: %s:%d\n", mqtt_host, String(mqtt_port).toInt()); diff --git a/Arduino/McLighting/definitions.h b/Arduino/McLighting/definitions.h index 9bff8fb..bd0ddae 100644 --- a/Arduino/McLighting/definitions.h +++ b/Arduino/McLighting/definitions.h @@ -22,8 +22,8 @@ uint32_t autoParams[][4] = { // color, speed, mode, duration (seconds) int mqtt_reconnect_retries = 0; - char mqtt_intopic[strlen(HOSTNAME) + 3]; // Topic in will be: /in - char mqtt_outtopic[strlen(HOSTNAME) + 4]; // Topic out will be: /out + char mqtt_intopic[strlen(HOSTNAME) + 4]; // Topic in will be: /in + char mqtt_outtopic[strlen(HOSTNAME) + 5]; // Topic out will be: /out const char mqtt_clientid[] = "ESP8266Client"; // MQTT ClientID