mirror of
https://github.com/alexandrebobkov/ESP-Nodes.git
synced 2025-10-03 20:27:04 +00:00
.
This commit is contained in:
@@ -190,7 +190,7 @@ void mosquitto_connect ()
|
|||||||
connection.setServer(mqtt_server, 8883);
|
connection.setServer(mqtt_server, 8883);
|
||||||
connection.setKeepAlive(60);
|
connection.setKeepAlive(60);
|
||||||
while (!connection.connected()) {
|
while (!connection.connected()) {
|
||||||
String client_id = "ESP32-U-" + String(WiFi.macAddress());
|
String client_id = "ESP32-WROOM-" + String(WiFi.macAddress());
|
||||||
Serial.printf("Connecting to MQTT Brocker as %s ... \n", client_id.c_str());
|
Serial.printf("Connecting to MQTT Brocker as %s ... \n", client_id.c_str());
|
||||||
if (connection.connect(client_id.c_str(), mqtt_username, mqtt_password)) {
|
if (connection.connect(client_id.c_str(), mqtt_username, mqtt_password)) {
|
||||||
Serial.println("Connected to MQTT Broker");
|
Serial.println("Connected to MQTT Broker");
|
||||||
@@ -363,12 +363,31 @@ void setup() {
|
|||||||
Serial.println(connection.state());
|
Serial.println(connection.state());
|
||||||
#endif
|
#endif
|
||||||
#ifdef MQTT_SSL // MOSQUITTO MQTT port 8883
|
#ifdef MQTT_SSL // MOSQUITTO MQTT port 8883
|
||||||
|
Serial.println(":8883");
|
||||||
|
espClientSSL.setCACert(NODE_CERT_CA);
|
||||||
|
connection.setServer(mqtt_server, 8883);
|
||||||
|
connection.setKeepAlive(60);
|
||||||
|
while (!connection.connected()) {
|
||||||
|
String client_id = "ESP32-WROOM-" + 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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/**
|
||||||
Serial.println(":8883");
|
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);
|
||||||
//espClientSSL.setPrivateKey(NODE_CERT_PRIVATE);
|
//espClientSSL.setPrivateKey(NODE_CERT_PRIVATE);
|
||||||
//connection.setCallback(mosquito_callback);
|
//connection.setCallback(mosquito_callback);
|
||||||
|
**/
|
||||||
if(connection.connect("esp32")) {
|
if(connection.connect("esp32")) {
|
||||||
Serial.println("Mosquitto Connected!");
|
Serial.println("Mosquitto Connected!");
|
||||||
connection.subscribe("esp32/sw1");
|
connection.subscribe("esp32/sw1");
|
||||||
@@ -430,7 +449,7 @@ void loop() {
|
|||||||
Serial.print(bme.readPressure() / 100.0F);
|
Serial.print(bme.readPressure() / 100.0F);
|
||||||
Serial.println(" hPa");
|
Serial.println(" hPa");
|
||||||
Serial.println("========\n");
|
Serial.println("========\n");
|
||||||
delay(2500);
|
delay(5000);
|
||||||
connection.loop();
|
connection.loop();
|
||||||
|
|
||||||
// Blink status LED when status is OK
|
// Blink status LED when status is OK
|
||||||
|
Reference in New Issue
Block a user