OpenWrt在场侦测
- OpenWrt: 192.168.1.1
- Clients: A, B, C ……
首先安装必要的软件包,并且允许匿名访问API
ubus call hostapd.wlan0 get_clients
opkg install uhttpd-mod-ubus jq
vi /usr/share/rpcd/acl.d/unauthenticated.json
service rpcd restart
service uhttpd restart
{
"unauthenticated": {
"description": "Access controls for unauthenticated requests",
"read": {
"ubus": {
"session": [
"access",
"login"
],
"hostapd.*": [
"get_clients"
]
}
}
}
}
用下面的命令侦测某个设备是否在场
curl -s http://127.0.0.1/ubus -d @payload.json |
jq -e '.result[1].clients|keys|contains(["aa:aa:aa:aa:aa:aa"])'
{
"jsonrpc": "2.0",
"id": 1,
"method": "call",
"params": [
"00000000000000000000000000000000",
"hostapd.wlan0",
"get_clients",
{}
]
}
{
"jsonrpc": "2.0",
"id": 1,
"result": [
0,
{
"freq": 2437,
"clients": {
"aa:aa:aa:aa:aa:aa": {...},
"bb:bb:bb:bb:bb:bb": {...},
"cc:cc:cc:cc:cc:cc": {...}
}
}
]
}
发布/订阅MQTT消息Broker
# install
opkg install mosquitto-client-ssl
# publish
curl -s http://127.0.0.1/ubus -d @payload.json | jq -c '.result[1].clients|keys|sort' | mosquitto_pub mosquitto_pub -h broker.hivemq.com -t openwrt/clients -l
# subscribe
mosquitto_sub -v -h broker.hivemq.com -t openwrt/clients