mirror of
https://github.com/alexandrebobkov/ESP-Nodes.git
synced 2025-08-08 13:10:52 +00:00
MQTX
This commit is contained in:
@@ -186,6 +186,24 @@ void mosquitto_connect ()
|
|||||||
#endif
|
#endif
|
||||||
#ifdef MQTT_SSL // MOSQUITTO MQTT port 8883
|
#ifdef MQTT_SSL // MOSQUITTO MQTT port 8883
|
||||||
Serial.println(":8883");
|
Serial.println(":8883");
|
||||||
|
espClientSSL.setCACert(NODE_CERT_CA);
|
||||||
|
connection.setServer(mqtt_server, 8883);
|
||||||
|
connection.setKeepAlive(60);
|
||||||
|
while (!connection.connected()) {
|
||||||
|
String client_id = "ESP32-U-" + String(WiFi.macAddress());
|
||||||
|
Serial.printf("Connecting to MQTT Brocker as %s ... \n", client_id.c_str());
|
||||||
|
if (connection.connect(client_id.c_str(), mqtt_username, mqtt_password)) {
|
||||||
|
Serial.println("Connected to MQTT Broker");
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
Serial.print("Failed to connect, rc=");
|
||||||
|
Serial.print(connection.state());
|
||||||
|
Serial.println(" Retrying in 5 seconds.");
|
||||||
|
delay(5000);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/* on-premises MQTT
|
||||||
|
Serial.println(":8883");
|
||||||
connection.setServer(mqtt_server, 8883);
|
connection.setServer(mqtt_server, 8883);
|
||||||
espClientSSL.setCACert(NODE_CERT_CA);
|
espClientSSL.setCACert(NODE_CERT_CA);
|
||||||
espClientSSL.setCertificate(NODE_CERT_CRT);
|
espClientSSL.setCertificate(NODE_CERT_CRT);
|
||||||
@@ -200,7 +218,7 @@ void mosquitto_connect ()
|
|||||||
connection.subscribe(MQTT_IOT_CHANNEL_OUTPUT_PWM_1);
|
connection.subscribe(MQTT_IOT_CHANNEL_OUTPUT_PWM_1);
|
||||||
}
|
}
|
||||||
Serial.print("Mosquitto state: ");
|
Serial.print("Mosquitto state: ");
|
||||||
Serial.println(connection.state());
|
Serial.println(connection.state());*/
|
||||||
#endif
|
#endif
|
||||||
delay(2000);
|
delay(2000);
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user