|
@@ -38,9 +38,6 @@
|
|
|
|
|
|
#define CLEARCONF_TOKEN "TUES"
|
|
|
|
|
|
-#define MAIN_SLEEP 10
|
|
|
-
|
|
|
-
|
|
|
// pin assignments, total relais/button count and default logic levels
|
|
|
// can only be changed at compile time here
|
|
|
// only use GPIO 0, 2, 4, 5, 12, 13, 14 !!
|
|
@@ -129,18 +126,15 @@ int buttonHoldTime = BUTTON_HOLD_TIME;
|
|
|
boolean relais_enabled[3] = {true, false, false};
|
|
|
boolean button_enabled[3] = {true, false, false};
|
|
|
boolean led_enabled[3] = {false, false, false};
|
|
|
-int sleep = MAIN_SLEEP;
|
|
|
byte hldToRel[3] = {0, 0, 0};
|
|
|
|
|
|
// global variables
|
|
|
long mqttLastReconnectAttempt = 0;
|
|
|
int mqttReconnects = 0;
|
|
|
boolean relais_state[RELAIS_COUNT];
|
|
|
-
|
|
|
byte relais_pins[3];
|
|
|
byte buttons_pins[3];
|
|
|
byte leds_pins[3];
|
|
|
-
|
|
|
boolean useDomoticz = false; // will be set to true in setup() if idx-values other than 0 are configured
|
|
|
boolean domoticzOutParseData = false; // indicates that domoticz/out json data is buffered, will then be parsed in next loop() run
|
|
|
boolean domoticzOutParserBusy = false; // indicates that domoticz/out json data is currently processed - no futher data will be accepted until finished
|
|
@@ -149,14 +143,11 @@ boolean updateDomoticz[3] = { true, true, true }; // flag to update domoticz for
|
|
|
byte lastSwitchSource[3] = {0, 0, 0}; // 0 = button, 1 = serial/mqtt cmd, 2 = web, 3 = domoticz/out
|
|
|
unsigned long lastSwitchTime[3] = { 0, 0, 0 }; // this is set to millis() when relais was toggled by button or web. domoticz/out updates for this Idx are then filtered out for [dismissUpdateFromDomoticzTimeout]
|
|
|
int dismissUpdateFromDomoticzTimeout = 1500;
|
|
|
-
|
|
|
char cmdPayload[101]; // buffer for commands
|
|
|
boolean cmdInQueue = false; // command is queued and will be processed next loop() run
|
|
|
-
|
|
|
bool saveConfigToFlash = false;
|
|
|
bool saveConfig2ToFlash = false;
|
|
|
bool saveConfigHwToFlash = false;
|
|
|
-
|
|
|
byte mqttMode = 0;
|
|
|
|
|
|
WiFiClient espClient;
|
|
@@ -364,27 +355,25 @@ void setup() {
|
|
|
|
|
|
void loop() {
|
|
|
checkMillis();
|
|
|
- yield();
|
|
|
|
|
|
persWM.handleWiFi(); //in non-blocking mode, handleWiFi must be called in the main loop
|
|
|
+
|
|
|
yield();
|
|
|
|
|
|
dnsServer.processNextRequest();
|
|
|
- yield();
|
|
|
-
|
|
|
+
|
|
|
httpServer.handleClient();
|
|
|
|
|
|
yield();
|
|
|
|
|
|
mqttHandleConnection();
|
|
|
- yield();
|
|
|
-
|
|
|
+
|
|
|
checkButtonStates();
|
|
|
+
|
|
|
yield();
|
|
|
|
|
|
evalCmd();
|
|
|
- yield();
|
|
|
-
|
|
|
+
|
|
|
if ( domoticzOutParseData ) {
|
|
|
parseDomoticzOut();
|
|
|
yield();
|
|
@@ -395,6 +384,5 @@ void loop() {
|
|
|
yield();
|
|
|
}
|
|
|
|
|
|
- delay(sleep); // save energy by sleeping, 50ms does not affect button and web
|
|
|
} //void loop
|
|
|
|