diff --git a/include/mqttclient.h b/include/mqttclient.h index 6e351e2a..5e595cca 100644 --- a/include/mqttclient.h +++ b/include/mqttclient.h @@ -17,7 +17,7 @@ #define MQTT_KEEPALIVE 10 // keep alive interval in seconds #ifndef MQTT_CLIENTNAME -#define MQTT_CLIENTNAME clientId.c_str() +#define MQTT_CLIENTNAME clientId #endif extern TaskHandle_t mqttTask; diff --git a/src/mqttclient.cpp b/src/mqttclient.cpp index 8e1d5aec..6dd5a89a 100644 --- a/src/mqttclient.cpp +++ b/src/mqttclient.cpp @@ -41,7 +41,10 @@ esp_err_t mqtt_init(void) { int mqtt_connect(const char *my_host, const uint16_t my_port) { IPAddress mqtt_server_ip; - static String clientId = "paxcounter-" + ETH.macAddress(); + const uint16_t hashed = hash(Ð.macAddress()[0], 4); // hash MAC to 4 digits + char clientId[16]; + snprintf(clientId, 16, "paxcounter_%d", hashed); + ESP_LOGI(TAG, "MQTT name is %s", MQTT_CLIENTNAME); // resolve server host name