How to check in CLI that WiFi is used and is functional?

Using OpenWrt 19.07.2

I have noticed, that sometimes WiFi "hangs", and even though a phone is connected to it, nothing passes through. However, LAN clients can access the internet well.

I think this is a router hardware issue or something, because this has happened with many different OpenWrt versions.

How to check in routers ssh CLI that, WiFi is actually working and clients can use it, packets go through etc.?

I have used ping command, but for example most phones like iPhone do not respond to any pings.

Simplest solution for me would be to check if WiFi is functioning, and if not, run wifi command in combination with cron.

Does:

wifi status

work???

iwinfo helps you find all wlan interfaces:

iwinfo
wlan0     ESSID: "wifi"
          Access Point: AA:AA:AA:AA:AA:AA
          Mode: Master  Channel: 11 (2.462 GHz)
...... etc.. etc..

iwinfo wlan0 assoclist
No station connected

After you've found the wlan interface you wish to check, you can then use iwinfo <interface> assoclist and you can see which clients are connected.

With ip link you can tell with the output:

ip link
9: wlan0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue master br-lan state UP qlen 1000

There are two UPs, the second one tells you if it's up:

mtu 1500 qdisc noqueue master br-lan state UP

In order to monitor your whole network in real time, I highly recommend iftop, which you can install:
https://openwrt.org/docs/guide-user/services/network_monitoring/bwmon

I can't test it, as wifi currently works... so yes, now it works.

The problem with my wifi is, that it does not disconnect clients. It stays connected. Just no data gets through, can't load websites, watch videos... nothing until wifi is restarted with wifi command from CLI.

My workaround for the moment is setting a cron job every 20 minutes pinging a wifi bridge @ $HOST and if it is not getting a reply, it restarts wifi:

ping -c1 $HOST 1>/dev/null 2>/dev/null || wifi

But I wish to work up a solution, that does not rely on wifi bridges.

I'm pretty sure that in the output of wifi status you can see if the radio is up:

	"radio1": {
		"up": true,

As for monitoring, you can use iwinfo device assoclist
You can see Rx, Tx, and even packets that move through.... but for real-time monitoring use a network monitor.

I have checked, the radio is up. Phones, tablets are connected. Just that wifi is frozen.

What would be a CLI command that would return a logical value of 0 or 1, that could be used in a script or as a standalone in a cron job?

How to count if packets # increase?

What about checking if there are any wireless broadcasters and if those can be interacted with?

I don't have a simple enough way to do this, you would have to use awk and other text filters to isolate a TRUE/FALSE statement.

If you wish to simply check if an interface is down then use the already provided system hotplug, which can respond to events within the network:
https://openwrt.org/docs/guide-user/base-system/hotplug

so for example, in /etc/hotplug.d/iface/99-myevents :

#!/bin/sh
if [ "${ACTION}" = "ifdown" ] || [ "${ACTION}" = "ifup-failed" ]
then
	case "${DEVICE}" in
		"wlan0" | "wlan1")
		wifi
    		logger -t hotplug "Device: ${DEVICE} / Action: ${ACTION} / Interface: ${INTERFACE}, restart wifi"
			;;
	esac
fi

I will get to that .. meanwhile I will try the below:

iw dev wlan0 scan | egrep SSID 1>/dev/null 2>/dev/null || wifi
iw dev wlan1 scan | egrep SSID 1>/dev/null 2>/dev/null || wifi

But when testing this, I saw a peculiar error ... 5GHz scanning of wifi networks does not work.

root@OpenWrt:~# iw dev wlan1 scan
command failed: Resource busy (-16)

As in comparison this returns a long list of network data:

root@OpenWrt:~# iw dev wlan0 scan

I'm not sure why maybe due to "DFS / radar detection", maybe the interface isn't up yet?

I am using channel 52

And yes, I am watching youtube on my phone on this 5GHz wifi as this happens.

If it continues try to use:

service network restart

NOTE: This will restart your whole network, wifi connections, lan connections etc.. even your connection to the ssh terminal

If it persists... it could be a configuration problem, or something more serious than that.

Another thing to take into consideration is that if an interface is busy feeding your phone data it won't be able to "scan" anything since radios can either transmit or receive at a time.. while it shouldn't be "stuck" at a specific mode but interchange between them, it's still possible in your case and depends on your configuration.

1 Like

I have done this, several times, with no difference ...

But I found a solution, I think:

iw dev wlan0 station get $MAC_ADDR0 
iw dev wlan1 station get $MAC_ADDR1

This returns an increasing packet count when client with mac address is downloading something.

There is a whole bunch of options to check, apart from rx bytes:

root@OpenWrt:~# iw dev wlan1 station get $MAC_ADDR1
Station $MAC_ADDR1 (on wlan1)
        inactive time:  610 ms
        rx bytes:       1091985
        rx packets:     8046
        tx bytes:       33095867
        tx packets:     19724
        tx retries:     1345
        tx failed:      1
        rx drop misc:   3
        signal:         -72 [-73, -72] dBm
        signal avg:     -70 [-70, -71] dBm
        tx bitrate:     526.6 MBit/s VHT-MCS 6 80MHz VHT-NSS 2
        rx bitrate:     24.0 MBit/s
        rx duration:    316223 us
        last ack signal:0 dBm
        expected throughput:    64.819Mbps
        authorized:     yes
        authenticated:  yes
        associated:     yes
        preamble:       long
        WMM/WME:        yes
        MFP:            yes
        TDLS peer:      no
        DTIM period:    2
        beacon interval:100
        short slot time:yes
        connected time: 1205 seconds

To get the value of a list only, I have to awk the line number.

root@OpenWrt:~# iw dev wlan1 station get $MAC_ADDR1 | awk 'NR==3 {print $NF}' 
1091985

Yes, this is it. The solution. I can check within a set interval, if this or that line number changes, increases or stays the same, and if not, can restart wifi. Painless, much less painless that restarting the router.

Much success. So OpenWrt. Many Linux.

For noobs: substitute the variable $MAC_ADDR1 outside of scripts with your device MAC address in the format 00:02:03:04:05:06

Alternative solution:

cron job to restart wifi every morning at 6 o'clock.

But this longer one on top is much more interesting ...

The iw dump is great, especially inactive time in addition to rx bytes.. can help you get a clearer picture..

Another thing you might want to use is ARP tables which you can check with ip neigh it shows you the status of specific clients (STALE, REACHABLE and FAILED), which should be better than ping.

1 Like

But the way, I think I discovered a bug with this experimenting.

Have a look:

https://forum.openwrt.org/t/openwrt-19-07-2-service-release/57066/16?u=lede_dude

Scanning of 5GHz networks does not work under certain country codes.

root@OpenWrt:~# iw dev wlan1 scan
command failed: Resource busy (-16)

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