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();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -298,6 +298,7 @@ String getTimerDataJSON() {
|
||||
void setup() {
|
||||
Serial.begin(115200);
|
||||
|
||||
|
||||
if (!SPIFFS.begin(true)) {
|
||||
Serial.println("SPIFFS Mount Failed");
|
||||
return;
|
||||
@@ -318,7 +319,7 @@ void setup() {
|
||||
setupOTA(&server);
|
||||
|
||||
setupRoutes();
|
||||
|
||||
setupLED();
|
||||
setupMqttServer(); // MQTT Server initialisieren
|
||||
|
||||
|
||||
|
||||
@@ -3,10 +3,15 @@
|
||||
|
||||
#define LED_PIN LED_BUILTIN
|
||||
|
||||
|
||||
// Status LED
|
||||
unsigned long lastLedBlink = 0;
|
||||
bool ledState = false;
|
||||
|
||||
void setupLED() {
|
||||
pinMode(LED_PIN, OUTPUT);
|
||||
digitalWrite(LED_PIN, LOW); // LED aus
|
||||
}
|
||||
|
||||
void updateStatusLED(int blinkPattern) {
|
||||
unsigned long currentTime = millis();
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
#include "licenceing.h"
|
||||
|
||||
const char* ssidAP = "AquaCross-Timer";
|
||||
const char* passwordAP = "aquacross123";
|
||||
const char* passwordAP = nullptr;
|
||||
|
||||
const char* ssidSTA = "Obiwlankenobi";
|
||||
const char* passwordSTA = "Delfine1!";
|
||||
|
||||
Reference in New Issue
Block a user