From b16fbcbef2da4c6d5409d3b545830249fdfd4ca2 Mon Sep 17 00:00:00 2001 From: DigiH Date: Sun, 4 Sep 2022 01:51:52 +0200 Subject: [PATCH] valueAsASubject to valueAsATopic inconsistency fix (#1260) --- docs/upload/advanced-configuration.md | 6 ++++-- main/User_config.h | 5 +++-- main/ZgatewayRF.ino | 2 +- main/ZgatewayRTL_433.ino | 2 +- main/main.ino | 4 ++-- platformio.ini | 4 ++-- 6 files changed, 13 insertions(+), 10 deletions(-) diff --git a/docs/upload/advanced-configuration.md b/docs/upload/advanced-configuration.md index b9764e41..f1ff38c1 100644 --- a/docs/upload/advanced-configuration.md +++ b/docs/upload/advanced-configuration.md @@ -32,10 +32,12 @@ You can know compile and upload to your board and the gateway should connect wit ## Add the received "value" at the end of the topic For the gateways that publish a "value" parameter on the json (RF, IR...), it is possible to concatenate this parameter at the end of the topic. -So as to activate this function you need to uncomment the line below in User_config.h +So as to activate this function you need to set `valueAsATopic` to true in User_config.h ``` cpp -//#define valueAsASubject true +#ifndef valueAsATopic +# define valueAsATopic false // define true to integrate msg value into the subject when receiving +#endif ``` Per default you see the following data: diff --git a/main/User_config.h b/main/User_config.h index 73aed54d..5d6081e9 100644 --- a/main/User_config.h +++ b/main/User_config.h @@ -456,8 +456,9 @@ int lowpowermode = DEFAULT_LOW_POWER_MODE; #define eraseCmd "erase" #define statusCmd "status" -// uncomment the line below to integrate msg value into the subject when receiving -//#define valueAsASubject true +#ifndef valueAsATopic +# define valueAsATopic false // define true to integrate msg value into the subject when receiving +#endif #if defined(ESP32) # define JSON_MSG_BUFFER 768 diff --git a/main/ZgatewayRF.ino b/main/ZgatewayRF.ino index a73a9cf3..1ccf9c0c 100644 --- a/main/ZgatewayRF.ino +++ b/main/ZgatewayRF.ino @@ -89,7 +89,7 @@ void RFtoMQTTdiscovery(SIGNAL_SIZE_UL_ULL MQTTvalue) { Log.trace(F("RF Entity Discovered, create HA Discovery CFG" CR)); char* switchRF[2] = {val, "RF"}; Log.trace(F("CreateDiscoverySwitch: %s" CR), switchRF[1]); -# ifdef valueAsASubject +# if valueAsATopic String discovery_topic = String(subjectRFtoMQTT) + "/" + String(switchRF[0]); # else String discovery_topic = String(subjectRFtoMQTT); diff --git a/main/ZgatewayRTL_433.ino b/main/ZgatewayRTL_433.ino index 907a817f..0db7f982 100644 --- a/main/ZgatewayRTL_433.ino +++ b/main/ZgatewayRTL_433.ino @@ -50,7 +50,7 @@ void rtl_433_Callback(char* message) { } String topic = String(subjectRTL_433toMQTT); -# ifdef valueAsASubject +# if valueAsATopic String model = RFrtl_433_ESPdata["model"]; String id = RFrtl_433_ESPdata["id"]; if (model != 0) { diff --git a/main/main.ino b/main/main.ino index 86fa23ed..21404881 100644 --- a/main/main.ino +++ b/main/main.ino @@ -313,7 +313,7 @@ void pub(const char* topicori, JsonObject& data) { Log.notice(F("Send on %s msg %s" CR), topicori, dataAsString.c_str()); digitalWrite(LED_SEND_RECEIVE, LED_SEND_RECEIVE_ON); String topic = String(mqtt_topic) + String(gateway_name) + String(topicori); -#ifdef valueAsASubject +#if valueAsATopic # ifdef ZgatewayPilight String value = data["value"]; String protocol = data["protocol"]; @@ -2100,7 +2100,7 @@ void MQTTtoSYS(char* topicOri, JsonObject& SYSdata) { // json object decoding } } -#if defined(valueAsASubject) && !defined(ZgatewayPilight) +#if valueAsATopic && !defined(ZgatewayPilight) # if defined(ESP32) || defined(ESP8266) || defined(__AVR_ATmega2560__) || defined(__AVR_ATmega1280__) String toString(uint64_t input) { String result = ""; diff --git a/platformio.ini b/platformio.ini index ca313acf..8abf99ae 100644 --- a/platformio.ini +++ b/platformio.ini @@ -760,7 +760,7 @@ build_flags = '-DZradioCC1101="CC1101"' '-DZgatewayRTL_433="rtl_433"' '-DGateway_Name="OpenMQTTGateway_rtl_433_ESP"' - '-DvalueAsASubject=true' ; MQTT topic includes model and device + '-DvalueAsATopic=true' ; MQTT topic includes model and device ; '-DPUBLISH_UNPARSED=true' ; Publish details of undecoded signals ; '-DRTL_DEBUG=4' ; enable rtl_433 verbose device decode @@ -784,7 +784,7 @@ build_flags = '-DZgatewayPilight="Pilight"' '-DZradioCC1101="CC1101"' '-DGateway_Name="OpenMQTTGateway_multi_receiver"' - '-DvalueAsASubject=true' ; MQTT topic includes model and device (rtl_433) or protocol and id ( RF and PiLight ) + '-DvalueAsATopic=true' ; MQTT topic includes model and device (rtl_433) or protocol and id (RF and PiLight) ; '-DDEFAULT_RECEIVER=1' ; Default receiver to enable on startup [env:tinypico-ble]