Files
AquaMasterMQTT/src/communication.h
Carsten Graf 2d2ee0a41a first commit
2025-06-01 11:51:02 +02:00

45 lines
1.1 KiB
C

#include <Arduino.h>
#include "master.h"
#include <PicoMQTT.h>
#include <statusled.h>
#include "timesync.h"
// Datenstruktur für ESP-NOW Nachrichten
// Datenstruktur für ESP-NOW Nachrichten
typedef struct {
uint8_t messageType;
uint8_t buttonId;
int buttonPressed;
uint32_t timestamp;
char messageId[33]; // 32 hex chars + null terminator for 128-bit ID
} ButtonMessage;
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);
});
// Start the MQTT server
mqtt.begin();
}
void loopMqttServer() {
// Handle incoming MQTT messages
mqtt.loop();
// 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!");
lastPublish = millis();
}
}