diff --git a/data/button.bin b/data/button.bin deleted file mode 100644 index 462920f..0000000 Binary files a/data/button.bin and /dev/null differ diff --git a/data/firmware.bin b/data/firmware.bin new file mode 100644 index 0000000..52506e0 Binary files /dev/null and b/data/firmware.bin differ diff --git a/data/index.html b/data/index.html index e419177..92c877b 100644 --- a/data/index.html +++ b/data/index.html @@ -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); diff --git a/src/communication.h b/src/communication.h index 8840854..e2fe271 100644 --- a/src/communication.h +++ b/src/communication.h @@ -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);