change topic conf for button press

This commit is contained in:
Carsten Graf
2025-07-05 01:37:43 +02:00
parent fb4e4d2bb5
commit 6f0c91d0ee
4 changed files with 12 additions and 8 deletions

Binary file not shown.

BIN
data/firmware.bin Normal file

Binary file not shown.

View File

@@ -87,7 +87,6 @@ const heartbeatTimeouts = {
// Set all heartbeats to red initially
["heartbeat1", "heartbeat2", "heartbeat3", "heartbeat4"].forEach(id => {
document.getElementById(id).classList.remove('active');
//document.getElementById(id).style.backgroundColor = "red";
});
// Handle WebSocket events
@@ -250,7 +249,6 @@ setInterval(() => {
].forEach(({button, id}) => {
if (now - heartbeatTimeouts[button] > 10000) {
document.getElementById(id).classList.remove('active');
//document.getElementById(id).style.backgroundColor = "red";
}
});
}, 1000);

View File

@@ -39,8 +39,15 @@ PicoMQTT::Server mqtt;
void readButtonJSON(const char * topic, const char * payload) {
if(strcmp(topic, "aquacross/button/press") == 0){
const char* prefix = "aquacross/button/";
size_t prefixLen = strlen(prefix);
if (strncmp(topic, prefix, prefixLen) != 0) {
return;
}
// MAC aus dem Topic extrahieren
String buttonId = String(topic + prefixLen);
// Create a JSON document to parse the incoming message
JsonDocument doc;
DeserializationError error = deserializeJson(doc, payload);
@@ -53,17 +60,16 @@ void readButtonJSON(const char * topic, const char * payload) {
// Extract values from JSON
int pressType = doc["type"] | 0;
const char* buttonId = doc["buttonmac"] | "unknown";
uint64_t timestamp = doc["timestamp"] | 0ULL;
// Print received data
Serial.printf("Button Press Received:\n");
Serial.printf(" Type: %d\n", pressType);
Serial.printf(" Button MAC: %s\n", buttonId);
Serial.printf(" Button MAC: %s\n", buttonId.c_str());
Serial.printf(" Timestamp: %llu\n", timestamp);
auto macBytes = macStringToBytes(buttonId);
auto macBytes = macStringToBytes(buttonId.c_str());
if (learningMode) {
handleLearningMode(macBytes.data());
@@ -84,7 +90,7 @@ void readButtonJSON(const char * topic, const char * payload) {
// Flash status LED to indicate received message
updateStatusLED(3);
}
}
void handleHeartbeatTopic(const char* topic, const char* payload) {
@@ -211,7 +217,7 @@ void setupMqttServer() {
mqtt.subscribe("#", [](const char * topic, const char * payload) {
//Message received callback
//Serial.printf("Received message on topic '%s': %s\n", topic, payload);
if (strcmp(topic, "aquacross/button/press") == 0) {
if (strncmp(topic, "aquacross/button/", 17) == 0) {
readButtonJSON(topic, payload);
} else if (strncmp(topic, "aquacross/button/rfid/", 22) == 0) {
readRFIDfromButton(topic, payload);