Add rule triggers

Add rule triggers Wifi#Connected and Wifi#Disconnected (#3359)
This commit is contained in:
Theo Arends 2018-07-28 15:06:31 +02:00
parent b7ccc64893
commit da7dadae21
4 changed files with 23 additions and 8 deletions

View File

@ -1,4 +1,5 @@
/* 6.1.1c
* Add rule triggers Wifi#Connected and Wifi#Disconnected (#3359)
* Fix unsecure main webpage update
* Add Turkish language file (#3332)
* Fix command TimeDst/TimeStd invalid JSON (#3322)

View File

@ -155,7 +155,7 @@ typedef union {
typedef union {
uint8_t data;
struct {
uint8_t pinmode : 3; // Enable INPUT
uint8_t pinmode : 3; // Enable INPUT
uint8_t pullup : 1; // Enable internal weak pull-up resistor
uint8_t b4 : 1;
uint8_t b5 : 1;
@ -369,7 +369,7 @@ struct XDRVMAILBOX {
char *data;
} 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...
uint16_t data; // Allow bit manipulation
struct {
@ -378,8 +378,8 @@ typedef union { // Restricted by MISRA-C Rule 18.4 bu
uint16_t time_set : 1;
uint16_t mqtt_connected : 1;
uint16_t mqtt_disconnected : 1;
uint16_t spare05 : 1;
uint16_t spare06 : 1;
uint16_t wifi_connected : 1;
uint16_t wifi_disconnected : 1;
uint16_t spare07 : 1;
uint16_t spare08 : 1;
uint16_t spare09 : 1;

View File

@ -1096,10 +1096,22 @@ void WifiBegin(uint8_t flag)
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()
{
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_retry = wifi_retry_init;
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;
} else {
global_state.wifi_down = 1;
WifiState(0);
uint8_t wifi_config_tool = Settings.sta_config;
wifi_status = WiFi.status();
switch (wifi_status) {
@ -1222,7 +1234,7 @@ void WifiCheck(uint8_t param)
WifiCheckIp();
}
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
if (1 == RtcSettings.ota_loader) {
RtcSettings.ota_loader = 0;
@ -1258,7 +1270,7 @@ void WifiCheck(uint8_t param)
}
#endif // USE_KNX
} else {
global_state.wifi_down = 1;
WifiState(0);
#if defined(USE_WEBSERVER) && defined(USE_EMULATION)
UdpDisconnect();
#endif // USE_EMULATION

View File

@ -432,6 +432,8 @@ void RulesEvery50ms()
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 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]) {
RulesProcessEvent(json_event);