mirror of
https://github.com/arendst/Tasmota.git
synced 2025-04-25 23:37:16 +00:00
Add rule triggers
Add rule triggers Wifi#Connected and Wifi#Disconnected (#3359)
This commit is contained in:
parent
b7ccc64893
commit
da7dadae21
@ -1,4 +1,5 @@
|
|||||||
/* 6.1.1c
|
/* 6.1.1c
|
||||||
|
* Add rule triggers Wifi#Connected and Wifi#Disconnected (#3359)
|
||||||
* Fix unsecure main webpage update
|
* Fix unsecure main webpage update
|
||||||
* Add Turkish language file (#3332)
|
* Add Turkish language file (#3332)
|
||||||
* Fix command TimeDst/TimeStd invalid JSON (#3322)
|
* Fix command TimeDst/TimeStd invalid JSON (#3322)
|
||||||
|
@ -369,7 +369,7 @@ struct XDRVMAILBOX {
|
|||||||
char *data;
|
char *data;
|
||||||
} XdrvMailbox;
|
} XdrvMailbox;
|
||||||
|
|
||||||
#define MAX_RULES_FLAG 5 // Number of bits used in RulesBitfield (tricky I know...)
|
#define MAX_RULES_FLAG 7 // Number of bits used in RulesBitfield (tricky I know...)
|
||||||
typedef union { // Restricted by MISRA-C Rule 18.4 but so usefull...
|
typedef union { // Restricted by MISRA-C Rule 18.4 but so usefull...
|
||||||
uint16_t data; // Allow bit manipulation
|
uint16_t data; // Allow bit manipulation
|
||||||
struct {
|
struct {
|
||||||
@ -378,8 +378,8 @@ typedef union { // Restricted by MISRA-C Rule 18.4 bu
|
|||||||
uint16_t time_set : 1;
|
uint16_t time_set : 1;
|
||||||
uint16_t mqtt_connected : 1;
|
uint16_t mqtt_connected : 1;
|
||||||
uint16_t mqtt_disconnected : 1;
|
uint16_t mqtt_disconnected : 1;
|
||||||
uint16_t spare05 : 1;
|
uint16_t wifi_connected : 1;
|
||||||
uint16_t spare06 : 1;
|
uint16_t wifi_disconnected : 1;
|
||||||
uint16_t spare07 : 1;
|
uint16_t spare07 : 1;
|
||||||
uint16_t spare08 : 1;
|
uint16_t spare08 : 1;
|
||||||
uint16_t spare09 : 1;
|
uint16_t spare09 : 1;
|
||||||
|
@ -1096,10 +1096,22 @@ void WifiBegin(uint8_t flag)
|
|||||||
AddLog(LOG_LEVEL_INFO);
|
AddLog(LOG_LEVEL_INFO);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void WifiState(uint8_t state)
|
||||||
|
{
|
||||||
|
if (state == global_state.wifi_down) {
|
||||||
|
if (state) {
|
||||||
|
rules_flag.wifi_connected = 1;
|
||||||
|
} else {
|
||||||
|
rules_flag.wifi_disconnected = 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
global_state.wifi_down = state ^1;
|
||||||
|
}
|
||||||
|
|
||||||
void WifiCheckIp()
|
void WifiCheckIp()
|
||||||
{
|
{
|
||||||
if ((WL_CONNECTED == WiFi.status()) && (static_cast<uint32_t>(WiFi.localIP()) != 0)) {
|
if ((WL_CONNECTED == WiFi.status()) && (static_cast<uint32_t>(WiFi.localIP()) != 0)) {
|
||||||
global_state.wifi_down = 0;
|
WifiState(1);
|
||||||
wifi_counter = WIFI_CHECK_SEC;
|
wifi_counter = WIFI_CHECK_SEC;
|
||||||
wifi_retry = wifi_retry_init;
|
wifi_retry = wifi_retry_init;
|
||||||
AddLog_P((wifi_status != WL_CONNECTED) ? LOG_LEVEL_INFO : LOG_LEVEL_DEBUG_MORE, S_LOG_WIFI, PSTR(D_CONNECTED));
|
AddLog_P((wifi_status != WL_CONNECTED) ? LOG_LEVEL_INFO : LOG_LEVEL_DEBUG_MORE, S_LOG_WIFI, PSTR(D_CONNECTED));
|
||||||
@ -1111,7 +1123,7 @@ void WifiCheckIp()
|
|||||||
}
|
}
|
||||||
wifi_status = WL_CONNECTED;
|
wifi_status = WL_CONNECTED;
|
||||||
} else {
|
} else {
|
||||||
global_state.wifi_down = 1;
|
WifiState(0);
|
||||||
uint8_t wifi_config_tool = Settings.sta_config;
|
uint8_t wifi_config_tool = Settings.sta_config;
|
||||||
wifi_status = WiFi.status();
|
wifi_status = WiFi.status();
|
||||||
switch (wifi_status) {
|
switch (wifi_status) {
|
||||||
@ -1222,7 +1234,7 @@ void WifiCheck(uint8_t param)
|
|||||||
WifiCheckIp();
|
WifiCheckIp();
|
||||||
}
|
}
|
||||||
if ((WL_CONNECTED == WiFi.status()) && (static_cast<uint32_t>(WiFi.localIP()) != 0) && !wifi_config_type) {
|
if ((WL_CONNECTED == WiFi.status()) && (static_cast<uint32_t>(WiFi.localIP()) != 0) && !wifi_config_type) {
|
||||||
global_state.wifi_down = 0;
|
WifiState(1);
|
||||||
#ifdef BE_MINIMAL
|
#ifdef BE_MINIMAL
|
||||||
if (1 == RtcSettings.ota_loader) {
|
if (1 == RtcSettings.ota_loader) {
|
||||||
RtcSettings.ota_loader = 0;
|
RtcSettings.ota_loader = 0;
|
||||||
@ -1258,7 +1270,7 @@ void WifiCheck(uint8_t param)
|
|||||||
}
|
}
|
||||||
#endif // USE_KNX
|
#endif // USE_KNX
|
||||||
} else {
|
} else {
|
||||||
global_state.wifi_down = 1;
|
WifiState(0);
|
||||||
#if defined(USE_WEBSERVER) && defined(USE_EMULATION)
|
#if defined(USE_WEBSERVER) && defined(USE_EMULATION)
|
||||||
UdpDisconnect();
|
UdpDisconnect();
|
||||||
#endif // USE_EMULATION
|
#endif // USE_EMULATION
|
||||||
|
@ -432,6 +432,8 @@ void RulesEvery50ms()
|
|||||||
case 2: snprintf_P(json_event, sizeof(json_event), PSTR("{\"Time\":{\"Set\":%d}}"), GetMinutesPastMidnight()); break;
|
case 2: snprintf_P(json_event, sizeof(json_event), PSTR("{\"Time\":{\"Set\":%d}}"), GetMinutesPastMidnight()); break;
|
||||||
case 3: strncpy_P(json_event, PSTR("{\"MQTT\":{\"Connected\":1}}"), sizeof(json_event)); break;
|
case 3: strncpy_P(json_event, PSTR("{\"MQTT\":{\"Connected\":1}}"), sizeof(json_event)); break;
|
||||||
case 4: strncpy_P(json_event, PSTR("{\"MQTT\":{\"Disconnected\":1}}"), sizeof(json_event)); break;
|
case 4: strncpy_P(json_event, PSTR("{\"MQTT\":{\"Disconnected\":1}}"), sizeof(json_event)); break;
|
||||||
|
case 5: strncpy_P(json_event, PSTR("{\"WIFI\":{\"Connected\":1}}"), sizeof(json_event)); break;
|
||||||
|
case 6: strncpy_P(json_event, PSTR("{\"WIFI\":{\"Disconnected\":1}}"), sizeof(json_event)); break;
|
||||||
}
|
}
|
||||||
if (json_event[0]) {
|
if (json_event[0]) {
|
||||||
RulesProcessEvent(json_event);
|
RulesProcessEvent(json_event);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user