change topic conf for button press
This commit is contained in:
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user