Actually use username and password when connecting to MQTT broker (see #2)

This commit is contained in:
Erik Borowski
2024-11-30 22:19:25 +01:00
parent 0071af40a6
commit a0b246aae1
2 changed files with 3 additions and 1 deletions

View File

@ -31,9 +31,11 @@
#define MQTT_PORT 1883
// The user to use to connect to the MQTT broker.
// Set this to NULL if no user is required.
#define MQTT_USER "<Your User>"
// The password to use to connect to the MQTT broker.
// Set this to NULL if no password is required.
#define MQTT_PASSWORD "<Your Password>"
// The root topic used for communicating with this controller.

View File

@ -111,7 +111,7 @@ void MQTT::setupMqtt()
{
Serial.println("[MQTT] Connecting to MQTT broker...");
uint retries = 0;
if (this->client->connect(this->clientId.c_str(), String(this->mqttRootTopic + "/" + this->clientId + "/availability").c_str(), 1, true, "offline"))
if (this->client->connect(this->clientId.c_str(), this->mqttUser, this->mqttPassword, String(this->mqttRootTopic + "/" + this->clientId + "/availability").c_str(), 1, true, "offline"))
{
Serial.println("[MQTT] connected!");
this->client->publish(String(this->mqttRootTopic + "/" + this->clientId + "/availability").c_str(), "online", true);