How to react to wifi connect/disconnect

Hi. Until today I was using OpenWrt 19.07 or 18.06. It was old, but did everything I wanted. In particular, I was able to get notifications when my phone connected and disconnected from the WiFi, which I used as signals into my home automation to indicate (in part) whether I was home or away. Specifically, I used /usr/sbin/hostapd_cli -iwlan<n> -a"/usr/bin/my_lua_script" & to get a kick whenever a device connected or disconnected.

Today I decided to bite the bullet and upgrade to 24.10, which has gone mostly OK, but I've lost my kick. I discovered that hostapd_cli was not install by default, and installed it, but now I get Failed to connect to hostapd - wpa_ctrl_open: No such file or directory.

Can anyone give me a pointer on how to run my Lua Script when a device connects and disconnects from the WiFi? Perhaps I'm missing something in the installation or configuration for hostapd? Perhaps they are too old and there is a better way? Any pointers would be very welcome.

Cheers,
Steve

Are your interfaces actually named in the wlanX format? They should be named something like phy1-ap0.

Also you should use -B run a daemon in the background option instead of &. Although -a might already imply that.

Otherwise hostapd_cli seems to work just fine on 24.10.0.

Thanks. Instead of original command, I can now run hostapd_cli -B -iphy<n>-ap0 -a/usr/bin/monitor4mqtt. It seems to work better, though not perfect yet. I suspect I also need to tweak my lua script (tomorrows job :grinning:), but your help has definitely pushed me on a step - Thank you.

For completeness, the last gotcha was that hostapd_cli now calls my script with an extra argument on an AP-STA-CONNECT than it used to. Easy change to my script and everything is working as it used to. Thanks.

1 Like

You're welcome. If all the issues were addressed, consider marking the original answer as Solution :wink:

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.