Added: Auth

This commit is contained in:
TheJoKlLa 2022-11-09 18:14:57 +01:00
parent 088eb55aa5
commit 006b1dc034
2 changed files with 15 additions and 2 deletions

View File

@ -1,6 +1,8 @@
#define WLAN_SSID "" #define WLAN_SSID ""
#define WLAN_PASS "" #define WLAN_PASS ""
#define MQTT_BROKER "" #define MQTT_BROKER ""
#define MQTT_USERNAME ""
#define MQTT_PASSWORD ""
#define FABLOCKID 1 #define FABLOCKID 1
#define MPC_RELAIS_ADDR 0x20 #define MPC_RELAIS_ADDR 0x20
#define HAS_FEEDBACK 1 #define HAS_FEEDBACK 1

View File

@ -86,8 +86,19 @@ void reconnect()
Serial.println("Connecting MQTT ..."); Serial.println("Connecting MQTT ...");
String clientId = "FABLOCK-"; String clientId = "FABLOCK-";
clientId += String(random(0xffff), HEX); clientId += String(random(0xffff), HEX);
if (client.connect(clientId.c_str()))
{ bool connected = false;
if(MQTT_USERNAME == "")
{
connected = client.connect(clientId.c_str());
}
else
{
connected = client.connect(clientId.c_str(), MQTT_USERNAME, MQTT_PASSWORD);
}
if (connected)
{
snprintf (topic_recv, TOPIC_BUFFER_SIZE, "fablock/%03d/+/trigger", FABLOCKID); snprintf (topic_recv, TOPIC_BUFFER_SIZE, "fablock/%03d/+/trigger", FABLOCKID);
client.subscribe(topic_recv); client.subscribe(topic_recv);
snprintf (topic_recv, TOPIC_BUFFER_SIZE, "fablock/%03d/+/set_state", FABLOCKID); snprintf (topic_recv, TOPIC_BUFFER_SIZE, "fablock/%03d/+/set_state", FABLOCKID);