hideakitai/MQTTPubSubClient

Connecting to MQTT broker adds topic with ID and userpw

JoostAB opened this issue · 1 comments

I connect to my MQTT broker (Mosquitto as HomeAssistant add-on) from an M5-Stack fire using
MQTTPubSubClient::connect(const String& client_id, const String& user = "", const String& pass = "");
I pass an ID, username and password. The connection is successful, but also publishes a new topic named after the client_id, and the first seven characters of the password as payload.

My code snippet:

#define SSID_NAME "ssid"
#define SSID_PW "ssid_pw"
#define MQTT_HOST "192.168.0.100"
#define MQTT_PORT 1883
#define MQTT_USER "mqtt_user"
#define MQTT_PW "mqtt_password"

WiFiCLient wifiClient;
MQTTPubSubClient mqttClient;

void setup() {
  WiFi.mode(WIFI_STA);
  WiFi.begin(SSID_NAME, SSID_PW);
  while (!(WiFi.status() == WL_CONNECTED)) {
    delay(200);
  }  

  wifiClient.connect(MQTT_HOST, MQTT_PORT);
  while (!wifiClient.connected()) {   
    delay(200);
  }

  mqttClient.begin(wifiClient);
  mqttClient.setWill("ventcontrol/main/lwt","offline", true);

  mqttClient.connect("Domo_Ventcontrol", MQTT_USER, MQTT_PW);
  while (!mqttClient.isConnected()) {
    delay(200);
  }
}

This results in the following published topic:
Domo_Ventcontrol = mqtt_pa
exposing part of the mqtt-broker password!

I've tested setting Will based on the WiFiMQTT.ino example. I've just added the following code after mqtt.begin()

    mqtt.begin(client);
    mqtt.setWill("ventcontrol/main/lwt","offline", true);  // added

Then, it worked well for me. I think somewhere in your code causes a memory leak.

Image

If you still need help, please reopen this issue with simple, minimal, and reproducible complete code.