first commit

This commit is contained in:
Carsten Graf
2025-06-01 11:51:02 +02:00
commit 2d2ee0a41a
22 changed files with 3241 additions and 0 deletions

44
src/communication.h Normal file
View File

@@ -0,0 +1,44 @@
#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();
}
}