Merge pull request #17041 from s-hadinger/func_network_up

Added ``FUNC_NETWORK_UP`` and ``FUNC_NETWORK_DOWN`` events
This commit is contained in:
Theo Arends 2022-11-11 11:39:29 +01:00 committed by GitHub
commit 082380a800
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
11 changed files with 87 additions and 43 deletions

2
API.md
View File

@ -51,6 +51,8 @@ FUNC_SET_CHANNELS | | 2 | | | 1 |
FUNC_SET_SCHEME | | | | | x |
FUNC_HOTPLUG_SCAN | | | x | | |
FUNC_DEVICE_GROUP_ITEM | | x | | | |
FUNC_NETWORK_UP | | 1 | 2 | 3 | 4 | Wifi or ETH network just went up (received even if webserver is not enabled)
FUNC_NETWORK_DOWN | | 1 | 2 | 3 | 4 | Wifi or ETH network just went down (received even if webserver is not enabled)
The numbers represent the sequence of execution

View File

@ -7,6 +7,7 @@ All notable changes to this project will be documented in this file.
### Added
- Support for Plantower PMSx003T AQI models with temperature and humidity (#16971)
- Support for Dingtian x595/x165 shift register based relay boards by Barbudor (#17032)
- Added ``FUNC_NETWORK_UP`` and ``FUNC_NETWORK_DOWN`` events
### Breaking Changed

View File

@ -387,7 +387,8 @@ enum XsnsFunctions {FUNC_SETTINGS_OVERRIDE, FUNC_PIN_STATE, FUNC_I2C_INIT, FUNC_
FUNC_RULES_PROCESS, FUNC_TELEPERIOD_RULES_PROCESS, FUNC_SERIAL, FUNC_FREE_MEM, FUNC_BUTTON_PRESSED, FUNC_BUTTON_MULTI_PRESSED,
FUNC_WEB_ADD_BUTTON, FUNC_WEB_ADD_CONSOLE_BUTTON, FUNC_WEB_ADD_MANAGEMENT_BUTTON, FUNC_WEB_ADD_MAIN_BUTTON,
FUNC_WEB_GET_ARG, FUNC_WEB_ADD_HANDLER, FUNC_SET_CHANNELS, FUNC_SET_SCHEME, FUNC_HOTPLUG_SCAN, FUNC_TIME_SYNCED,
FUNC_DEVICE_GROUP_ITEM };
FUNC_DEVICE_GROUP_ITEM,
FUNC_NETWORK_UP, FUNC_NETWORK_DOWN };
enum AddressConfigSteps { ADDR_IDLE, ADDR_RECEIVE, ADDR_SEND };

View File

@ -21,10 +21,6 @@ extern "C" {
extern struct rst_info resetInfo;
}
#ifdef USE_KNX
bool knx_started = false;
#endif // USE_KNX
/*********************************************************************************************\
* Watchdog extension (https://github.com/esp8266/Arduino/issues/1532)
\*********************************************************************************************/

View File

@ -1569,76 +1569,79 @@ void Every250mSeconds(void)
WifiDisable();
}
break;
case 3: // Every x.75 second
if (!TasmotaGlobal.global_state.network_down) {
case 3:
{
// is there a network state change since last time, if so send events to modules
static bool network_was_down = true; // keep track of the previous state of network
bool network_state_changed = (network_was_down != (bool)TasmotaGlobal.global_state.network_down); // network state changed from last tick
network_was_down = TasmotaGlobal.global_state.network_down;
if (!TasmotaGlobal.global_state.network_down) {
#ifdef FIRMWARE_MINIMAL
#ifdef CONFIG_IDF_TARGET_ESP32C3
if (OtaFactoryRead()) {
OtaFactoryWrite(false);
TasmotaGlobal.ota_state_flag = 3;
}
if (OtaFactoryRead()) {
OtaFactoryWrite(false);
TasmotaGlobal.ota_state_flag = 3;
}
#endif
if (1 == RtcSettings.ota_loader) {
RtcSettings.ota_loader = 0;
TasmotaGlobal.ota_state_flag = 3;
}
if (1 == RtcSettings.ota_loader) {
RtcSettings.ota_loader = 0;
TasmotaGlobal.ota_state_flag = 3;
}
#endif // FIRMWARE_MINIMAL
#ifdef USE_DISCOVERY
StartMdns();
StartMdns();
#endif // USE_DISCOVERY
#ifdef USE_WEBSERVER
if (Settings->webserver) {
if (Settings->webserver) {
#ifdef ESP8266
if (!WifiIsInManagerMode()) { StartWebserver(Settings->webserver, WiFi.localIP()); }
if (!WifiIsInManagerMode()) { StartWebserver(Settings->webserver, WiFi.localIP()); }
#endif // ESP8266
#ifdef ESP32
#ifdef USE_ETHERNET
StartWebserver(Settings->webserver, (EthernetLocalIP()) ? EthernetLocalIP() : WiFi.localIP());
StartWebserver(Settings->webserver, (EthernetLocalIP()) ? EthernetLocalIP() : WiFi.localIP());
#else
StartWebserver(Settings->webserver, WiFi.localIP());
StartWebserver(Settings->webserver, WiFi.localIP());
#endif
#endif // ESP32
#ifdef USE_DISCOVERY
#ifdef WEBSERVER_ADVERTISE
MdnsAddServiceHttp();
MdnsAddServiceHttp();
#endif // WEBSERVER_ADVERTISE
#endif // USE_DISCOVERY
} else {
StopWebserver();
}
#ifdef USE_EMULATION
if (Settings->flag2.emulation) { UdpConnect(); }
#endif // USE_EMULATION
} else {
StopWebserver();
}
#endif // USE_WEBSERVER
#ifdef USE_DEVICE_GROUPS
DeviceGroupsStart();
DeviceGroupsStart();
#endif // USE_DEVICE_GROUPS
#ifdef USE_KNX
if (!knx_started && Settings->flag.knx_enabled) { // CMND_KNX_ENABLED
KNXStart();
knx_started = true;
}
#endif // USE_KNX
// send FUNC_NETWORK_UP to all modules
if (network_state_changed) {
// AddLog(LOG_LEVEL_DEBUG_MORE, PSTR("WIF: Sending FUNC_NETWORK_UP"));
XdrvXsnsCall(FUNC_NETWORK_UP);
}
MqttCheck();
} else {
#ifdef USE_EMULATION
UdpDisconnect();
#endif // USE_EMULATION
MqttCheck();
} else {
#ifdef USE_DEVICE_GROUPS
DeviceGroupsStop();
DeviceGroupsStop();
#endif // USE_DEVICE_GROUPS
#ifdef USE_KNX
knx_started = false;
#endif // USE_KNX
// send FUNC_NETWORK_UP to all modules
if (network_state_changed) {
// AddLog(LOG_LEVEL_DEBUG_MORE, PSTR("WIF: Sending FUNC_NETWORK_DOWN"));
XdrvXsnsCall(FUNC_NETWORK_DOWN);
}
} // Every x.75 second
}
break;
}

View File

@ -1415,6 +1415,12 @@ bool Xdrv03(uint32_t function)
case FUNC_COMMAND:
result = DecodeCommand(kEnergyCommands, EnergyCommand);
break;
case FUNC_NETWORK_UP:
XnrgCall(FUNC_NETWORK_UP);
break;
case FUNC_NETWORK_DOWN:
XnrgCall(FUNC_NETWORK_DOWN);
break;
}
}
return result;

View File

@ -3428,6 +3428,12 @@ bool Xdrv04(uint32_t function)
case FUNC_BUTTON_MULTI_PRESSED:
result = XlgtCall(FUNC_BUTTON_MULTI_PRESSED);
break;
case FUNC_NETWORK_UP:
XlgtCall(FUNC_NETWORK_UP);
break;
case FUNC_NETWORK_DOWN:
XlgtCall(FUNC_NETWORK_DOWN);
break;
#ifdef USE_WEBSERVER
case FUNC_WEB_ADD_MAIN_BUTTON:
XlgtCall(FUNC_WEB_ADD_MAIN_BUTTON);

View File

@ -52,6 +52,8 @@ uint8_t Settings->knx_CB_param[MAX_KNX_CB] Type of Output (set relay,
#include <esp-knx-ip.h> // KNX Library
bool knx_started = false;
address_t KNX_physs_addr; // Physical KNX address of this device
address_t KNX_addr; // KNX Address converter variable
@ -1329,6 +1331,15 @@ bool Xdrv11(uint32_t function)
case FUNC_PRE_INIT:
KNX_INIT();
break;
case FUNC_NETWORK_UP:
if (!knx_started && Settings->flag.knx_enabled) { // CMND_KNX_ENABLED
KNXStart();
knx_started = true;
}
break;
case FUNC_NETWORK_DOWN:
knx_started = false;
break;
// case FUNC_SET_POWER:
// break;
}

View File

@ -1162,6 +1162,12 @@ bool Xdrv20(uint32_t function)
case FUNC_WEB_ADD_HANDLER:
WebServer_on(PSTR("/description.xml"), HandleUpnpSetupHue);
break;
case FUNC_NETWORK_UP:
UdpConnect();
break;
case FUNC_NETWORK_DOWN:
UdpDisconnect();
break;
}
}
return result;

View File

@ -354,6 +354,12 @@ bool Xdrv21(uint32_t function)
WebServer_on(PSTR("/metainfoservice.xml"), HandleUpnpMetaService);
WebServer_on(PSTR("/setup.xml"), HandleUpnpSetupWemo);
break;
case FUNC_NETWORK_UP:
UdpConnect();
break;
case FUNC_NETWORK_DOWN:
UdpDisconnect();
break;
}
}
return result;

View File

@ -453,6 +453,12 @@ bool Xdrv21(uint32_t function)
numOfWemoSwitch++;
}
break;
case FUNC_NETWORK_UP:
UdpConnect();
break;
case FUNC_NETWORK_DOWN:
UdpDisconnect();
break;
}
}
return result;