mirror of
https://github.com/nodemcu/nodemcu-firmware.git
synced 2025-02-06 21:18:25 +08:00
commit
09269a6452
@ -991,32 +991,11 @@ static int wifi_station_status( lua_State* L )
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
// wifi.sta.eventMonStop()
|
||||||
* wifi.sta.eventMonStop()
|
void wifi_station_event_mon_stop(lua_State* L)
|
||||||
* Description:
|
|
||||||
* Stop wifi station event monitor
|
|
||||||
* Syntax:
|
|
||||||
* wifi.sta.eventMonStop()
|
|
||||||
* wifi.sta.eventMonStop("unreg all")
|
|
||||||
* Parameters:
|
|
||||||
* "unreg all": unregister all previously registered functions
|
|
||||||
* Returns:
|
|
||||||
* Nothing.
|
|
||||||
*
|
|
||||||
* Example:
|
|
||||||
--stop wifi event monitor
|
|
||||||
wifi.sta.eventMonStop()
|
|
||||||
|
|
||||||
--stop wifi event monitor and unregister all callbacks
|
|
||||||
wifi.sta.eventMonStop("unreg all")
|
|
||||||
*/
|
|
||||||
static void wifi_station_event_mon_stop(lua_State* L)
|
|
||||||
{
|
{
|
||||||
os_timer_disarm(&wifi_sta_status_timer);
|
os_timer_disarm(&wifi_sta_status_timer);
|
||||||
if(lua_isstring(L,1))
|
if(lua_isstring(L,1))
|
||||||
{
|
|
||||||
|
|
||||||
if (c_strcmp(luaL_checkstring(L, 1), "unreg all")==0)
|
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
for (i=0; i<6; i++)
|
for (i=0; i<6; i++)
|
||||||
@ -1028,12 +1007,13 @@ static void wifi_station_event_mon_stop(lua_State* L)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void wifi_status_cb(int arg)
|
static void wifi_status_cb(int arg)
|
||||||
{
|
{
|
||||||
if (wifi_get_opmode()==2)
|
lua_State* L = lua_getstate();
|
||||||
|
if (wifi_get_opmode() == SOFTAP_MODE)
|
||||||
{
|
{
|
||||||
os_timer_disarm(&wifi_sta_status_timer);
|
os_timer_disarm(&wifi_sta_status_timer);
|
||||||
return;
|
return;
|
||||||
@ -1043,65 +1023,33 @@ static void wifi_status_cb(int arg)
|
|||||||
{
|
{
|
||||||
if(wifi_status_cb_ref[wifi_status] != LUA_NOREF)
|
if(wifi_status_cb_ref[wifi_status] != LUA_NOREF)
|
||||||
{
|
{
|
||||||
lua_rawgeti(gL, LUA_REGISTRYINDEX, wifi_status_cb_ref[wifi_status]);
|
lua_rawgeti(L, LUA_REGISTRYINDEX, wifi_status_cb_ref[wifi_status]);
|
||||||
lua_call(gL, 0, 0);
|
lua_pushnumber(L, prev_wifi_status);
|
||||||
|
lua_call(L, 1, 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
prev_wifi_status = wifi_status;
|
prev_wifi_status = wifi_status;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
// wifi.sta.eventMonReg()
|
||||||
* wifi.sta.eventMonReg()
|
int wifi_station_event_mon_reg(lua_State* L)
|
||||||
* Description:
|
|
||||||
* Register callback for wifi station status event
|
|
||||||
* Syntax:
|
|
||||||
* wifi.sta.eventMonReg(wifi_status, function)
|
|
||||||
* wifi.sta.eventMonReg(wifi.status, "unreg") //unregister callback
|
|
||||||
* Parameters:
|
|
||||||
* wifi_status: wifi status you would like to set callback for
|
|
||||||
* Valid wifi states:
|
|
||||||
* wifi.STA_IDLE
|
|
||||||
* wifi.STA_CONNECTING
|
|
||||||
* wifi.STA_WRONGPWD
|
|
||||||
* wifi.STA_APNOTFOUND
|
|
||||||
* wifi.STA_FAIL
|
|
||||||
* wifi.STA_GOTIP
|
|
||||||
* function: function to perform
|
|
||||||
* "unreg": unregister previously registered function
|
|
||||||
* Returns:
|
|
||||||
* Nothing.
|
|
||||||
*
|
|
||||||
* Example:
|
|
||||||
--register callback
|
|
||||||
wifi.sta.eventMonReg(0, function() print("STATION_IDLE") end)
|
|
||||||
wifi.sta.eventMonReg(1, function() print("STATION_CONNECTING") end)
|
|
||||||
wifi.sta.eventMonReg(2, function() print("STATION_WRONG_PASSWORD") end)
|
|
||||||
wifi.sta.eventMonReg(3, function() print("STATION_NO_AP_FOUND") end)
|
|
||||||
wifi.sta.eventMonReg(4, function() print("STATION_CONNECT_FAIL") end)
|
|
||||||
wifi.sta.eventMonReg(5, function() print("STATION_GOT_IP") end)
|
|
||||||
|
|
||||||
--unregister callback
|
|
||||||
wifi.sta.eventMonReg(0, "unreg")
|
|
||||||
*/
|
|
||||||
static int wifi_station_event_mon_reg(lua_State* L)
|
|
||||||
{
|
{
|
||||||
gL=L;
|
uint8 id=(uint8)luaL_checknumber(L, 1);
|
||||||
uint8 id=luaL_checknumber(L, 1);
|
if ((id > 5)) // verify user specified a valid wifi status
|
||||||
if (!(id >= 0 && id <=5))
|
|
||||||
{
|
{
|
||||||
return luaL_error( L, "valid wifi status:0-5" );
|
return luaL_error( L, "valid wifi status:0-5" );
|
||||||
}
|
}
|
||||||
|
|
||||||
if (lua_type(L, 2) == LUA_TFUNCTION || lua_type(L, 2) == LUA_TLIGHTFUNCTION)
|
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); // copy argument (func) to the top of stack
|
lua_pushvalue(L, 2); //push function to top of stack
|
||||||
if(wifi_status_cb_ref[id] != LUA_NOREF)
|
if(wifi_status_cb_ref[id] != LUA_NOREF)
|
||||||
{
|
{
|
||||||
luaL_unref(L, LUA_REGISTRYINDEX, wifi_status_cb_ref[id]);
|
luaL_unref(L, LUA_REGISTRYINDEX, wifi_status_cb_ref[id]);
|
||||||
}
|
}
|
||||||
wifi_status_cb_ref[id] = luaL_ref(L, LUA_REGISTRYINDEX);
|
wifi_status_cb_ref[id] = luaL_ref(L, LUA_REGISTRYINDEX);
|
||||||
}
|
}
|
||||||
else if (c_strcmp(luaL_checkstring(L, 2), "unreg")==0)
|
else
|
||||||
{
|
{
|
||||||
if(wifi_status_cb_ref[id] != LUA_NOREF)
|
if(wifi_status_cb_ref[id] != LUA_NOREF)
|
||||||
{
|
{
|
||||||
@ -1113,25 +1061,7 @@ static int wifi_station_event_mon_reg(lua_State* L)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
//wifi.sta.eventMonStart()
|
||||||
* wifi.sta.eventMonStart()
|
|
||||||
* Description:
|
|
||||||
* Start wifi station event monitor
|
|
||||||
* Syntax:
|
|
||||||
* wifi.sta.eventMonStart()
|
|
||||||
* wifi.sta.eventMonStart(mS)
|
|
||||||
* Parameters:
|
|
||||||
* mS:interval between checks in milliseconds. defaults to 150 mS if not provided
|
|
||||||
* Returns:
|
|
||||||
* Nothing.
|
|
||||||
*
|
|
||||||
* Example:
|
|
||||||
--start wifi event monitor with default interval
|
|
||||||
wifi.sta.eventMonStart()
|
|
||||||
|
|
||||||
--start wifi event monitor with 100 mS interval
|
|
||||||
wifi.sta.eventMonStart(100)
|
|
||||||
*/
|
|
||||||
static int wifi_station_event_mon_start(lua_State* L)
|
static int wifi_station_event_mon_start(lua_State* L)
|
||||||
{
|
{
|
||||||
if(wifi_get_opmode() == SOFTAP_MODE)
|
if(wifi_get_opmode() == SOFTAP_MODE)
|
||||||
|
@ -326,19 +326,18 @@ none
|
|||||||
Registers callbacks for WiFi station status events.
|
Registers callbacks for WiFi station status events.
|
||||||
|
|
||||||
#### Syntax
|
#### Syntax
|
||||||
- `wifi.sta.eventMonReg(wifi_status, function([previous_state]))`
|
- `wifi.sta.eventMonReg(wifi_status[, function([previous_state])])`
|
||||||
- `wifi.sta.eventMonReg(wifi.status, "unreg")`
|
|
||||||
|
|
||||||
#### Parameters
|
#### Parameters
|
||||||
- `wifi_status` WiFi status you would like to set callback for, one of:
|
- `wifi_status` WiFi status you would like to set a callback for:
|
||||||
- `wifi.STA_IDLE`
|
- `wifi.STA_IDLE`
|
||||||
- `wifi.STA_CONNECTING`
|
- `wifi.STA_CONNECTING`
|
||||||
- `wifi.STA_WRONGPWD`
|
- `wifi.STA_WRONGPWD`
|
||||||
- `wifi.STA_APNOTFOUND`
|
- `wifi.STA_APNOTFOUND`
|
||||||
- `wifi.STA_FAIL`
|
- `wifi.STA_FAIL`
|
||||||
- `wifi.STA_GOTIP`
|
- `wifi.STA_GOTIP`
|
||||||
- `function` function to perform when event occurs
|
- `function` callback function to perform when event occurs
|
||||||
- `"unreg"` unregister previously registered callback
|
- Note: leaving field blank unregisters callback.
|
||||||
- `previous_state` previous wifi_state(0 - 5)
|
- `previous_state` previous wifi_state(0 - 5)
|
||||||
|
|
||||||
#### Returns
|
#### Returns
|
||||||
@ -364,7 +363,7 @@ wifi.sta.eventMonReg(wifi.STA_CONNECTING, function(previous_State)
|
|||||||
end)
|
end)
|
||||||
|
|
||||||
--unregister callback
|
--unregister callback
|
||||||
wifi.sta.eventMonReg(wifi.STA_IDLE, "unreg")
|
wifi.sta.eventMonReg(wifi.STA_IDLE)
|
||||||
```
|
```
|
||||||
#### See also
|
#### See also
|
||||||
- [`wifi.sta.eventMonStart()`](#wifistaeventmonstart)
|
- [`wifi.sta.eventMonStart()`](#wifistaeventmonstart)
|
||||||
@ -395,15 +394,16 @@ wifi.sta.eventMonStart(100)
|
|||||||
#### See also
|
#### See also
|
||||||
- [`wifi.sta.eventMonReg()`](#wifistaeventmonreg)
|
- [`wifi.sta.eventMonReg()`](#wifistaeventmonreg)
|
||||||
- [`wifi.sta.eventMonStop()`](#wifistaeventmonstop)
|
- [`wifi.sta.eventMonStop()`](#wifistaeventmonstop)
|
||||||
-
|
|
||||||
## wifi.sta.eventMonStop()
|
## wifi.sta.eventMonStop()
|
||||||
|
|
||||||
Stops WiFi station event monitor.
|
Stops WiFi station event monitor.
|
||||||
#### Syntax
|
#### Syntax
|
||||||
`wifi.sta.eventMonStop(["unreg all"])`
|
`wifi.sta.eventMonStop([unregister_all])`
|
||||||
|
|
||||||
#### Parameters
|
#### Parameters
|
||||||
`"unreg all"` unregister all previously registered functions
|
- `unregister_all` enter 1 to unregister all previously registered functions.
|
||||||
|
- Note: leave blank to leave callbacks registered
|
||||||
|
|
||||||
#### Returns
|
#### Returns
|
||||||
`nil`
|
`nil`
|
||||||
@ -414,7 +414,7 @@ Stops WiFi station event monitor.
|
|||||||
wifi.sta.eventMonStop()
|
wifi.sta.eventMonStop()
|
||||||
|
|
||||||
--stop WiFi event monitor and unregister all callbacks
|
--stop WiFi event monitor and unregister all callbacks
|
||||||
wifi.sta.eventMonStop("unreg all")
|
wifi.sta.eventMonStop(1)
|
||||||
```
|
```
|
||||||
|
|
||||||
#### See also
|
#### See also
|
||||||
|
Loading…
x
Reference in New Issue
Block a user