Publishing/receiving inconsistencies fix (#1229)

* Publishing/receiving inconsistencies

* General platformio.ini changes

General platformio.ini changes to allow for publishing/receiving settings to be defined in User_cofig.h instead of them only working if defined in the environments. Kept separate so far for discussion.
This commit is contained in:
DigiH authored and GitHub committed 2022-07-01 07:17:02 -05:00
1 parent 3bd1d31fcc
commit a388f14e75
15 files changed
+39 -40

No files matched your search

+7 -9
View File
@@ -29,8 +29,6 @@ lib_deps =
${libraries.arduinolog} ${libraries.arduinolog}
build_flags = build_flags =
-w ; supress all warnings -w ; supress all warnings
'-DjsonPublishing=true'
'-DjsonReceiving=true'
; '-DLOG_LEVEL=LOG_LEVEL_TRACE' ; Enable trace level logging ; '-DLOG_LEVEL=LOG_LEVEL_TRACE' ; Enable trace level logging
monitor_speed = 115200 monitor_speed = 115200
``` ```
@@ -96,8 +94,8 @@ build_flags =
'-DLED_RECEIVE_ON=LOW' ; Comment 2 '-DLED_RECEIVE_ON=LOW' ; Comment 2
'-DRF_RECEIVER_GPIO=13' '-DRF_RECEIVER_GPIO=13'
'-DRF_EMITTER_GPIO=15' '-DRF_EMITTER_GPIO=15'
'-UsimpleReceiving' ; Disable HA discovery '-DsimpleReceiving=false'
'-UZmqttDiscovery' '-UZmqttDiscovery' ; Disable HA discovery
monitor_speed = 115200 monitor_speed = 115200
[env:nodemcuv2-pilight-bme280-ota] [env:nodemcuv2-pilight-bme280-ota]
@@ -108,7 +106,7 @@ upload_flags =
--auth=otapassword --auth=otapassword
--port=8266 --port=8266
``` ```
The first new environment we create, `nodemcuv2-pilight-bme280`, inherits the default `nodemcuv2-pilight` environment in `platformio.ini` with the `extends = env:nodemcuv2-pilight` line. In the `lib_deps` section, it imports all the `lib_deps` of `nodemcuv2-pilight` with the `${env:nodemcuv2-pilight.lib_deps}` line, and adds BME280 on top of it. (Since the environment we're extending already has this `lib_deps` attribute, specifying it again would normally replace it completely with our new attribute; instead, to keep its value but simply append to it, we import the original in the beginning of our `lib_deps` attribute.) In the `build_flags` section, it again imports all the `build_flags` of `nodemcuv2-pilight` and many of its own overrides, e.g. changing `Base_Topic` found in `User_config.h` from the default to "rf/" by using the `'-DBase_Topic="rf/"'` line. It also unsets previously set configurations (i.e. `simpleReceiving`) by using `'-UsimpleReceiving'`. This environment will work over serial upload. The first new environment we create, `nodemcuv2-pilight-bme280`, inherits the default `nodemcuv2-pilight` environment in `platformio.ini` with the `extends = env:nodemcuv2-pilight` line. In the `lib_deps` section, it imports all the `lib_deps` of `nodemcuv2-pilight` with the `${env:nodemcuv2-pilight.lib_deps}` line, and adds BME280 on top of it. (Since the environment we're extending already has this `lib_deps` attribute, specifying it again would normally replace it completely with our new attribute; instead, to keep its value but simply append to it, we import the original in the beginning of our `lib_deps` attribute.) In the `build_flags` section, it again imports all the `build_flags` of `nodemcuv2-pilight` and many of its own overrides, e.g. changing `Base_Topic` found in `User_config.h` from the default to "rf/" by using the `'-DBase_Topic="rf/"'` line. It also unsets previously set configurations (i.e. `mqttDiscovery`) by using `'-UZmqttDiscovery'`. This environment will work over serial upload.
The second new environment, `nodemcuv2-pilight-bme280-ota`, inherits everything we specified in the first environment (with the line `extends = env:nodemcuv2-pilight-bme280`), but modifies it to upload over OTA (Wi-Fi). We also specified this as the `default_env` in the beginning of the file, so PlatformIO will choose this environment to build and upload if we don't specify otherwise. The second new environment, `nodemcuv2-pilight-bme280-ota`, inherits everything we specified in the first environment (with the line `extends = env:nodemcuv2-pilight-bme280`), but modifies it to upload over OTA (Wi-Fi). We also specified this as the `default_env` in the beginning of the file, so PlatformIO will choose this environment to build and upload if we don't specify otherwise.
@@ -230,14 +228,14 @@ Per default Json reception and Json publication is activated, the previous simpl
You can deactivate Json or simple mode following theses instructions: You can deactivate Json or simple mode following theses instructions:
```cpp ```cpp
#define jsonPublishing true //comment if you don't want to use Json publishing (one topic for all the parameters) #define jsonPublishing true //define false if you don't want to use Json publishing (one topic for all the parameters)
//example home/OpenMQTTGateway_ESP32_DEVKIT/BTtoMQTT/4XXXXXXXXXX4 {"rssi":-63,"servicedata":"fe0000000000000000000000000000000000000000"} //example home/OpenMQTTGateway_ESP32_DEVKIT/BTtoMQTT/4XXXXXXXXXX4 {"rssi":-63,"servicedata":"fe0000000000000000000000000000000000000000"}
//#define simplePublishing true //comment if you don't want to use simple publishing (one topic for one parameter) #define simplePublishing false //define true if you want to use simple publishing (one topic for one parameter)
//example //example
// home/OpenMQTTGateway_ESP32_DEVKIT/BTtoMQTT/4XXXXXXXXXX4/rssi -63.0 // home/OpenMQTTGateway_ESP32_DEVKIT/BTtoMQTT/4XXXXXXXXXX4/rssi -63.0
// home/OpenMQTTGateway_ESP32_DEVKIT/BTtoMQTT/4XXXXXXXXXX4/servicedata fe0000000000000000000000000000000000000000 // home/OpenMQTTGateway_ESP32_DEVKIT/BTtoMQTT/4XXXXXXXXXX4/servicedata fe0000000000000000000000000000000000000000
#define simpleReceiving true //comment if you don't want to use old way reception analysis #define simpleReceiving true //define false if you don't want to use old way reception analysis
#define jsonReceiving true //comment if you don't want to use Json reception analysis #define jsonReceiving true //define false if you don't want to use Json reception analysis
``` ```
If you are using platformio you can also comment the definitions above and define your parameters into platformio.ini file by setting the following `build_flags`: If you are using platformio you can also comment the definitions above and define your parameters into platformio.ini file by setting the following `build_flags`:
+8 -4
View File
@@ -353,18 +353,22 @@ int lowpowermode = DEFAULT_LOW_POWER_MODE;
#endif #endif
#ifndef jsonPublishing #ifndef jsonPublishing
# define jsonPublishing true //comment if you don't want to use Json publishing (one topic for all the parameters) # define jsonPublishing true //define false if you don't want to use Json publishing (one topic for all the parameters)
#endif #endif
//example home/OpenMQTTGateway_ESP32_DEVKIT/BTtoMQTT/4XXXXXXXXXX4 {"rssi":-63,"servicedata":"fe0000000000000000000000000000000000000000"} //example home/OpenMQTTGateway_ESP32_DEVKIT/BTtoMQTT/4XXXXXXXXXX4 {"rssi":-63,"servicedata":"fe0000000000000000000000000000000000000000"}
#ifndef jsonReceiving #ifndef jsonReceiving
# define jsonReceiving true //comment if you don't want to use Json reception analysis # define jsonReceiving true //define false if you don't want to use Json reception analysis
#endif #endif
//#define simplePublishing true //comment if you don't want to use simple publishing (one topic for one parameter) #ifndef simplePublishing
# define simplePublishing false //define true if you want to use simple publishing (one topic for one parameter)
#endif
//example //example
// home/OpenMQTTGateway_ESP32_DEVKIT/BTtoMQTT/4XXXXXXXXXX4/rssi -63.0 // home/OpenMQTTGateway_ESP32_DEVKIT/BTtoMQTT/4XXXXXXXXXX4/rssi -63.0
// home/OpenMQTTGateway_ESP32_DEVKIT/BTtoMQTT/4XXXXXXXXXX4/servicedata fe0000000000000000000000000000000000000000 // home/OpenMQTTGateway_ESP32_DEVKIT/BTtoMQTT/4XXXXXXXXXX4/servicedata fe0000000000000000000000000000000000000000
//#define simpleReceiving true //comment if you don't want to use old way reception analysis #ifndef simpleReceiving
# define simpleReceiving true //define false if you don't want to use old way reception analysis
#endif
/*-------------DEFINE YOUR OTA PARAMETERS BELOW----------------*/ /*-------------DEFINE YOUR OTA PARAMETERS BELOW----------------*/
#ifndef ota_hostname #ifndef ota_hostname
+2 -2
View File
@@ -97,7 +97,7 @@ void FASTLEDLoop() {
boolean FASTLEDtoMQTT() { boolean FASTLEDtoMQTT() {
return false; return false;
} }
# ifdef jsonReceiving # if jsonReceiving
void MQTTtoFASTLED(char* topicOri, JsonObject& jsonData) { void MQTTtoFASTLED(char* topicOri, JsonObject& jsonData) {
currentLEDState = GENERAL; currentLEDState = GENERAL;
//trc(topicOri); //trc(topicOri);
@@ -121,7 +121,7 @@ void MQTTtoFASTLED(char* topicOri, JsonObject& jsonData) {
} }
# endif # endif
# ifdef simpleReceiving # if simpleReceiving
void MQTTtoFASTLED(char* topicOri, char* datacallback) { void MQTTtoFASTLED(char* topicOri, char* datacallback) {
Log.trace(F("MQTTtoFASTLED: " CR)); Log.trace(F("MQTTtoFASTLED: " CR));
currentLEDState = GENERAL; currentLEDState = GENERAL;
+2 -2
View File
@@ -30,7 +30,7 @@
#ifdef ZactuatorONOFF #ifdef ZactuatorONOFF
# ifdef jsonReceiving # if jsonReceiving
void MQTTtoONOFF(char* topicOri, JsonObject& ONOFFdata) { void MQTTtoONOFF(char* topicOri, JsonObject& ONOFFdata) {
if (cmpToMainTopic(topicOri, subjectMQTTtoONOFF)) { if (cmpToMainTopic(topicOri, subjectMQTTtoONOFF)) {
Log.trace(F("MQTTtoONOFF json data analysis" CR)); Log.trace(F("MQTTtoONOFF json data analysis" CR));
@@ -70,7 +70,7 @@ void MQTTtoONOFF(char* topicOri, JsonObject& ONOFFdata) {
} }
# endif # endif
# ifdef simpleReceiving # if simpleReceiving
void MQTTtoONOFF(char* topicOri, char* datacallback) { void MQTTtoONOFF(char* topicOri, char* datacallback) {
if ((cmpToMainTopic(topicOri, subjectMQTTtoONOFF))) { if ((cmpToMainTopic(topicOri, subjectMQTTtoONOFF))) {
Log.trace(F("MQTTtoONOFF" CR)); Log.trace(F("MQTTtoONOFF" CR));
+1 -1
View File
@@ -195,7 +195,7 @@ boolean PWMtoMQTT() {
return false; return false;
} }
# ifdef jsonReceiving # if jsonReceiving
void MQTTtoPWM(char* topicOri, JsonObject& jsonData) { void MQTTtoPWM(char* topicOri, JsonObject& jsonData) {
if (cmpToMainTopic(topicOri, subjectMQTTtoPWMset)) { if (cmpToMainTopic(topicOri, subjectMQTTtoPWMset)) {
Log.trace(F("MQTTtoPWM JSON analysis" CR)); Log.trace(F("MQTTtoPWM JSON analysis" CR));
+1 -1
View File
@@ -51,7 +51,7 @@ void setupSomfy() {
Log.trace(F("ZactuatorSomfy setup done " CR)); Log.trace(F("ZactuatorSomfy setup done " CR));
} }
# ifdef jsonReceiving # if jsonReceiving
void MQTTtoSomfy(char* topicOri, JsonObject& jsonData) { void MQTTtoSomfy(char* topicOri, JsonObject& jsonData) {
if (cmpToMainTopic(topicOri, subjectMQTTtoSomfy)) { if (cmpToMainTopic(topicOri, subjectMQTTtoSomfy)) {
# ifdef ZradioCC1101 # ifdef ZradioCC1101
+2 -2
View File
@@ -95,7 +95,7 @@ bool _2GtoMQTT() {
} }
return false; return false;
} }
# ifdef simpleReceiving # if simpleReceiving
void MQTTto2G(char* topicOri, char* datacallback) { void MQTTto2G(char* topicOri, char* datacallback) {
String data = datacallback; String data = datacallback;
String topic = topicOri; String topic = topicOri;
@@ -126,7 +126,7 @@ void MQTTto2G(char* topicOri, char* datacallback) {
} }
# endif # endif
# ifdef jsonReceiving # if jsonReceiving
void MQTTto2G(char* topicOri, JsonObject& SMSdata) { void MQTTto2G(char* topicOri, JsonObject& SMSdata) {
if (cmpToMainTopic(topicOri, subjectMQTTto2G)) { if (cmpToMainTopic(topicOri, subjectMQTTto2G)) {
const char* sms = SMSdata["message"]; const char* sms = SMSdata["message"];
+1 -1
View File
@@ -181,7 +181,7 @@ void IRtoMQTT() {
bool sendIdentifiedProtocol(const char* protocol_name, SIGNAL_SIZE_UL_ULL data, const char* hex, unsigned int valueBITS, uint16_t valueRPT); bool sendIdentifiedProtocol(const char* protocol_name, SIGNAL_SIZE_UL_ULL data, const char* hex, unsigned int valueBITS, uint16_t valueRPT);
# ifdef jsonReceiving # if jsonReceiving
void MQTTtoIR(char* topicOri, JsonObject& IRdata) { void MQTTtoIR(char* topicOri, JsonObject& IRdata) {
if (cmpToMainTopic(topicOri, subjectMQTTtoIR)) { if (cmpToMainTopic(topicOri, subjectMQTTtoIR)) {
Log.trace(F("MQTTtoIR json" CR)); Log.trace(F("MQTTtoIR json" CR));
+2 -2
View File
@@ -81,7 +81,7 @@ void LORAtoMQTT() {
} }
} }
# ifdef jsonReceiving # if jsonReceiving
void MQTTtoLORA(char* topicOri, JsonObject& LORAdata) { // json object decoding void MQTTtoLORA(char* topicOri, JsonObject& LORAdata) { // json object decoding
if (cmpToMainTopic(topicOri, subjectMQTTtoLORA)) { if (cmpToMainTopic(topicOri, subjectMQTTtoLORA)) {
Log.trace(F("MQTTtoLORA json" CR)); Log.trace(F("MQTTtoLORA json" CR));
@@ -115,7 +115,7 @@ void MQTTtoLORA(char* topicOri, JsonObject& LORAdata) { // json object decoding
} }
} }
# endif # endif
# ifdef simpleReceiving # if simpleReceiving
void MQTTtoLORA(char* topicOri, char* LORAdata) { // json object decoding void MQTTtoLORA(char* topicOri, char* LORAdata) { // json object decoding
if (cmpToMainTopic(topicOri, subjectMQTTtoLORA)) { if (cmpToMainTopic(topicOri, subjectMQTTtoLORA)) {
LoRa.beginPacket(); LoRa.beginPacket();
+2 -2
View File
@@ -173,7 +173,7 @@ void RFtoMQTT() {
} }
} }
# ifdef simpleReceiving # if simpleReceiving
void MQTTtoRF(char* topicOri, char* datacallback) { void MQTTtoRF(char* topicOri, char* datacallback) {
# ifdef ZradioCC1101 // set Receive off and Transmitt on # ifdef ZradioCC1101 // set Receive off and Transmitt on
ELECHOUSE_cc1101.SetTx(receiveMhz); ELECHOUSE_cc1101.SetTx(receiveMhz);
@@ -235,7 +235,7 @@ void MQTTtoRF(char* topicOri, char* datacallback) {
} }
# endif # endif
# ifdef jsonReceiving # if jsonReceiving
void MQTTtoRF(char* topicOri, JsonObject& RFdata) { // json object decoding void MQTTtoRF(char* topicOri, JsonObject& RFdata) { // json object decoding
if (cmpToMainTopic(topicOri, subjectMQTTtoRF)) { if (cmpToMainTopic(topicOri, subjectMQTTtoRF)) {
Log.trace(F("MQTTtoRF json" CR)); Log.trace(F("MQTTtoRF json" CR));
+2 -2
View File
@@ -148,7 +148,7 @@ void rf2Callback(unsigned int period, unsigned long address, unsigned long group
rf2rd.hasNewData = true; rf2rd.hasNewData = true;
} }
# ifdef simpleReceiving # if simpleReceiving
void MQTTtoRF2(char* topicOri, char* datacallback) { void MQTTtoRF2(char* topicOri, char* datacallback) {
# ifdef ZradioCC1101 # ifdef ZradioCC1101
NewRemoteReceiver::disable(); NewRemoteReceiver::disable();
@@ -258,7 +258,7 @@ void MQTTtoRF2(char* topicOri, char* datacallback) {
} }
# endif # endif
# ifdef jsonReceiving # if jsonReceiving
void MQTTtoRF2(char* topicOri, JsonObject& RF2data) { // json object decoding void MQTTtoRF2(char* topicOri, JsonObject& RF2data) { // json object decoding
if (cmpToMainTopic(topicOri, subjectMQTTtoRF2)) { if (cmpToMainTopic(topicOri, subjectMQTTtoRF2)) {
+2 -2
View File
@@ -175,7 +175,7 @@ bool RFM69toMQTT(void) {
} }
} }
# ifdef simpleReceiving # if simpleReceiving
void MQTTtoRFM69(char* topicOri, char* datacallback) { void MQTTtoRFM69(char* topicOri, char* datacallback) {
if (cmpToMainTopic(topicOri, subjectMQTTtoRFM69)) { if (cmpToMainTopic(topicOri, subjectMQTTtoRFM69)) {
Log.trace(F("MQTTtoRFM69 data analysis" CR)); Log.trace(F("MQTTtoRFM69 data analysis" CR));
@@ -204,7 +204,7 @@ void MQTTtoRFM69(char* topicOri, char* datacallback) {
} }
} }
# endif # endif
# ifdef jsonReceiving # if jsonReceiving
void MQTTtoRFM69(char* topicOri, JsonObject& RFM69data) { void MQTTtoRFM69(char* topicOri, JsonObject& RFM69data) {
if (cmpToMainTopic(topicOri, subjectMQTTtoRFM69)) { if (cmpToMainTopic(topicOri, subjectMQTTtoRFM69)) {
const char* data = RFM69data["data"]; const char* data = RFM69data["data"];
+2 -2
View File
@@ -166,7 +166,7 @@ bool _rfbToChar(byte* in, char* out) {
return true; return true;
} }
# ifdef simpleReceiving # if simpleReceiving
void MQTTtoSRFB(char* topicOri, char* datacallback) { void MQTTtoSRFB(char* topicOri, char* datacallback) {
// RF DATA ANALYSIS // RF DATA ANALYSIS
String topic = topicOri; String topic = topicOri;
@@ -262,7 +262,7 @@ void MQTTtoSRFB(char* topicOri, char* datacallback) {
} }
} }
# endif # endif
# ifdef jsonReceiving # if jsonReceiving
void MQTTtoSRFB(char* topicOri, JsonObject& SRFBdata) { void MQTTtoSRFB(char* topicOri, JsonObject& SRFBdata) {
// RF DATA ANALYSIS // RF DATA ANALYSIS
const char* raw = SRFBdata["raw"]; const char* raw = SRFBdata["raw"];
+4 -4
View File
@@ -328,12 +328,12 @@ void pub(const char* topicori, JsonObject& data) {
# endif # endif
#endif #endif
#ifdef jsonPublishing #if jsonPublishing
Log.trace(F("jsonPubl - ON" CR)); Log.trace(F("jsonPubl - ON" CR));
pubMQTT(topic, dataAsString.c_str()); pubMQTT(topic, dataAsString.c_str());
#endif #endif
#ifdef simplePublishing #if simplePublishing
Log.trace(F("simplePub - ON" CR)); Log.trace(F("simplePub - ON" CR));
// Loop through all the key-value pairs in obj // Loop through all the key-value pairs in obj
for (JsonPair p : data) { for (JsonPair p : data) {
@@ -1696,7 +1696,7 @@ void receivingMQTT(char* topicOri, char* datacallback) {
#ifdef ZgatewayRTL_433 // ZgatewayRTL_433 is only defined with json publishing due to its numerous parameters #ifdef ZgatewayRTL_433 // ZgatewayRTL_433 is only defined with json publishing due to its numerous parameters
MQTTtoRTL_433(topicOri, jsondata); MQTTtoRTL_433(topicOri, jsondata);
#endif #endif
#ifdef jsonReceiving #if jsonReceiving
# ifdef ZgatewayLORA # ifdef ZgatewayLORA
MQTTtoLORA(topicOri, jsondata); MQTTtoLORA(topicOri, jsondata);
# endif # endif
@@ -1747,7 +1747,7 @@ void receivingMQTT(char* topicOri, char* datacallback) {
MQTTtoSYS(topicOri, jsondata); MQTTtoSYS(topicOri, jsondata);
} else { // not a json object --> simple decoding } else { // not a json object --> simple decoding
#ifdef simpleReceiving #if simpleReceiving
# ifdef ZgatewayLORA # ifdef ZgatewayLORA
MQTTtoLORA(topicOri, datacallback); MQTTtoLORA(topicOri, datacallback);
# endif # endif
+1 -4
View File
@@ -144,8 +144,6 @@ lib_deps =
${libraries.arduinolog} ${libraries.arduinolog}
build_flags = build_flags =
-w ; supress all warnings -w ; supress all warnings
'-DjsonPublishing=true'
'-DjsonReceiving=true'
; '-DLOG_LEVEL=LOG_LEVEL_TRACE' ; Enable trace level logging ; '-DLOG_LEVEL=LOG_LEVEL_TRACE' ; Enable trace level logging
monitor_speed = 115200 monitor_speed = 115200
@@ -159,7 +157,6 @@ lib_deps =
${env.lib_deps} ${env.lib_deps}
build_flags = build_flags =
${env.build_flags} ${env.build_flags}
'-DsimpleReceiving=true'
'-DZmqttDiscovery="HADiscovery"' '-DZmqttDiscovery="HADiscovery"'
'-DTRACE=1' '-DTRACE=1'
'-DCONFIG_BT_NIMBLE_ROLE_PERIPHERAL_DISABLED' '-DCONFIG_BT_NIMBLE_ROLE_PERIPHERAL_DISABLED'
@@ -174,7 +171,6 @@ lib_deps =
${libraries.ethernet} ${libraries.ethernet}
build_flags = build_flags =
${env.build_flags} ${env.build_flags}
'-DsimpleReceiving=true'
'-DZmqttDiscovery="HADiscovery"' '-DZmqttDiscovery="HADiscovery"'
'-DTRACE=1' '-DTRACE=1'
@@ -184,6 +180,7 @@ lib_deps =
${libraries.ethernet} ${libraries.ethernet}
build_flags = build_flags =
${env.build_flags} ${env.build_flags}
'-DsimpleReceiving=false'
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; ENVIRONMENTS LIST ; ; ENVIRONMENTS LIST ;