mosquitto_connect();

This commit is contained in:
Alexander 2024-03-07 20:22:30 -05:00
parent 136c606653
commit c70d2ad1ff
3 changed files with 19 additions and 18 deletions

View File

@ -2,7 +2,7 @@
//#define RTC //#define RTC
//#define MICRO_SD //#define MICRO_SD
//#define BMP280 // Adafruit BMP280; temp & pressure //#define BMP280 // Adafruit BMP280; temp & pressure
#define BME280 // Generic BME280; temp, pressure & humidity #define BME280 // Generic I2C BME280; temp, pressure & humidity
/* /*
BME-280 BME-280
SCL -> GPIO 22 SCL -> GPIO 22

View File

@ -1,5 +1,6 @@
/* /*
Written for ESP32 development board DEVKIT v1 (Espressive ESP32-WROOM-32) Written for ESP32 development board DEVKIT v1 (Espressive ESP32-WROOM-32).
Modified for ESP32 WROOM U (external anthena).
Node sending temperature and atmosphere pressure readings via MQTT. Node sending temperature and atmosphere pressure readings via MQTT.
@ -19,11 +20,10 @@
#include "secrets.h" #include "secrets.h"
#include "config.h" #include "config.h"
#ifdef BME280 #ifdef BME280 // I2C temperature, pressure and humidity sensor.
#include <Adafruit_BME280.h> #include <Adafruit_BME280.h>
#endif #endif
#ifdef BMP280 #ifdef BMP280 // ISP temperature, pressure and humidity sensor.
#include <Adafruit_BMP280.h> #include <Adafruit_BMP280.h>
#endif #endif
@ -67,8 +67,6 @@ PubSubClient connection(espClientSSL); //mosquitto_ssl
void mosquito_callback (char* topic, byte* message, unsigned int length) void mosquito_callback (char* topic, byte* message, unsigned int length)
{ {
//mosquitto.mosquito_callback(topic, message, length);
// Display topic and message received. // Display topic and message received.
Serial.print("\nMessage arrived on topic: "); Serial.print("\nMessage arrived on topic: ");
Serial.println(topic); Serial.println(topic);
@ -185,6 +183,7 @@ void mosquitto_connect ()
Serial.println(connection.state()); Serial.println(connection.state());
#endif #endif
#ifdef MQTT_SSL // MOSQUITTO MQTT port 8883 #ifdef MQTT_SSL // MOSQUITTO MQTT port 8883
// MQTX MQTT Cloud
Serial.println(":8883"); Serial.println(":8883");
espClientSSL.setCACert(NODE_CERT_CA); espClientSSL.setCACert(NODE_CERT_CA);
connection.setServer(mqtt_server, 8883); connection.setServer(mqtt_server, 8883);
@ -202,7 +201,7 @@ void mosquitto_connect ()
delay(5000); delay(5000);
} }
} }
/* on-premises MQTT /* on-premises Mosquitto MQTT
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);
@ -348,6 +347,8 @@ void setup() {
Serial.print("Connecting to Mosquitto at IP: "); Serial.print("Connecting to Mosquitto at IP: ");
Serial.print(mqtt_server); Serial.print(mqtt_server);
mosquitto_connect();
/**
#ifdef MQTT // MOSQUITTO MQTT port 1883 #ifdef MQTT // MOSQUITTO MQTT port 1883
Serial.println(":1883"); Serial.println(":1883");
connection.setServer(mqtt_server, 1883); connection.setServer(mqtt_server, 1883);

Binary file not shown.