diff --git a/app/include/user_config.h b/app/include/user_config.h index 393da734..f7c2a467 100644 --- a/app/include/user_config.h +++ b/app/include/user_config.h @@ -111,7 +111,6 @@ extern void luaL_assertfail(const char *file, int line, const char *message); //#define WIFI_SMART_ENABLE -#define WIFI_STATION_STATUS_MONITOR_ENABLE #define WIFI_SDK_EVENT_MONITOR_ENABLE #define WIFI_EVENT_MONITOR_DISCONNECT_REASON_LIST_ENABLE diff --git a/app/modules/wifi.c b/app/modules/wifi.c index e1c8f94c..d30382c7 100644 --- a/app/modules/wifi.c +++ b/app/modules/wifi.c @@ -1629,11 +1629,6 @@ static const LUA_REG_TYPE wifi_station_map[] = { { LSTRKEY( "config" ), LFUNCVAL( wifi_station_config ) }, { LSTRKEY( "connect" ), LFUNCVAL( wifi_station_connect4lua ) }, { LSTRKEY( "disconnect" ), LFUNCVAL( wifi_station_disconnect4lua ) }, -#if defined(WIFI_STATION_STATUS_MONITOR_ENABLE) - { LSTRKEY( "eventMonReg" ), LFUNCVAL( wifi_station_event_mon_reg ) }, //defined in wifi_eventmon.c - { LSTRKEY( "eventMonStart" ), LFUNCVAL( wifi_station_event_mon_start ) }, //defined in wifi_eventmon.c - { LSTRKEY( "eventMonStop" ), LFUNCVAL( wifi_station_event_mon_stop ) }, //defined in wifi_eventmon.c -#endif { LSTRKEY( "getap" ), LFUNCVAL( wifi_station_listap ) }, { LSTRKEY( "getapindex" ), LFUNCVAL( wifi_station_get_ap_index ) }, { LSTRKEY( "getapinfo" ), LFUNCVAL( wifi_station_get_ap_info4lua ) }, diff --git a/app/modules/wifi_common.h b/app/modules/wifi_common.h index df8a77a7..c77d89cc 100644 --- a/app/modules/wifi_common.h +++ b/app/modules/wifi_common.h @@ -65,10 +65,5 @@ enum wifi_suspension_state extern const LUA_REG_TYPE wifi_event_monitor_map[]; void wifi_eventmon_init(); #endif -#ifdef WIFI_STATION_STATUS_MONITOR_ENABLE - int wifi_station_event_mon_start(lua_State* L); - int wifi_station_event_mon_reg(lua_State* L); - void wifi_station_event_mon_stop(lua_State* L); -#endif #endif /* APP_MODULES_WIFI_COMMON_H_ */ diff --git a/app/modules/wifi_eventmon.c b/app/modules/wifi_eventmon.c index 05af3c38..14f32043 100644 --- a/app/modules/wifi_eventmon.c +++ b/app/modules/wifi_eventmon.c @@ -17,100 +17,6 @@ #if defined(LUA_USE_MODULES_WIFI) -#ifdef WIFI_STATION_STATUS_MONITOR_ENABLE - -//variables for wifi event monitor -static int wifi_station_status_cb_ref[6] = {[0 ... 6-1] = LUA_NOREF}; -static os_timer_t wifi_sta_status_timer; -static uint8 prev_wifi_status=0; - -// wifi.sta.eventMonStop() -void wifi_station_event_mon_stop(lua_State* L) -{ - os_timer_disarm(&wifi_sta_status_timer); - if(lua_isstring(L,1)) - { - int i; - for (i=0; i<6; i++) - { - unregister_lua_cb(L, &wifi_station_status_cb_ref[i]); - } - } - return; -} - -static void wifi_status_cb(int arg) -{ - lua_State* L = lua_getstate(); - if (wifi_get_opmode() == SOFTAP_MODE) - { - os_timer_disarm(&wifi_sta_status_timer); - return; - } - int wifi_status = wifi_station_get_connect_status(); - if (wifi_status != prev_wifi_status) - { - if(wifi_station_status_cb_ref[wifi_status] != LUA_NOREF) - { - lua_rawgeti(L, LUA_REGISTRYINDEX, wifi_station_status_cb_ref[wifi_status]); - lua_pushnumber(L, prev_wifi_status); - lua_call(L, 1, 0); - } - } - prev_wifi_status = wifi_status; -} - -// wifi.sta.eventMonReg() -int wifi_station_event_mon_reg(lua_State* L) -{ - platform_print_deprecation_note("wifi.sta.eventmonreg() is replaced by wifi.eventmon.register()", "in the next version"); - - uint8 id=(uint8)luaL_checknumber(L, 1); - if ((id > 5)) // verify user specified a valid wifi status - { - return luaL_error( L, "valid wifi status:0-5" ); - } - - if (lua_type(L, 2) == LUA_TFUNCTION || lua_type(L, 2) == LUA_TLIGHTFUNCTION) //check if 2nd item on stack is a function - { - lua_pushvalue(L, 2); //push function to top of stack - register_lua_cb(L, &wifi_station_status_cb_ref[id]);//pop function from top of the stack, register it in the LUA_REGISTRY, then assign returned lua_ref to wifi_station_status_cb_ref[id] - } - else - { - unregister_lua_cb(L, &wifi_station_status_cb_ref[id]); // unregister user's callback - } - return 0; -} - - -// wifi.sta.eventMonStart() -int wifi_station_event_mon_start(lua_State* L) -{ - if(wifi_get_opmode() == SOFTAP_MODE) //Verify ESP is in either Station mode or StationAP mode - { - return luaL_error( L, "Can't monitor in SOFTAP mode" ); - } - if (wifi_station_status_cb_ref[0] == LUA_NOREF && wifi_station_status_cb_ref[1] == LUA_NOREF && - wifi_station_status_cb_ref[2] == LUA_NOREF && wifi_station_status_cb_ref[3] == LUA_NOREF && - wifi_station_status_cb_ref[4] == LUA_NOREF && wifi_station_status_cb_ref[5] == LUA_NOREF ) - { //verify user has registered callbacks - return luaL_error( L, "No callbacks defined" ); - } - uint32 ms = 150; //set default timer interval - if(lua_isnumber(L, 1)) // check if user has specified a different timer interval - { - ms=luaL_checknumber(L, 1); // retrieve user-defined interval - } - - os_timer_disarm(&wifi_sta_status_timer); - os_timer_setfn(&wifi_sta_status_timer, (os_timer_func_t *)wifi_status_cb, NULL); - os_timer_arm(&wifi_sta_status_timer, ms, 1); - return 0; -} - -#endif - #ifdef WIFI_SDK_EVENT_MONITOR_ENABLE //variables for wifi event monitor diff --git a/docs/en/modules/wifi.md b/docs/en/modules/wifi.md index 0f81d36d..6775dbbb 100644 --- a/docs/en/modules/wifi.md +++ b/docs/en/modules/wifi.md @@ -489,116 +489,6 @@ none - [`wifi.sta.config()`](#wifistaconfig) - [`wifi.sta.connect()`](#wifistaconnect) -## wifi.sta.eventMonReg() - -Registers callbacks for WiFi station status events. - -!!! note - Please update your program to use the [`wifi.eventmon`](#wifieventmon-module) API, as the `wifi.sta.eventmon___()` API is deprecated. - -#### Syntax -- `wifi.sta.eventMonReg(wifi_status[, function([previous_state])])` - -#### Parameters -- `wifi_status` WiFi status you would like to set a callback for: - - `wifi.STA_IDLE` - - `wifi.STA_CONNECTING` - - `wifi.STA_WRONGPWD` - - `wifi.STA_APNOTFOUND` - - `wifi.STA_FAIL` - - `wifi.STA_GOTIP` -- `function` callback function to perform when event occurs - - Note: leaving field blank unregisters callback. -- `previous_state` previous wifi_state(0 - 5) - -#### Returns -`nil` - -#### Example -```lua ---register callback -wifi.sta.eventMonReg(wifi.STA_IDLE, function() print("STATION_IDLE") end) -wifi.sta.eventMonReg(wifi.STA_CONNECTING, function() print("STATION_CONNECTING") end) -wifi.sta.eventMonReg(wifi.STA_WRONGPWD, function() print("STATION_WRONG_PASSWORD") end) -wifi.sta.eventMonReg(wifi.STA_APNOTFOUND, function() print("STATION_NO_AP_FOUND") end) -wifi.sta.eventMonReg(wifi.STA_FAIL, function() print("STATION_CONNECT_FAIL") end) -wifi.sta.eventMonReg(wifi.STA_GOTIP, function() print("STATION_GOT_IP") end) - ---register callback: use previous state -wifi.sta.eventMonReg(wifi.STA_CONNECTING, function(previous_State) - if(previous_State==wifi.STA_GOTIP) then - print("Station lost connection with access point\n\tAttempting to reconnect...") - else - print("STATION_CONNECTING") - end -end) - ---unregister callback -wifi.sta.eventMonReg(wifi.STA_IDLE) -``` -#### See also -- [`wifi.sta.eventMonStart()`](#wifistaeventmonstart) -- [`wifi.sta.eventMonStop()`](#wifistaeventmonstop) -- [`wifi.eventmon.register()`](#wifieventmonregister) -- [`wifi.eventmon.unregister()`](#wifieventmonunregister) - - -## wifi.sta.eventMonStart() - -Starts WiFi station event monitor. - -#### Syntax -`wifi.sta.eventMonStart([ms])` - -### Parameters -- `ms` interval between checks in milliseconds, defaults to 150ms if not provided. - -#### Returns -`nil` - -#### Example -```lua ---start WiFi event monitor with default interval -wifi.sta.eventMonStart() - ---start WiFi event monitor with 100ms interval -wifi.sta.eventMonStart(100) -``` - -#### See also -- [`wifi.sta.eventMonReg()`](#wifistaeventmonreg) -- [`wifi.sta.eventMonStop()`](#wifistaeventmonstop) -- [`wifi.eventmon.register()`](#wifieventmonregister) -- [`wifi.eventmon.unregister()`](#wifieventmonunregister) - -## wifi.sta.eventMonStop() - -Stops WiFi station event monitor. -#### Syntax -`wifi.sta.eventMonStop([unregister_all])` - -#### Parameters -- `unregister_all` enter 1 to unregister all previously registered functions. - - Note: leave blank to leave callbacks registered - -#### Returns -`nil` - -#### Example -```lua ---stop WiFi event monitor -wifi.sta.eventMonStop() - ---stop WiFi event monitor and unregister all callbacks -wifi.sta.eventMonStop(1) -``` - -#### See also -- [`wifi.sta.eventMonReg()`](#wifistaeventmonreg) -- [`wifi.sta.eventMonStart()`](#wifistaeventmonstart) -- [`wifi.eventmon.register()`](#wifieventmonregister) -- [`wifi.eventmon.unregister()`](#wifieventmonunregister) - ## wifi.sta.getap() Scans AP list as a Lua table into callback function. @@ -1464,7 +1354,6 @@ none boolean indicating success # wifi.eventmon Module -Note: The functions `wifi.sta.eventMon___()` and `wifi.eventmon.___()` are completely seperate and can be used independently of one another. ## wifi.eventmon.register() @@ -1573,9 +1462,6 @@ T: Table returned by event. ``` #### See also - [`wifi.eventmon.unregister()`](#wifieventmonunregister) -- [`wifi.sta.eventMonStart()`](#wifistaeventmonstart) -- [`wifi.sta.eventMonStop()`](#wifistaeventmonstop) -- [`wifi.sta.eventMonReg()`](#wifistaeventmonreg) ## wifi.eventmon.unregister() @@ -1608,8 +1494,6 @@ Event: WiFi event you would like to set a callback for. ``` #### See also - [`wifi.eventmon.register()`](#wifieventmonregister) -- [`wifi.sta.eventMonStart()`](#wifistaeventmonstart) -- [`wifi.sta.eventMonStop()`](#wifistaeventmonstop) ## wifi.eventmon.reason