Save currently active receiver and restore on reboot (#1091)

* save active receiver and restore on reboot

Co-authored-by: Kern, Thomas <thomas@kernwelt.de>
This commit is contained in:
Thomas KernandKern, Thomas authored and GitHub committed 2021-10-29 16:53:05 -05:00
1 parent e9ce921717
commit c5f7a3a55e
6 files changed
+34 -6

No files matched your search

+1 -1
View File
@@ -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);
}
}
+1 -1
View File
@@ -292,7 +292,7 @@ void MQTTtoRF(char* topicOri, JsonObject& RFdata) { // json object decoding
Log.error(F("MQTTtoRF Fail json" CR));
}
}
enableActiveReceiver();
enableActiveReceiver(false);
}
}
# endif
+1 -1
View File
@@ -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
+1 -1
View File
@@ -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);
}
}
+29 -1
View File
@@ -29,6 +29,10 @@
#include <Arduino.h>
#include <ArduinoJson.h>
#if defined(ESP8266) || defined(ESP32)
# include <EEPROM.h>
#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) {
+1 -1
View File
@@ -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);