From eb9617e3f91ad1f0075b7ebd42b094825765d924 Mon Sep 17 00:00:00 2001 From: Theo Arends <11044339+arendst@users.noreply.github.com> Date: Sat, 30 Mar 2019 13:03:45 +0100 Subject: [PATCH] Tune some functionality Tune some functionality --- sonoff/xdrv_01_webserver.ino | 2 +- sonoff/xdrv_02_mqtt.ino | 15 +++++---------- sonoff/xdrv_03_energy.ino | 6 +++--- sonoff/xdrv_08_serial_bridge.ino | 6 +++--- sonoff/xdrv_11_knx.ino | 6 +++--- sonoff/xdrv_16_tuyadimmer.ino | 6 +++--- sonoff/xdrv_18_armtronix_dimmers.ino | 6 +++--- sonoff/xdrv_19_ps16dz_dimmer.ino | 6 +++--- sonoff/xdrv_99_debug.ino | 6 +++--- sonoff/xnrg_04_mcp39f501.ino | 6 +++--- 10 files changed, 30 insertions(+), 35 deletions(-) diff --git a/sonoff/xdrv_01_webserver.ino b/sonoff/xdrv_01_webserver.ino index 48932fb0d..eb58081ee 100644 --- a/sonoff/xdrv_01_webserver.ino +++ b/sonoff/xdrv_01_webserver.ino @@ -2355,7 +2355,7 @@ bool Xdrv01(uint8_t function) case FUNC_LOOP: PollDnsWebserver(); #ifdef USE_EMULATION - if (Settings.flag2.emulation) PollUdp(); + if (Settings.flag2.emulation) { PollUdp(); } #endif // USE_EMULATION break; case FUNC_COMMAND: diff --git a/sonoff/xdrv_02_mqtt.ino b/sonoff/xdrv_02_mqtt.ino index b4228b11e..dda79790c 100644 --- a/sonoff/xdrv_02_mqtt.ino +++ b/sonoff/xdrv_02_mqtt.ino @@ -50,7 +50,6 @@ bool mqtt_allowed = false; // MQTT enabled and parameters valid * void MqttDisconnect() * void MqttSubscribeLib(char *topic) * bool MqttPublishLib(const char* topic, bool retained) - * void MqttLoop() \*********************************************************************************************/ #include @@ -91,11 +90,6 @@ bool MqttPublishLib(const char* topic, bool retained) return result; } -void MqttLoop(void) -{ - MqttClient.loop(); -} - /*********************************************************************************************/ #ifdef USE_DISCOVERY @@ -425,7 +419,8 @@ void MqttReconnect(void) UdpDisconnect(); #endif // USE_EMULATION - AddLog_P(LOG_LEVEL_INFO, S_LOG_MQTT, PSTR(D_ATTEMPTING_CONNECTION)); +// AddLog_P(LOG_LEVEL_INFO, S_LOG_MQTT, PSTR(D_ATTEMPTING_CONNECTION)); + AddLog_P2(LOG_LEVEL_INFO, PSTR(D_LOG_MQTT "(%d) " D_ATTEMPTING_CONNECTION), ESP.getFreeHeap()/1024); mqtt_connected = false; mqtt_retry_counter = Settings.mqtt_retry; @@ -816,6 +811,9 @@ bool Xdrv02(uint8_t function) if (Settings.flag.mqtt_enabled) { switch (function) { + case FUNC_LOOP: + if (MqttIsConnected()) { MqttClient.loop(); } + break; #ifdef USE_WEBSERVER case FUNC_WEB_ADD_BUTTON: WSContentSend_P(HTTP_BTN_MENU_MQTT); @@ -824,9 +822,6 @@ bool Xdrv02(uint8_t function) WebServer->on("/" WEB_HANDLE_MQTT, HandleMqttConfiguration); break; #endif // USE_WEBSERVER - case FUNC_LOOP: - if (!global_state.mqtt_down) { MqttLoop(); } - break; case FUNC_COMMAND: result = MqttCommand(); break; diff --git a/sonoff/xdrv_03_energy.ino b/sonoff/xdrv_03_energy.ino index 69d93b244..c1c65eafe 100644 --- a/sonoff/xdrv_03_energy.ino +++ b/sonoff/xdrv_03_energy.ino @@ -689,15 +689,15 @@ bool Xdrv03(uint8_t function) } else if (energy_flg) { switch (function) { + case FUNC_LOOP: + XnrgCall(FUNC_LOOP); + break; case FUNC_COMMAND: result = EnergyCommand(); break; case FUNC_SET_POWER: EnergySetPowerSteadyCounter(); break; - case FUNC_LOOP: - XnrgCall(FUNC_LOOP); - break; case FUNC_SERIAL: result = XnrgCall(FUNC_SERIAL); break; diff --git a/sonoff/xdrv_08_serial_bridge.ino b/sonoff/xdrv_08_serial_bridge.ino index e9f8294ca..fbad30683 100644 --- a/sonoff/xdrv_08_serial_bridge.ino +++ b/sonoff/xdrv_08_serial_bridge.ino @@ -172,12 +172,12 @@ bool Xdrv08(uint8_t function) if (serial_bridge_active) { switch (function) { - case FUNC_PRE_INIT: - SerialBridgeInit(); - break; case FUNC_LOOP: if (SerialBridgeSerial) { SerialBridgeInput(); } break; + case FUNC_PRE_INIT: + SerialBridgeInit(); + break; case FUNC_COMMAND: result = SerialBridgeCommand(); break; diff --git a/sonoff/xdrv_11_knx.ino b/sonoff/xdrv_11_knx.ino index b92ed1c7b..c4111bae3 100644 --- a/sonoff/xdrv_11_knx.ino +++ b/sonoff/xdrv_11_knx.ino @@ -1223,6 +1223,9 @@ bool Xdrv11(uint8_t function) { bool result = false; switch (function) { + case FUNC_LOOP: + if (!global_state.wifi_down) { knx.loop(); } // Process knx events + break; case FUNC_PRE_INIT: KNX_INIT(); break; @@ -1236,9 +1239,6 @@ bool Xdrv11(uint8_t function) break; #endif // USE_KNX_WEB_MENU #endif // USE_WEBSERVER - case FUNC_LOOP: - if (!global_state.wifi_down) { knx.loop(); } // Process knx events - break; case FUNC_EVERY_50_MSECOND: if (toggle_inhibit) { toggle_inhibit--; diff --git a/sonoff/xdrv_16_tuyadimmer.ino b/sonoff/xdrv_16_tuyadimmer.ino index f9b3665e4..d43e6397e 100644 --- a/sonoff/xdrv_16_tuyadimmer.ino +++ b/sonoff/xdrv_16_tuyadimmer.ino @@ -393,15 +393,15 @@ bool Xdrv16(uint8_t function) if (TUYA_DIMMER == my_module_type) { switch (function) { + case FUNC_LOOP: + if (TuyaSerial) { TuyaSerialInput(); } + break; case FUNC_MODULE_INIT: result = TuyaModuleSelected(); break; case FUNC_INIT: TuyaInit(); break; - case FUNC_LOOP: - if (TuyaSerial) { TuyaSerialInput(); } - break; case FUNC_SET_DEVICE_POWER: result = TuyaSetPower(); break; diff --git a/sonoff/xdrv_18_armtronix_dimmers.ino b/sonoff/xdrv_18_armtronix_dimmers.ino index 30af12ce7..79645bdf9 100644 --- a/sonoff/xdrv_18_armtronix_dimmers.ino +++ b/sonoff/xdrv_18_armtronix_dimmers.ino @@ -170,15 +170,15 @@ bool Xdrv18(uint8_t function) if (ARMTRONIX_DIMMERS == my_module_type) { switch (function) { + case FUNC_LOOP: + if (ArmtronixSerial) { ArmtronixSerialInput(); } + break; case FUNC_MODULE_INIT: result = ArmtronixModuleSelected(); break; case FUNC_INIT: ArmtronixInit(); break; - case FUNC_LOOP: - if (ArmtronixSerial) { ArmtronixSerialInput(); } - break; case FUNC_EVERY_SECOND: if (ArmtronixSerial) { if (armtronix_wifi_state!=WifiState()) { ArmtronixSetWifiLed(); } diff --git a/sonoff/xdrv_19_ps16dz_dimmer.ino b/sonoff/xdrv_19_ps16dz_dimmer.ino index ab58b6d9d..bcca6b0be 100644 --- a/sonoff/xdrv_19_ps16dz_dimmer.ino +++ b/sonoff/xdrv_19_ps16dz_dimmer.ino @@ -223,15 +223,15 @@ bool Xdrv19(uint8_t function) if (PS_16_DZ == my_module_type) { switch (function) { + case FUNC_LOOP: + if (PS16DZSerial) { PS16DZSerialInput(); } + break; case FUNC_MODULE_INIT: result = PS16DZModuleSelected(); break; case FUNC_INIT: PS16DZInit(); break; - case FUNC_LOOP: - if (PS16DZSerial) { PS16DZSerialInput(); } - break; case FUNC_SET_DEVICE_POWER: result = PS16DZSetPower(); break; diff --git a/sonoff/xdrv_99_debug.ino b/sonoff/xdrv_99_debug.ino index 08a73d4da..e3e90a398 100644 --- a/sonoff/xdrv_99_debug.ino +++ b/sonoff/xdrv_99_debug.ino @@ -497,12 +497,12 @@ bool Xdrv99(uint8_t function) bool result = false; switch (function) { - case FUNC_PRE_INIT: - CPU_last_millis = millis(); - break; case FUNC_LOOP: CpuLoadLoop(); break; + case FUNC_PRE_INIT: + CPU_last_millis = millis(); + break; case FUNC_COMMAND: result = DebugCommand(); break; diff --git a/sonoff/xnrg_04_mcp39f501.ino b/sonoff/xnrg_04_mcp39f501.ino index 5d6adec33..5441a45ca 100644 --- a/sonoff/xnrg_04_mcp39f501.ino +++ b/sonoff/xnrg_04_mcp39f501.ino @@ -652,12 +652,12 @@ int Xnrg04(uint8_t function) } else if (XNRG_04 == energy_flg) { switch (function) { - case FUNC_INIT: - McpSnsInit(); - break; case FUNC_LOOP: if (McpSerial) { McpSerialInput(); } break; + case FUNC_INIT: + McpSnsInit(); + break; case FUNC_EVERY_SECOND: if (McpSerial) { McpEverySecond(); } break;