change topic conf for button press
This commit is contained in:
BIN
data/button.bin
BIN
data/button.bin
Binary file not shown.
BIN
data/firmware.bin
Normal file
BIN
data/firmware.bin
Normal file
Binary file not shown.
@@ -87,7 +87,6 @@ const heartbeatTimeouts = {
|
|||||||
// Set all heartbeats to red initially
|
// Set all heartbeats to red initially
|
||||||
["heartbeat1", "heartbeat2", "heartbeat3", "heartbeat4"].forEach(id => {
|
["heartbeat1", "heartbeat2", "heartbeat3", "heartbeat4"].forEach(id => {
|
||||||
document.getElementById(id).classList.remove('active');
|
document.getElementById(id).classList.remove('active');
|
||||||
//document.getElementById(id).style.backgroundColor = "red";
|
|
||||||
});
|
});
|
||||||
|
|
||||||
// Handle WebSocket events
|
// Handle WebSocket events
|
||||||
@@ -250,7 +249,6 @@ setInterval(() => {
|
|||||||
].forEach(({button, id}) => {
|
].forEach(({button, id}) => {
|
||||||
if (now - heartbeatTimeouts[button] > 10000) {
|
if (now - heartbeatTimeouts[button] > 10000) {
|
||||||
document.getElementById(id).classList.remove('active');
|
document.getElementById(id).classList.remove('active');
|
||||||
//document.getElementById(id).style.backgroundColor = "red";
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}, 1000);
|
}, 1000);
|
||||||
|
|||||||
@@ -39,8 +39,15 @@ PicoMQTT::Server mqtt;
|
|||||||
|
|
||||||
void readButtonJSON(const char * topic, const char * payload) {
|
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
|
// Create a JSON document to parse the incoming message
|
||||||
JsonDocument doc;
|
JsonDocument doc;
|
||||||
DeserializationError error = deserializeJson(doc, payload);
|
DeserializationError error = deserializeJson(doc, payload);
|
||||||
@@ -53,17 +60,16 @@ void readButtonJSON(const char * topic, const char * payload) {
|
|||||||
|
|
||||||
// Extract values from JSON
|
// Extract values from JSON
|
||||||
int pressType = doc["type"] | 0;
|
int pressType = doc["type"] | 0;
|
||||||
const char* buttonId = doc["buttonmac"] | "unknown";
|
|
||||||
uint64_t timestamp = doc["timestamp"] | 0ULL;
|
uint64_t timestamp = doc["timestamp"] | 0ULL;
|
||||||
|
|
||||||
// Print received data
|
// Print received data
|
||||||
Serial.printf("Button Press Received:\n");
|
Serial.printf("Button Press Received:\n");
|
||||||
Serial.printf(" Type: %d\n", pressType);
|
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);
|
Serial.printf(" Timestamp: %llu\n", timestamp);
|
||||||
|
|
||||||
|
|
||||||
auto macBytes = macStringToBytes(buttonId);
|
auto macBytes = macStringToBytes(buttonId.c_str());
|
||||||
|
|
||||||
if (learningMode) {
|
if (learningMode) {
|
||||||
handleLearningMode(macBytes.data());
|
handleLearningMode(macBytes.data());
|
||||||
@@ -84,7 +90,7 @@ void readButtonJSON(const char * topic, const char * payload) {
|
|||||||
// Flash status LED to indicate received message
|
// Flash status LED to indicate received message
|
||||||
updateStatusLED(3);
|
updateStatusLED(3);
|
||||||
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void handleHeartbeatTopic(const char* topic, const char* payload) {
|
void handleHeartbeatTopic(const char* topic, const char* payload) {
|
||||||
@@ -211,7 +217,7 @@ void setupMqttServer() {
|
|||||||
mqtt.subscribe("#", [](const char * topic, const char * payload) {
|
mqtt.subscribe("#", [](const char * topic, const char * payload) {
|
||||||
//Message received callback
|
//Message received callback
|
||||||
//Serial.printf("Received message on topic '%s': %s\n", topic, payload);
|
//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);
|
readButtonJSON(topic, payload);
|
||||||
} else if (strncmp(topic, "aquacross/button/rfid/", 22) == 0) {
|
} else if (strncmp(topic, "aquacross/button/rfid/", 22) == 0) {
|
||||||
readRFIDfromButton(topic, payload);
|
readRFIDfromButton(topic, payload);
|
||||||
|
|||||||
Reference in New Issue
Block a user