diff --git a/main/ZgatewayPilight.ino b/main/ZgatewayPilight.ino index d622df7..a998376 100644 --- a/main/ZgatewayPilight.ino +++ b/main/ZgatewayPilight.ino @@ -194,7 +194,7 @@ void MQTTtoPilight(char* topicOri, JsonObject& Pilightdata) { pub(subjectGTWPilighttoMQTT, "{\"Status\": \"Error\"}"); // Fail feedback Log.error(F("MQTTtoPilight Fail json" CR)); } - enableActiveReceiver(); + enableActiveReceiver(false); } } diff --git a/main/ZgatewayRF.ino b/main/ZgatewayRF.ino index c083ff5..a4e8fae 100644 --- a/main/ZgatewayRF.ino +++ b/main/ZgatewayRF.ino @@ -292,7 +292,7 @@ void MQTTtoRF(char* topicOri, JsonObject& RFdata) { // json object decoding Log.error(F("MQTTtoRF Fail json" CR)); } } - enableActiveReceiver(); + enableActiveReceiver(false); } } # endif diff --git a/main/ZgatewayRF2.ino b/main/ZgatewayRF2.ino index d56a8dd..aadab47 100644 --- a/main/ZgatewayRF2.ino +++ b/main/ZgatewayRF2.ino @@ -329,7 +329,7 @@ void MQTTtoRF2(char* topicOri, JsonObject& RF2data) { // json object decoding # endif Log.error(F("MQTTtoRF2 failed json read" CR)); } - enableActiveReceiver(); + enableActiveReceiver(false); } } # endif diff --git a/main/ZgatewayRTL_433.ino b/main/ZgatewayRTL_433.ino index ea39b6a..907a817 100644 --- a/main/ZgatewayRTL_433.ino +++ b/main/ZgatewayRTL_433.ino @@ -116,7 +116,7 @@ extern void MQTTtoRTL_433(char* topicOri, JsonObject& RTLdata) { pub(subjectRTL_433toMQTT, "{\"Status\": \"Error\"}"); // Fail feedback Log.error(F("MQTTtoRTL_433 Fail json" CR)); } - enableActiveReceiver(); + enableActiveReceiver(false); } } diff --git a/main/config_RF.h b/main/config_RF.h index e84f317..e088a5d 100644 --- a/main/config_RF.h +++ b/main/config_RF.h @@ -29,6 +29,10 @@ #include #include +#if defined(ESP8266) || defined(ESP32) +# include +#endif + #ifdef ZgatewayRF extern void setupRF(); extern void RFtoMQTT(); @@ -176,7 +180,31 @@ int currentReceiver = -1; extern void stateMeasures(); // Send a status message -void enableActiveReceiver() { +void enableActiveReceiver(bool isBoot) { +// Save currently active receiver and restore after reboot. +// Only works with ESP and if there is no conflict. +# if !defined(ZgatewayRFM69) && !defined(ZactuatorSomfy) +# if defined(ESP8266) || defined(ESP32) +# define _ACTIVE_RECV_MAGIC 0xA1B2C3D4 + + struct { + uint64_t magic; + int receiver; + } data; + + EEPROM.begin(sizeof(data)); + EEPROM.get(0, data); + if (isBoot && data.magic == _ACTIVE_RECV_MAGIC) { + activeReceiver = data.receiver; + } else { + data.magic = _ACTIVE_RECV_MAGIC; + data.receiver = activeReceiver; + EEPROM.put(0, data); + } + EEPROM.end(); +# endif +# endif + // if (currentReceiver != activeReceiver) { Log.trace(F("enableActiveReceiver: %d" CR), activeReceiver); switch (activeReceiver) { diff --git a/main/main.ino b/main/main.ino index 6b22296..da769ba 100644 --- a/main/main.ino +++ b/main/main.ino @@ -794,7 +794,7 @@ void setup() { # else activeReceiver = ACTIVE_RECEIVER; # endif - enableActiveReceiver(); + enableActiveReceiver(true); #endif Log.trace(F("mqtt_max_packet_size: %d" CR), mqtt_max_packet_size);