Catfriend1 / openwrt-presence

OpenWrt device presence detection bash script. Works accross multiple APs. Listens to events from OpenWrt logread via syslog-ng on a master AP "passively". Can resync "actively" by executing "wrtwifistareport" on slave APs every 5 minutes in case of missed events. Outputs "device A=[present/away]" events to a /tmp/ file and FIFOs. The information can be consumed by home automation or logger software. Presence/Away state is detected representative to the whole extent of a SSID and not limited to a single AP.
Mozilla Public License 2.0
35 stars 9 forks source link

Can't get it to work - wrong hostname of nodes #10

Closed myde2001 closed 4 months ago

myde2001 commented 4 months ago

Hi, I followed the steps but in my device it seems the dto files are not generating.

root@Router:~# sh /root/wrtpresence show
Usage: /root/wrtpresence {start|debug|stop|reset|restart|showlog|livelog|showstate|livestate|diag|ping|clean}
root@Router:~# sh /root/wrtpresence showstate
*** associations.dto: =0 = PRESENT, >0 and <5 = PRESENT, disconnected, =5 = AWAY
cat: can't open '/tmp/associations.dto': No such file or directory

*** present_devices.dto: Device names defined in main service script.
cat: can't open '/tmp/present_devices.dto': No such file or directory

*** wrtwifistareport last received unix time
grep: /tmp/*.last_wrtwifistareport: No such file or directory

What could it be? Thanks

Catfriend1 commented 4 months ago

@myde2001 Please check with the command ... livelog if the main service outputs lines. If not, it is not running. If it exits early, an error should be shown - maybe required packages are missing? -> opkg update; opkg install (pkgname)

I am still using the scripts and they work fine. Hardware is Xiaomi AX3600 here.

myde2001 commented 4 months ago

This is the output of the command:

root@Router:~# sh /root/wrtpresence livelog
2024-06-29 [20-40-41] [INFO] Service was restarted.
2024-06-29 [20-40-44] [INFO] Service was restarted.
2024-06-29 [20-42-38] [INFO] Service was restarted.
2024-06-29 [20-42-48] [INFO] BEGIN logreader_loop
2024-06-29 [20-42-48] [INFO] BEGIN disconnectIdxBumper_loop
2024-06-29 [20-43-44] [INFO] Service was restarted.
2024-06-29 [20-43-54] [INFO] BEGIN disconnectIdxBumper_loop
2024-06-29 [20-43-54] [INFO] BEGIN logreader_loop
2024-06-29 [20-46-39] [INFO] Service was restarted.
2024-06-29 [20-46-49] [INFO] BEGIN disconnectIdxBumper_loop

I installed all the packages that the wrtpresence_main.sh show and removed logd. My hardware is an ASUS TUF-AX4200

Catfriend1 commented 4 months ago

@myde2001 looks fine to me. I guess, syslog-ng is installed, too. What are your wifi interface names? I had a problem after switching to ax3600 and WDS instead of Batman mesh ago where the interface names were not recognized by the regex in the scripts. It does not output a connect line if you e.g. disconnect and reconnect your phone to/from Wifi?

myde2001 commented 4 months ago

The names are: phy0-ap0 and phy1-ap0.

Where should it output the disconnect and reconnect lines? In the livelog?

Thanks

Catfriend1 commented 4 months ago

Yes. Thats fine like it is.

I am not on a big screen now, so unable to deep dive. Check the comments on top of the file. Maybe you can run it with a "debug" command line to get more log output.

Catfriend1 commented 4 months ago

You could also open a second SSH session and follow:

logread -f

Your openwrt log should show disconnect/connect lines. If not, something is different outside of my script. The script just follows your routers log and filters out the wifi driver connect and disconnect events.

myde2001 commented 4 months ago

Hi, this is the output I get with the command logread -f:

Jun 29 21:21:28 PLC-Cocina hostapd: wlan0: AP-STA-CONNECTED b8:5d:0a:xx:xx:xx
Jun 29 21:21:28 PLC-Cocina hostapd: wlan0: STA b8:5d:0a:xx:xx:xx WPA: pairwise key handshake completed (RSN)
Jun 29 21:21:28 PLC-Cocina hostapd: wlan0: EAPOL-4WAY-HS-COMPLETED b8:5d:0a:xx:xx:xx
Jun 29 19:22:02 Router hostapd: phy0-ap0: AP-STA-DISCONNECTED b8:5d:0a:xx:xx:xx
Jun 29 19:22:07 Router hostapd: phy0-ap0: STA b8:5d:0a:xx:xx:xx IEEE 802.11: deauthenticated due to local deauth request
Jun 29 19:22:48 Router hostapd: phy1-ap0: STA b8:5d:0a:xx:xx:xx IEEE 802.11: authenticated
Jun 29 19:22:48 Router hostapd: phy1-ap0: STA b8:5d:0a:xx:xx:xx IEEE 802.11: associated (aid 2)
Jun 29 19:22:48 Router hostapd: phy1-ap0: AP-STA-CONNECTED b8:5d:0a:xx:xx:xx auth_alg=open
Jun 29 19:22:48 Router hostapd: phy1-ap0: STA b8:5d:0a:xx:xx:xx RADIUS: starting accounting session 3EF2EF089B4C3889
Jun 29 19:22:48 Router hostapd: phy1-ap0: STA b8:5d:0a:xx:xx:xx WPA: pairwise key handshake completed (RSN)
Jun 29 19:22:48 Router hostapd: phy1-ap0: EAPOL-4WAY-HS-COMPLETED b8:5d:0a:xx:xx:xx

And the livelog of the service in debug mode:

root@Router:~# sh /root/wrtpresence livelog
2024-06-29 [20-42-48] [INFO] BEGIN disconnectIdxBumper_loop
2024-06-29 [20-43-44] [INFO] Service was restarted.
2024-06-29 [20-43-54] [INFO] BEGIN disconnectIdxBumper_loop
2024-06-29 [20-43-54] [INFO] BEGIN logreader_loop
2024-06-29 [20-46-39] [INFO] Service was restarted.
2024-06-29 [20-46-49] [INFO] BEGIN disconnectIdxBumper_loop
2024-06-29 [21-19-00] *************
2024-06-29 [21-19-01] [INFO] Service was restarted in DEBUG_MODE.
2024-06-29 [21-19-01] [INFO] BEGIN disconnectIdxBumper_loop
2024-06-29 [21-19-01] [INFO] BEGIN logreader_loop

Also, I'm using it in another AP with the slave config, that's why "PLC-Cocina" is shown

Catfriend1 commented 4 months ago

Ref: https://github.com/Catfriend1/openwrt-presence/blob/3024942544aea978e8138117b662c22690497099/wrtpresence_main.sh#L17

I don't remember , but maybe i've hardcoded the router naming prefix which is in my case "WifiAP**". Look for that string in the code and adjust it - or try renaming the routers like WifiAP-01 WifiAP-02

Your syslog-ng and logd seems configured correctly if the main nodes receives events from both logs. :)

myde2001 commented 4 months ago

Yes, it is hardcoded! I found it, I'm going to try and change the hostname

myde2001 commented 4 months ago

Now the files seems to be generated. Thanks. I'll try to get it working with MQTT and I'll get back to thank you if I worked!

Catfriend1 commented 4 months ago

Please also note https://github.com/Catfriend1/openwrt-presence/issues/9#issuecomment-1793393721