Hi all,
I wanted to get some feedback on how I am using the OpenWrt RPC interface (luci-mod-rpc
) to detect reliably, when a device is active or leaves the network.
I created a Python module called openwrt-luci-rpc to do this:
This module is consumed by the Home Assistant project, as per this PR.
Anyway, to get to my actual question:
Is the way I am detecting presence actually correct?
Here is the code I am using for OpenWRT v17 to determine if a device is reachable:
# Check if the Flags for each device contain
# NUD_REACHABLE and if not, skip.
if not int(device_entry['Flags'], 16) & 0x2:
continue
That was working fine, but now since v18, using the ip neighbors ref rpc interface is used to get a list of connected devices, and there is no longer a Flags
property.
There are other properties returned, such as the following:
{
"dev": "br-lan",
"stale": true,
"mac": "00:1E:EC:09:08:AD",
"noarp": false,
"dest": "192.168.7.5",
"permanent": false,
"failed": false,
"family": 4,
"proxy": false,
"router": false,
"reachable": false,
"probe": false,
"delay": false,
"incomplete": false
},
I tried using the reachable
and stale
booleans, to indicate presence, but they flap a lot, even when they have not left the house (this flapping is probably only true for non-wired devices, like phones).
Anyway, I don't fully understand what each of these properties actually mean, and I would appreciate any advice on how to intelligently use them to determine if a smart phone has left the building (for example).
Right now, my logic for v18+ is, if the device entry exists at all in the ip neighbors list, then consider it at "home" and not "away".
This seems to work pretty well, and I see my phone drops off the list after about 10-15 minutes (iPhone).
Anyway, any thoughts on this would be appreciated!
CC @jow who I know has contributed to the luci-mod-rpc package.