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}
build_flags =
-w ; supress all warnings
'-DjsonPublishing=true'
'-DjsonReceiving=true'
; '-DLOG_LEVEL=LOG_LEVEL_TRACE' ; Enable trace level logging
monitor_speed = 115200
```
@@ -96,8 +94,8 @@ build_flags =
'-DLED_RECEIVE_ON=LOW' ; Comment 2
'-DRF_RECEIVER_GPIO=13'
'-DRF_EMITTER_GPIO=15'
'-UsimpleReceiving' ; Disable HA discovery
'-UZmqttDiscovery'
'-DsimpleReceiving=false'
'-UZmqttDiscovery' ; Disable HA discovery
monitor_speed = 115200
[env:nodemcuv2-pilight-bme280-ota]
@@ -108,7 +106,7 @@ upload_flags =
--auth=otapassword
--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.
@@ -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:
```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"}
//#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
// home/OpenMQTTGateway_ESP32_DEVKIT/BTtoMQTT/4XXXXXXXXXX4/rssi -63.0
// home/OpenMQTTGateway_ESP32_DEVKIT/BTtoMQTT/4XXXXXXXXXX4/servicedata fe0000000000000000000000000000000000000000
#define simpleReceiving true //comment 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 simpleReceiving true //define false if you don't want to use old way 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`:
+8 -4
View File
@@ -353,18 +353,22 @@ int lowpowermode = DEFAULT_LOW_POWER_MODE;
#endif
#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
//example home/OpenMQTTGateway_ESP32_DEVKIT/BTtoMQTT/4XXXXXXXXXX4 {"rssi":-63,"servicedata":"fe0000000000000000000000000000000000000000"}
#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
//#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
// home/OpenMQTTGateway_ESP32_DEVKIT/BTtoMQTT/4XXXXXXXXXX4/rssi -63.0
// 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----------------*/
#ifndef ota_hostname
+2 -2
View File
@@ -97,7 +97,7 @@ void FASTLEDLoop() {
boolean FASTLEDtoMQTT() {
return false;
}
# ifdef jsonReceiving
# if jsonReceiving
void MQTTtoFASTLED(char* topicOri, JsonObject& jsonData) {
currentLEDState = GENERAL;
//trc(topicOri);
@@ -121,7 +121,7 @@ void MQTTtoFASTLED(char* topicOri, JsonObject& jsonData) {
}
# endif
# ifdef simpleReceiving
# if simpleReceiving
void MQTTtoFASTLED(char* topicOri, char* datacallback) {
Log.trace(F("MQTTtoFASTLED: " CR));
currentLEDState = GENERAL;
+2 -2
View File
@@ -30,7 +30,7 @@
#ifdef ZactuatorONOFF
# ifdef jsonReceiving
# if jsonReceiving
void MQTTtoONOFF(char* topicOri, JsonObject& ONOFFdata) {
if (cmpToMainTopic(topicOri, subjectMQTTtoONOFF)) {
Log.trace(F("MQTTtoONOFF json data analysis" CR));
@@ -70,7 +70,7 @@ void MQTTtoONOFF(char* topicOri, JsonObject& ONOFFdata) {
}
# endif
# ifdef simpleReceiving
# if simpleReceiving
void MQTTtoONOFF(char* topicOri, char* datacallback) {
if ((cmpToMainTopic(topicOri, subjectMQTTtoONOFF))) {
Log.trace(F("MQTTtoONOFF" CR));
+1 -1
View File
@@ -195,7 +195,7 @@ boolean PWMtoMQTT() {
return false;
}
# ifdef jsonReceiving
# if jsonReceiving
void MQTTtoPWM(char* topicOri, JsonObject& jsonData) {
if (cmpToMainTopic(topicOri, subjectMQTTtoPWMset)) {
Log.trace(F("MQTTtoPWM JSON analysis" CR));
+1 -1
View File
@@ -51,7 +51,7 @@ void setupSomfy() {
Log.trace(F("ZactuatorSomfy setup done " CR));
}
# ifdef jsonReceiving
# if jsonReceiving
void MQTTtoSomfy(char* topicOri, JsonObject& jsonData) {
if (cmpToMainTopic(topicOri, subjectMQTTtoSomfy)) {
# ifdef ZradioCC1101
+2 -2
View File
@@ -95,7 +95,7 @@ bool _2GtoMQTT() {
}
return false;
}
# ifdef simpleReceiving
# if simpleReceiving
void MQTTto2G(char* topicOri, char* datacallback) {
String data = datacallback;
String topic = topicOri;
@@ -126,7 +126,7 @@ void MQTTto2G(char* topicOri, char* datacallback) {
}
# endif
# ifdef jsonReceiving
# if jsonReceiving
void MQTTto2G(char* topicOri, JsonObject& SMSdata) {
if (cmpToMainTopic(topicOri, subjectMQTTto2G)) {
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);
# ifdef jsonReceiving
# if jsonReceiving
void MQTTtoIR(char* topicOri, JsonObject& IRdata) {
if (cmpToMainTopic(topicOri, subjectMQTTtoIR)) {
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
if (cmpToMainTopic(topicOri, subjectMQTTtoLORA)) {
Log.trace(F("MQTTtoLORA json" CR));
@@ -115,7 +115,7 @@ void MQTTtoLORA(char* topicOri, JsonObject& LORAdata) { // json object decoding
}
}
# endif
# ifdef simpleReceiving
# if simpleReceiving
void MQTTtoLORA(char* topicOri, char* LORAdata) { // json object decoding
if (cmpToMainTopic(topicOri, subjectMQTTtoLORA)) {
LoRa.beginPacket();
+2 -2
View File
@@ -173,7 +173,7 @@ void RFtoMQTT() {
}
}
# ifdef simpleReceiving
# if simpleReceiving
void MQTTtoRF(char* topicOri, char* datacallback) {
# ifdef ZradioCC1101 // set Receive off and Transmitt on
ELECHOUSE_cc1101.SetTx(receiveMhz);
@@ -235,7 +235,7 @@ void MQTTtoRF(char* topicOri, char* datacallback) {
}
# endif
# ifdef jsonReceiving
# if jsonReceiving
void MQTTtoRF(char* topicOri, JsonObject& RFdata) { // json object decoding
if (cmpToMainTopic(topicOri, subjectMQTTtoRF)) {
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;
}
# ifdef simpleReceiving
# if simpleReceiving
void MQTTtoRF2(char* topicOri, char* datacallback) {
# ifdef ZradioCC1101
NewRemoteReceiver::disable();
@@ -258,7 +258,7 @@ void MQTTtoRF2(char* topicOri, char* datacallback) {
}
# endif
# ifdef jsonReceiving
# if jsonReceiving
void MQTTtoRF2(char* topicOri, JsonObject& RF2data) { // json object decoding
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) {
if (cmpToMainTopic(topicOri, subjectMQTTtoRFM69)) {
Log.trace(F("MQTTtoRFM69 data analysis" CR));
@@ -204,7 +204,7 @@ void MQTTtoRFM69(char* topicOri, char* datacallback) {
}
}
# endif
# ifdef jsonReceiving
# if jsonReceiving
void MQTTtoRFM69(char* topicOri, JsonObject& RFM69data) {
if (cmpToMainTopic(topicOri, subjectMQTTtoRFM69)) {
const char* data = RFM69data["data"];
+2 -2
View File
@@ -166,7 +166,7 @@ bool _rfbToChar(byte* in, char* out) {
return true;
}
# ifdef simpleReceiving
# if simpleReceiving
void MQTTtoSRFB(char* topicOri, char* datacallback) {
// RF DATA ANALYSIS
String topic = topicOri;
@@ -262,7 +262,7 @@ void MQTTtoSRFB(char* topicOri, char* datacallback) {
}
}
# endif
# ifdef jsonReceiving
# if jsonReceiving
void MQTTtoSRFB(char* topicOri, JsonObject& SRFBdata) {
// RF DATA ANALYSIS
const char* raw = SRFBdata["raw"];
+4 -4
View File
@@ -328,12 +328,12 @@ void pub(const char* topicori, JsonObject& data) {
# endif
#endif
#ifdef jsonPublishing
#if jsonPublishing
Log.trace(F("jsonPubl - ON" CR));
pubMQTT(topic, dataAsString.c_str());
#endif
#ifdef simplePublishing
#if simplePublishing
Log.trace(F("simplePub - ON" CR));
// Loop through all the key-value pairs in obj
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
MQTTtoRTL_433(topicOri, jsondata);
#endif
#ifdef jsonReceiving
#if jsonReceiving
# ifdef ZgatewayLORA
MQTTtoLORA(topicOri, jsondata);
# endif
@@ -1747,7 +1747,7 @@ void receivingMQTT(char* topicOri, char* datacallback) {
MQTTtoSYS(topicOri, jsondata);
} else { // not a json object --> simple decoding
#ifdef simpleReceiving
#if simpleReceiving
# ifdef ZgatewayLORA
MQTTtoLORA(topicOri, datacallback);
# endif
+1 -4
View File
@@ -144,8 +144,6 @@ lib_deps =
${libraries.arduinolog}
build_flags =
-w ; supress all warnings
'-DjsonPublishing=true'
'-DjsonReceiving=true'
; '-DLOG_LEVEL=LOG_LEVEL_TRACE' ; Enable trace level logging
monitor_speed = 115200
@@ -159,7 +157,6 @@ lib_deps =
${env.lib_deps}
build_flags =
${env.build_flags}
'-DsimpleReceiving=true'
'-DZmqttDiscovery="HADiscovery"'
'-DTRACE=1'
'-DCONFIG_BT_NIMBLE_ROLE_PERIPHERAL_DISABLED'
@@ -174,7 +171,6 @@ lib_deps =
${libraries.ethernet}
build_flags =
${env.build_flags}
'-DsimpleReceiving=true'
'-DZmqttDiscovery="HADiscovery"'
'-DTRACE=1'
@@ -184,6 +180,7 @@ lib_deps =
${libraries.ethernet}
build_flags =
${env.build_flags}
'-DsimpleReceiving=false'
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; ENVIRONMENTS LIST ;