added wifidisconnect

master
Martin Ger 2018-02-22 09:36:42 +01:00
rodzic 76b14adb37
commit 81a009de8a
7 zmienionych plików z 32 dodań i 7 usunięć

Wyświetl plik

@ -30,7 +30,7 @@ In general, scripts conform to the following BNF:
<statement> <statement>
<event> ::= init |
wificonnect |
wificonnect | wifidisconnect |
mqttconnect |
timer <num> |
alarm <num> |
@ -92,9 +92,9 @@ init
This event happens once after restart of the script. All "config" parameters are applied, but typically WiFi is not yet up and no external nodes are connected. This is typically the clause where the initalization of variables and timers as well as subscriptions to topics on the local broker take place.
```
wificonnect
wificonnect | wifidisconnect
```
This event happens each time, the esp_uMQTT_broker (re-)connects as client to the WiFi and has received an IP address.
This event happens each time, the esp_uMQTT_broker (re-)connects as client to the WiFi and has received an IP address, resp. if it disconnects (tyically due to link loss).
```
mqttconnect

Plik binarny nie jest wyświetlany.

Plik binarny nie jest wyświetlany.

Wyświetl plik

@ -1,2 +1,2 @@
006758f605dad0af543519127a32d340648d0429 0x00000.bin
743f4b2d6048740d41be990bcef8c6cab8aee749 0x10000.bin
98ff2105dd36027e691991d4871d4ee0bb8bfdf8 0x00000.bin
bdedac73a8ac9b70a476213c10993d7b0f2de653 0x10000.bin

Wyświetl plik

@ -533,6 +533,15 @@ int ICACHE_FLASH_ATTR parse_event(int next_token, bool * happend) {
return next_token + 1;
}
if (is_token(next_token, "wifidisconnect")) {
lang_debug("event wifidisconnect\r\n");
*happend = (interpreter_status == WIFI_DISCONNECT);
if (*happend)
lang_log("on wifidisconnect\r\n");
return next_token + 1;
}
if (is_token(next_token, "topic")) {
char *topic;
int topic_len;
@ -646,7 +655,7 @@ int ICACHE_FLASH_ATTR parse_event(int next_token, bool * happend) {
return next_token + 1;
}
#endif
return syntax_error(next_token, "'init', 'mqttconnect', 'topic', 'gpio_interrupt', 'serial', 'alarm', 'http_response', or 'timer' expected");
return syntax_error(next_token, "event spec (like 'topic') expected");
}
int ICACHE_FLASH_ATTR parse_action(int next_token, bool doit) {
@ -1892,6 +1901,18 @@ int ICACHE_FLASH_ATTR interpreter_wifi_connect(void) {
return parse_statement(0);
}
int ICACHE_FLASH_ATTR interpreter_wifi_disconnect(void) {
if (!script_enabled)
return -1;
lang_debug("interpreter_wifi_disconnect\r\n");
interpreter_status = WIFI_DISCONNECT;
interpreter_topic = interpreter_data = "";
interpreter_data_len = 0;
return parse_statement(0);
}
int ICACHE_FLASH_ATTR interpreter_mqtt_connect(void) {
if (!script_enabled)
return -1;

Wyświetl plik

@ -3,7 +3,7 @@
#include "mqtt/mqtt_server.h"
typedef enum {SYNTAX_CHECK, CONFIG, INIT, MQTT_CLIENT_CONNECT, WIFI_CONNECT, TOPIC_LOCAL, TOPIC_REMOTE, TIMER, SERIAL_INPUT, GPIO_INT, ALARM, HTTP_RESPONSE} Interpreter_Status;
typedef enum {SYNTAX_CHECK, CONFIG, INIT, MQTT_CLIENT_CONNECT, WIFI_CONNECT, WIFI_DISCONNECT, TOPIC_LOCAL, TOPIC_REMOTE, TIMER, SERIAL_INPUT, GPIO_INT, ALARM, HTTP_RESPONSE} Interpreter_Status;
typedef enum {STRING_T, DATA_T} Value_Type;
typedef struct _var_entry_t {
@ -41,6 +41,7 @@ int interpreter_config();
int interpreter_init();
int interpreter_mqtt_connect(void);
int interpreter_wifi_connect(void);
int interpreter_wifi_disconnect(void);
int interpreter_topic_received(const char *topic, const char *data, int data_len, bool local);
int interpreter_serial_input(const char *data, int data_len);

Wyświetl plik

@ -560,6 +560,9 @@ void wifi_handle_event_cb(System_Event_t * evt) {
MQTT_server_cleanupClientCons();
#ifdef SCRIPTED
interpreter_wifi_disconnect();
#endif
#ifdef MQTT_CLIENT
if (mqtt_enabled)
// Missing test for local