Callback system for WiFi events



  • Hello folks,
    I just wanna know if it possible to create a callback system for WiFi events when WLAN is configured on AP mode. I need to get the list of connected devices in the WiFI network and their hostname or states. However I have no idea how it can be achieved without this feature.

    I was thinking of something similar to the LoRa callback system : https://docs.pycom.io/firmwareapi/pycom/network/lora/ (see lora.callback(trigger, handler=None, arg=None)).

    If it doesn't exist or no way to fulfill my needs, please share me a link to the firmware source code and the WLAN class.

    Thank you in advance for your time. ;-)



  • Okay I've made a new function in the modwlan.c in the LoPy firmware that returns a tuple containing mac and ipv4 address for each connected devices.

    Here the GitHub PR link : https://github.com/pycom/pycom-micropython-sigfox/pull/415
    It may be useful for some people ! ;-)



  • Thank you for your help !

    This function and many others have changed since the last time I've flashed my LoPy4. So I updated my firmware and did a dir(network.WLAN) and got this :

    ['__class__', '__name__', 'AP', 'COUNTRY_POL_AUTO', 'COUNTRY_POL_MAN', 'Connected_ap_pwd', 'EVENT_PKT_ANY', 'EVENT_PKT_CTRL', 'EVENT_PKT_DATA', 'EVENT_PKT_DATA_AMPDU', 'EVENT_PKT_DATA_MPDU', 'EVENT_PKT_MGMT', 'EVENT_PKT_MISC', 'EXT_ANT', 'FILTER_CTRL_PKT_ACK', 'FILTER_CTRL_PKT_ALL', 'FILTER_CTRL_PKT_BA', 'FILTER_CTRL_PKT_BAR', 'FILTER_CTRL_PKT_CFEND', 'FILTER_CTRL_PKT_CFENDACK', 'FILTER_CTRL_PKT_CTS', 'FILTER_CTRL_PKT_PSPOLL', 'FILTER_CTRL_PKT_WRAPPER', 'HT20', 'HT40', 'INT_ANT', 'PHY_11_B', 'PHY_11_G', 'PHY_11_N', 'PHY_LOW_RATE', 'SCAN_ACTIVE', 'SCAN_PASSIVE', 'SECONDARY_CHN_ABOVE', 'SECONDARY_CHN_BELOW', 'SECONDARY_CHN_NONE', 'SMART_CONF_DONE', 'SMART_CONF_TIMEOUT', 'STA', 'STA_AP', 'WEP', 'WPA', 'WPA2', 'WPA2_ENT', 'antenna', 'ap_sta_list', 'auth', 'bandwidth', 'bssid', 'callback', 'channel', 'connect', 'country', 'ctrl_pkt_filter', 'deinit', 'disconnect', 'events', 'hostname', 'ifconfig', 'init', 'isconnected', 'joined_ap_info', 'mac', 'max_tx_power', 'mode', 'promiscuous', 'scan', 'send_raw', 'smartConfig', 'ssid', 'wifi_packet', 'wifi_protocol']
    

    The code isn't documented so tried some triggers like EVENT_PKT_* but did not get callback activity. Furthermore, the events() function returns always 0.

    I will go further in the next days to find a solution but if you have more info about those features I would be pleased. ;-)

    I've also found the ap_sta_list() function that returns the list of info on device connected (mac, rssi, wlan_protocol). It is not callback featured but could do the trick maybe ! I will post my progress during the next days too.



  • This post is deleted!


  • @agicquel I'm not sure if a callback system is actually required, a function returning the currently connected devices should be enough (though "hostnames" is a topic by itself...), but that doesn't exist.

    The source of the WLAN module is here: https://github.com/pycom/pycom-micropython-sigfox/blob/Dev/esp32/mods/modwlan.c

    Interestingly... There seems to be an undocumented callback system in there. No idea if it works at all, though, nor if it would provide the data you want.

    Don't have a Pycom module at hand right now, so I'll let you try WLAN.callback(trigger, handler, arg) yourself :-)


Log in to reply
 

Pycom on Twitter