mirror of
https://github.com/alexandrebobkov/ESP-Nodes.git
synced 2024-10-05 20:47:50 -04:00
mosquitto_connect();
This commit is contained in:
parent
136c606653
commit
c70d2ad1ff
@ -1,8 +1,8 @@
|
||||
// Uncomment modules as required
|
||||
//#define RTC
|
||||
//#define MICRO_SD
|
||||
//#define BMP280 // Adafruit BMP280; temp & pressure
|
||||
#define BME280 // Generic BME280; temp, pressure & humidity
|
||||
//#define BMP280 // Adafruit BMP280; temp & pressure
|
||||
#define BME280 // Generic I2C BME280; temp, pressure & humidity
|
||||
/*
|
||||
BME-280
|
||||
SCL -> GPIO 22
|
||||
@ -29,14 +29,14 @@
|
||||
// MQTT Channel specific for each node
|
||||
// [NODE]/sensors/sensor
|
||||
// IoT ID
|
||||
#define IoT_ID "node1"
|
||||
#define MQTT_NODE_TEMPERATURE "/sensors/temperature"
|
||||
#define MQTT_NODE_PRESSURE "/sensors/pressure"
|
||||
#define MQTT_NODE_HUMIDITY "/sensors/humidity"
|
||||
#define MQTT_NODE_PULSE "/pulse"
|
||||
#define MQTT_NODE_SWITCH_1 "/sw1"
|
||||
#define MQTT_NODE_SWITCH_2 "/sw2"
|
||||
#define MQTT_NODE_OUTPUT_PWM_1 "/pwm1"
|
||||
#define IoT_ID "node1"
|
||||
#define MQTT_NODE_TEMPERATURE "/sensors/temperature"
|
||||
#define MQTT_NODE_PRESSURE "/sensors/pressure"
|
||||
#define MQTT_NODE_HUMIDITY "/sensors/humidity"
|
||||
#define MQTT_NODE_PULSE "/pulse"
|
||||
#define MQTT_NODE_SWITCH_1 "/sw1"
|
||||
#define MQTT_NODE_SWITCH_2 "/sw2"
|
||||
#define MQTT_NODE_OUTPUT_PWM_1 "/pwm1"
|
||||
// Standardize switches channels
|
||||
#define MQTT_IOT_CHANNEL_OUTPUT_PULSE "node1/output/pulse"
|
||||
#define MQTT_IOT_CHANNEL_OUTPUT_SWITCH_1 "node1/output/sw1"
|
||||
|
@ -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.
|
||||
|
||||
@ -19,11 +20,10 @@
|
||||
#include "secrets.h"
|
||||
#include "config.h"
|
||||
|
||||
#ifdef BME280
|
||||
|
||||
#ifdef BME280 // I2C temperature, pressure and humidity sensor.
|
||||
#include <Adafruit_BME280.h>
|
||||
#endif
|
||||
#ifdef BMP280
|
||||
#ifdef BMP280 // ISP temperature, pressure and humidity sensor.
|
||||
#include <Adafruit_BMP280.h>
|
||||
#endif
|
||||
|
||||
@ -67,13 +67,11 @@ PubSubClient connection(espClientSSL); //mosquitto_ssl
|
||||
|
||||
void mosquito_callback (char* topic, byte* message, unsigned int length)
|
||||
{
|
||||
//mosquitto.mosquito_callback(topic, message, length);
|
||||
|
||||
// Display topic and message received.
|
||||
Serial.print("\nMessage arrived on topic: ");
|
||||
Serial.println(topic);
|
||||
Serial.print("Message: ");
|
||||
String messageTemp; // variable to temporary store message received
|
||||
String messageTemp; // variable to temporary store message received
|
||||
|
||||
// Convert message received in bytes into String
|
||||
for (int i=0; i < length; i++) {
|
||||
@ -185,6 +183,7 @@ void mosquitto_connect ()
|
||||
Serial.println(connection.state());
|
||||
#endif
|
||||
#ifdef MQTT_SSL // MOSQUITTO MQTT port 8883
|
||||
// MQTX MQTT Cloud
|
||||
Serial.println(":8883");
|
||||
espClientSSL.setCACert(NODE_CERT_CA);
|
||||
connection.setServer(mqtt_server, 8883);
|
||||
@ -202,7 +201,7 @@ void mosquitto_connect ()
|
||||
delay(5000);
|
||||
}
|
||||
}
|
||||
/* on-premises MQTT
|
||||
/* on-premises Mosquitto MQTT
|
||||
Serial.println(":8883");
|
||||
connection.setServer(mqtt_server, 8883);
|
||||
espClientSSL.setCACert(NODE_CERT_CA);
|
||||
@ -348,6 +347,8 @@ void setup() {
|
||||
|
||||
Serial.print("Connecting to Mosquitto at IP: ");
|
||||
Serial.print(mqtt_server);
|
||||
mosquitto_connect();
|
||||
/**
|
||||
#ifdef MQTT // MOSQUITTO MQTT port 1883
|
||||
Serial.println(":1883");
|
||||
connection.setServer(mqtt_server, 1883);
|
||||
|
BIN
ESP32_Temperture-Node_2024-03-07.zip
Normal file
BIN
ESP32_Temperture-Node_2024-03-07.zip
Normal file
Binary file not shown.
Loading…
Reference in New Issue
Block a user