Skip to content

Commit

Permalink
Publishing/receiving inconsistencies fix (#1229)
Browse files Browse the repository at this point in the history
* 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.
  • Loading branch information
DigiH authored Jul 1, 2022
1 parent 3bd1d31 commit a388f14
Show file tree
Hide file tree
Showing 15 changed files with 39 additions and 40 deletions.
16 changes: 7 additions & 9 deletions docs/upload/builds.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
```
Expand Down Expand Up @@ -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]
Expand All @@ -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.

Expand Down Expand Up @@ -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`:
Expand Down
12 changes: 8 additions & 4 deletions main/User_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions main/ZactuatorFASTLED.ino
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ void FASTLEDLoop() {
boolean FASTLEDtoMQTT() {
return false;
}
# ifdef jsonReceiving
# if jsonReceiving
void MQTTtoFASTLED(char* topicOri, JsonObject& jsonData) {
currentLEDState = GENERAL;
//trc(topicOri);
Expand All @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions main/ZactuatorONOFF.ino
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down Expand Up @@ -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));
Expand Down
2 changes: 1 addition & 1 deletion main/ZactuatorPWM.ino
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
2 changes: 1 addition & 1 deletion main/ZactuatorSomfy.ino
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions main/Zgateway2G.ino
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ bool _2GtoMQTT() {
}
return false;
}
# ifdef simpleReceiving
# if simpleReceiving
void MQTTto2G(char* topicOri, char* datacallback) {
String data = datacallback;
String topic = topicOri;
Expand Down Expand Up @@ -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"];
Expand Down
2 changes: 1 addition & 1 deletion main/ZgatewayIR.ino
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
4 changes: 2 additions & 2 deletions main/ZgatewayLORA.ino
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down Expand Up @@ -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();
Expand Down
4 changes: 2 additions & 2 deletions main/ZgatewayRF.ino
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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));
Expand Down
4 changes: 2 additions & 2 deletions main/ZgatewayRF2.ino
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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)) {
Expand Down
4 changes: 2 additions & 2 deletions main/ZgatewayRFM69.ino
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down Expand Up @@ -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"];
Expand Down
4 changes: 2 additions & 2 deletions main/ZgatewaySRFB.ino
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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"];
Expand Down
8 changes: 4 additions & 4 deletions main/main.ino
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
5 changes: 1 addition & 4 deletions platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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'
Expand All @@ -174,7 +171,6 @@ lib_deps =
${libraries.ethernet}
build_flags =
${env.build_flags}
'-DsimpleReceiving=true'
'-DZmqttDiscovery="HADiscovery"'
'-DTRACE=1'

Expand All @@ -184,6 +180,7 @@ lib_deps =
${libraries.ethernet}
build_flags =
${env.build_flags}
'-DsimpleReceiving=false'

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; ENVIRONMENTS LIST ;
Expand Down

0 comments on commit a388f14

Please sign in to comment.