[SOLVED] Assoc/Disassoc event/trigger

Hi,
is there a way to trigger a command when a device associates/disassociates from my AP?
(ideally also a connect disconnect event on the LAN ports)
I was expecting/hoping for a built-in event that could trigger an action, cfr hotplug or via ubus listen maybe?

all recipes i've found rely on some sort of polling e.g. a (lua) script/cron job that calls iwinfo than parsing/diffing for changes or parsing the log for assoc events.

Is there such a mechanism available within LEDE/wrt?
(maybe i've been looking in all the wrong places)

thanks!

Alright I was looking in all the right place... just not hard enough. :slight_smile:

there's a connect/disconnect event available directly from hostapd.
opkg install hostapd-utils will give you hostapd_cli

which you can run with an 'action file' (e.g. a simple shell script)
hostapd_cli -a/bin/hostapd_eventscript -B

the script will be get interface cmd mac as parameters e.g.
#!/bin/sh
logger -t $0 "hostapd event received $1 $2 $3"

will result in something like this in the logs
hostapd event received wlan1 AP-STA-CONNECTED xx:xx:xx:xx:xx:xx

hopefully somebody will find this helpful someday

4 Likes

I found this incredibly helpful 3 years later - thanks!

1 Like

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