Exposed wifi event OPMODE_CHANGED. (#1967)

This commit is contained in:
dnc40085 2017-05-15 00:05:22 -07:00 committed by Marcel Stör
parent c4516f1a17
commit 447fcd397d
2 changed files with 25 additions and 5 deletions

View File

@ -154,9 +154,10 @@ static void wifi_event_monitor_handle_event_cb(System_Event_t *evt)
if((wifi_event_cb_ref[evt->event] != LUA_NOREF) || ((wifi_event_cb_ref[EVENT_MAX] != LUA_NOREF) && if((wifi_event_cb_ref[evt->event] != LUA_NOREF) || ((wifi_event_cb_ref[EVENT_MAX] != LUA_NOREF) &&
!(evt->event == EVENT_STAMODE_CONNECTED || evt->event == EVENT_STAMODE_DISCONNECTED || !(evt->event == EVENT_STAMODE_CONNECTED || evt->event == EVENT_STAMODE_DISCONNECTED ||
evt->event == EVENT_STAMODE_AUTHMODE_CHANGE||evt->event==EVENT_STAMODE_GOT_IP || evt->event == EVENT_STAMODE_AUTHMODE_CHANGE || evt->event == EVENT_STAMODE_GOT_IP ||
evt->event == EVENT_STAMODE_DHCP_TIMEOUT||evt->event==EVENT_SOFTAPMODE_STACONNECTED || evt->event == EVENT_STAMODE_DHCP_TIMEOUT || evt->event == EVENT_SOFTAPMODE_STACONNECTED ||
evt->event == EVENT_SOFTAPMODE_STADISCONNECTED||evt->event==EVENT_SOFTAPMODE_PROBEREQRECVED))) evt->event == EVENT_SOFTAPMODE_STADISCONNECTED || evt->event == EVENT_SOFTAPMODE_PROBEREQRECVED ||
evt->event == EVENT_OPMODE_CHANGED)))
{ {
evt_queue_t *temp = (evt_queue_t*)c_malloc(sizeof(evt_queue_t)); //allocate memory for new queue item evt_queue_t *temp = (evt_queue_t*)c_malloc(sizeof(evt_queue_t)); //allocate memory for new queue item
temp->evt = (System_Event_t*)c_malloc(sizeof(System_Event_t)); //allocate memory to hold event structure temp->evt = (System_Event_t*)c_malloc(sizeof(System_Event_t)); //allocate memory to hold event structure
@ -279,7 +280,16 @@ static void wifi_event_monitor_process_event_queue(task_param_t param, uint8 pri
evt->event_info.ap_probereqrecved.rssi); evt->event_info.ap_probereqrecved.rssi);
break; break;
default://if event is not implemented, push table with userdata containing event data case EVENT_OPMODE_CHANGED:
EVENT_DBG("\n\tOPMODE_CHANGED\n");
wifi_add_int_field(L, "old_mode", evt->event_info.opmode_changed.old_opmode);
wifi_add_int_field(L, "new_mode", evt->event_info.opmode_changed.new_opmode);
EVENT_DBG("\topmode: %u -> %u\n",
evt->event_info.opmode_changed.old_opmode,
evt->event_info.opmode_changed.new_opmode);
break;
default://if event is not implemented, return event id
EVENT_DBG("\n\tswitch/case default\n"); EVENT_DBG("\n\tswitch/case default\n");
wifi_add_sprintf_field(L, "info", "event %u not implemented", evt->event); wifi_add_sprintf_field(L, "info", "event %u not implemented", evt->event);
break; break;
@ -350,6 +360,7 @@ const LUA_REG_TYPE wifi_event_monitor_map[] =
{ LSTRKEY( "AP_STACONNECTED" ), LNUMVAL( EVENT_SOFTAPMODE_STACONNECTED ) }, { LSTRKEY( "AP_STACONNECTED" ), LNUMVAL( EVENT_SOFTAPMODE_STACONNECTED ) },
{ LSTRKEY( "AP_STADISCONNECTED" ), LNUMVAL( EVENT_SOFTAPMODE_STADISCONNECTED ) }, { LSTRKEY( "AP_STADISCONNECTED" ), LNUMVAL( EVENT_SOFTAPMODE_STADISCONNECTED ) },
{ LSTRKEY( "AP_PROBEREQRECVED" ), LNUMVAL( EVENT_SOFTAPMODE_PROBEREQRECVED ) }, { LSTRKEY( "AP_PROBEREQRECVED" ), LNUMVAL( EVENT_SOFTAPMODE_PROBEREQRECVED ) },
{ LSTRKEY( "WIFI_MODE_CHANGED" ), LNUMVAL( EVENT_OPMODE_CHANGED ) },
{ LSTRKEY( "EVENT_MAX" ), LNUMVAL( EVENT_MAX ) }, { LSTRKEY( "EVENT_MAX" ), LNUMVAL( EVENT_MAX ) },
#ifdef WIFI_EVENT_MONITOR_DISCONNECT_REASON_LIST_ENABLE #ifdef WIFI_EVENT_MONITOR_DISCONNECT_REASON_LIST_ENABLE
{ LSTRKEY( "reason" ), LROVAL( wifi_event_monitor_reason_map ) }, { LSTRKEY( "reason" ), LROVAL( wifi_event_monitor_reason_map ) },

View File

@ -1523,6 +1523,9 @@ T: Table returned by event.
- `wifi.eventmon.AP_PROBEREQRECVED`: A probe request was received. - `wifi.eventmon.AP_PROBEREQRECVED`: A probe request was received.
- `MAC`: MAC address of the client that is probing the access point. - `MAC`: MAC address of the client that is probing the access point.
- `RSSI`: Received Signal Strength Indicator of client. - `RSSI`: Received Signal Strength Indicator of client.
- `wifi.eventmon.WIFI_MODE_CHANGE`: WiFi mode has changed.
- `old_auth_mode`: Old WiFi mode.
- `new_auth_mode`: New WiFi mode.
#### Example #### Example
@ -1537,7 +1540,7 @@ T: Table returned by event.
T.BSSID.."\n\treason: "..T.reason) T.BSSID.."\n\treason: "..T.reason)
end) end)
wifi.eventmon.register(wifi.eventmon.STA_AUTHMODE_CHANGE, Function(T) wifi.eventmon.register(wifi.eventmon.STA_AUTHMODE_CHANGE, function(T)
print("\n\tSTA - AUTHMODE CHANGE".."\n\told_auth_mode: ".. print("\n\tSTA - AUTHMODE CHANGE".."\n\told_auth_mode: "..
T.old_auth_mode.."\n\tnew_auth_mode: "..T.new_auth_mode) T.old_auth_mode.."\n\tnew_auth_mode: "..T.new_auth_mode)
end) end)
@ -1562,6 +1565,11 @@ T: Table returned by event.
wifi.eventmon.register(wifi.eventmon.AP_PROBEREQRECVED, function(T) wifi.eventmon.register(wifi.eventmon.AP_PROBEREQRECVED, function(T)
print("\n\tAP - PROBE REQUEST RECEIVED".."\n\tMAC: ".. T.MAC.."\n\tRSSI: "..T.RSSI) print("\n\tAP - PROBE REQUEST RECEIVED".."\n\tMAC: ".. T.MAC.."\n\tRSSI: "..T.RSSI)
end) end)
wifi.eventmon.register(wifi.eventmon.WIFI_MODE_CHANGED, function(T)
print("\n\tSTA - WIFI MODE CHANGED".."\n\told_mode: "..
T.old_mode.."\n\tnew_mode: "..T.new_mode)
end)
``` ```
#### See also #### See also
- [`wifi.eventmon.unregister()`](#wifieventmonunregister) - [`wifi.eventmon.unregister()`](#wifieventmonunregister)
@ -1588,6 +1596,7 @@ Event: WiFi event you would like to set a callback for.
- wifi.eventmon.AP_STACONNECTED - wifi.eventmon.AP_STACONNECTED
- wifi.eventmon.AP_STADISCONNECTED - wifi.eventmon.AP_STADISCONNECTED
- wifi.eventmon.AP_PROBEREQRECVED - wifi.eventmon.AP_PROBEREQRECVED
- wifi.eventmon.WIFI_MODE_CHANGED
#### Returns #### Returns
`nil` `nil`