Umstellung auf MQTT
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
#include <Arduino.h>
|
||||
#include "master.h"
|
||||
#include <ArduinoJson.h>
|
||||
|
||||
#include <PicoMQTT.h>
|
||||
|
||||
@@ -21,14 +22,18 @@ PicoMQTT::Server mqtt;
|
||||
|
||||
|
||||
void setupMqttServer() {
|
||||
|
||||
// Set up the MQTT server with the desired port
|
||||
// Subscribe to a topic pattern and attach a callback
|
||||
mqtt.subscribe("#", [](const char * topic, const char * payload) {
|
||||
Serial.printf("Received message in topic '%s': %s\n", topic, payload);
|
||||
updateStatusLED(3); // Flash LED on message received
|
||||
});
|
||||
|
||||
// Start the MQTT server
|
||||
mqtt.begin();
|
||||
|
||||
Serial.println("MQTT server started on port 1883");
|
||||
}
|
||||
|
||||
void loopMqttServer() {
|
||||
@@ -38,7 +43,7 @@ void loopMqttServer() {
|
||||
// Optionally, you can publish a message periodically
|
||||
static unsigned long lastPublish = 0;
|
||||
if (millis() - lastPublish > 5000) { // Publish every 5 seconds
|
||||
mqtt.publish("test/topic", "Hello from ESP32!");
|
||||
mqtt.publish("heartbeat/live", "Alive!");
|
||||
lastPublish = millis();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user