Umstellung auf MQTT

This commit is contained in:
Carsten Graf
2025-06-01 21:41:57 +02:00
parent 2d2ee0a41a
commit 5f86308367
4 changed files with 15 additions and 4 deletions

View File

@@ -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();
}
}