WOW-FI reconnection with fonera

Dear all, since I'm connected to a fastweb client network (WOW- FI) and I'm facing the common problem of disconnection after 15 min i post my solution here.

I paste all my configuration so that you can check it and compare with your config.

BusyBox v1.15.3 (2011-11-24 02:38:24 CET) built-in shell (ash)
Enter 'help' for a list of built-in commands.

  _______                     ________        __
 |       |.-----.-----.-----.|  |  |  |.----.|  |_
 |   -   ||  _  |  -__|     ||  |  |  ||   _||   _|
 |_______||   __|_____|__|__||________||__|  |____|
          |__| W I R E L E S S   F R E E D O M
 Backfire (10.03.1, r29592) ------------------------
  * 1/3 shot Kahlua    In a shot glass, layer Kahlua 
  * 1/3 shot Bailey's  on the bottom, then Bailey's, 
  * 1/3 shot Vodka     then Vodka.
 ---------------------------------------------------
root@OpenWrt:~# cat /etc/config/network 

config 'interface' 'loopback'
	option 'ifname' 'lo'
	option 'proto' 'static'
	option 'ipaddr' '127.0.0.1'
	option 'netmask' '255.0.0.0'

config 'interface' 'lan'
	option 'proto' 'static'
	option 'ipaddr' '192.168.2.254'
	option 'netmask' '255.255.255.0'
	option 'ifname' 'eth0'

config 'interface' 'wwan'
	option 'proto' 'dhcp'
	option 'hostname' 'BananaJoe'

root@OpenWrt:~# cat /etc/config/dhcp 

config 'dnsmasq'
	option 'domainneeded' '1'
	option 'boguspriv' '1'
	option 'filterwin2k' '0'
	option 'localise_queries' '1'
	option 'rebind_protection' '1'
	option 'rebind_localhost' '1'
	option 'local' '/lan/'
	option 'domain' 'lan'
	option 'expandhosts' '1'
	option 'nonegcache' '0'
	option 'authoritative' '1'
	option 'readethers' '1'
	option 'leasefile' '/tmp/dhcp.leases'
	option 'resolvfile' '/tmp/resolv.conf.auto'

config 'dhcp' 'lan'
	option 'interface' 'lan'
	option 'start' '100'
	option 'limit' '150'
	option 'leasetime' '12h'

config 'dhcp' 'wan'
	option 'interface' 'wan'
	option 'ignore' '1'

root@OpenWrt:~# cat /etc/config/wireless 

config 'wifi-device' 'wifi0'
	option 'type' 'atheros'
#	option 'diversity' '0'
#	option 'txpower' '10'
	option 'channel' '1'

config 'wifi-iface'
	option 'ssid' 'WOW FI - FASTWEB'
	option 'device' 'wifi0'
	option 'mode' 'sta'
	option 'bssid' '12:13:31:F3:37:F0' #prende malino
	option 'network' 'wwan'
	option 'encryption' 'wpa2+ccmp'
	option 'eap_type' 'peap'
	option 'auth' 'MSCHAPV2'
	option 'identity' 'myIdentity'
	option 'password' 'myPwd'
  
root@OpenWrt:~# cat /etc/config/firewall 

config 'defaults'
	option 'input' 'DROP'
	option 'output' 'DROP'
	option 'drop_invalid' '1'
	option 'forward' 'DROP'

config 'zone'
	option 'name' 'lan'
	option 'input' 'ACCEPT'
	option 'output' 'ACCEPT'
	option 'network' 'lan'
	option 'forward' 'ACCEPT'

config 'zone'
	option 'name' 'wan'
	option 'masq' '1'
	option 'output' 'ACCEPT'
	option 'input' 'DROP'
	option 'forward' 'DROP'
	option 'network' 'wwan'

config 'rule'
	option 'name' 'Allow-DHCP-Renew'
	option 'src' 'wan'
	option 'proto' 'udp'
	option 'dest_port' '68'
	option 'target' 'ACCEPT'
	option 'family' 'ipv4'

config 'rule'
	option 'name' 'Allow-Ping'
	option 'src' 'wan'
	option 'proto' 'icmp'
	option 'icmp_type' 'echo-request'
	option 'family' 'ipv4'
	option 'target' 'ACCEPT'

config 'rule'
	option 'name' 'Allow-DHCPv6'
	option 'src' 'wan'
	option 'proto' 'udp'
	option 'src_ip' 'fe80::/10'
	option 'src_port' '547'
	option 'dest_ip' 'fe80::/10'
	option 'dest_port' '546'
	option 'family' 'ipv6'
	option 'target' 'ACCEPT'

config 'rule'
	option 'name' 'Allow-ICMPv6-Input'
	option 'src' 'wan'
	option 'proto' 'icmp'
	list 'icmp_type' 'echo-request'
	list 'icmp_type' 'destination-unreachable'
	list 'icmp_type' 'packet-too-big'
	list 'icmp_type' 'time-exceeded'
	list 'icmp_type' 'bad-header'
	list 'icmp_type' 'unknown-header-type'
	list 'icmp_type' 'router-solicitation'
	list 'icmp_type' 'neighbour-solicitation'
	option 'limit' '1000/sec'
	option 'family' 'ipv6'
	option 'target' 'ACCEPT'

config 'rule'
	option 'name' 'Allow-ICMPv6-Forward'
	option 'src' 'wan'
	option 'dest' '*'
	option 'proto' 'icmp'
	list 'icmp_type' 'echo-request'
	list 'icmp_type' 'destination-unreachable'
	list 'icmp_type' 'packet-too-big'
	list 'icmp_type' 'time-exceeded'
	list 'icmp_type' 'bad-header'
	list 'icmp_type' 'unknown-header-type'
	option 'limit' '1000/sec'
	option 'family' 'ipv6'
	option 'target' 'ACCEPT'

config 'include'
	option 'path' '/etc/firewall.user'

config 'forwarding'
	option 'dest' 'wan'
	option 'src' 'lan'

and now the script for reconnecting

root@OpenWrt:~# cat restartConnection.sh 
#!/bin/sh 

downCounter=0
rebootCounter=0
maxDown=3

intCheck() {
	ping -c1 openwrt.org &>/dev/null
	if [ $? -eq 0 ]; then 
		return 0 
	else 
		ping -c1 www.google.com &>/dev/null
		if [ $? -eq 0 ]; then
			return 0
		else
			return 1
		fi 
	fi
}

updateCounter() {
	if intCheck; then
		downCounter=0
		rebootCounter=0
		maxDown=3
	else
		downCounter=$(expr $downCounter + 1)
		touch /root/wifiRebootsCounter.log
	fi
}

act() {
	downCounter=0
	rebootCounter=$(expr $rebootCounter + 1)
	maxDown=$(expr $maxDown + 1)
	echo $rebootCounter > /root/wifiRebootsCounter.log
	if [ $rebootCounter -gt 25 ]; then
		reboot 
		echo $(date) >> /root/fonRebootsCounter.log
	fi
#	ifup wwan  #which is better?
	wifi
	sleep 40
}

while [ 1 ]; do 
	updateCounter
	sleep 5
	if [ $downCounter -gt $maxDown ]; then act; fi
done

root@OpenWrt:~# cat /etc/init.d/restartConnectionService 
#!/bin/sh /etc/rc.common
# 
# Giulio Benetti - giulio.benetti@gmail.com

START=98
STOP=10

start() { 

echo "starting restart service"
	/root/restartConnection.sh &
}

stop() { 
	echo "STOPPING restart service"  
	killall restartConnection.sh
}

root@OpenWrt:~# ls -l /etc/rc.d/
lrwxrwxrwx    1 root     root           34 Mar 21 20:17 K10restartConnectionService -> ../init.d/restartConnectionService
lrwxrwxrwx    1 root     root           34 Mar 21 20:17 S98restartConnectionService -> ../init.d/restartConnectionService

In the last part i listed only the two symbolic links i'm interested to.

As you can see the tool check both openwrt.org and google.com with ping and, if it fails, touch a file, counts up to a certain number and reset the wifi.
After a some attempts it also reboots the fonera.

I'd like to pose just a couple of questions to the experts of the forum:

  • Is it better to use the wifi or the ifup wwan command to restart the wifi?
  • Do you have any suggestion for the whole scheme?

Hope it helps and thank you in advance.

Regards

1 Like

Your OpenWrt version is ancient and unsupported, you won't be able to find anyone to help you.
You can upgrade the router to a newer one that runs the latest OpenWrt version without spending much money.
Other than that I don't see anything wrong in the configuration and I would prefer ifup to restart an interface.

2 Likes

Thank you for the response.

At the moment the fonera is working fine, I don't see any reason to change it.

I posted my solution here because I was not able to find a solution elsewhere. Just for reference.

Regarding the wifi vs ifup solution... is it actually the same? In my view ifup wwan restarts the network interface whereas wifi should restart the wifi interface... is it correct?

Regards.

If I am not mistaken the analogy of wifi would be to pull out a cable of an ethernet interface. If you do it rapidly the interface might not restart. Ifup on the other hand will force the interface to go down and then back up, forcing dhcp discovery.

Ciao Giulio. Ho trovato il tuo post seguendo quello che avevi pubblicato su inforge.net.
Ammiro molto la tua capacità di scrivere scripts e farli girare su openwrt. Continuo in inglese.

Dear Giulio, can you explain a bit more what did you do here?
I have a simple router with openwrt, I installed the full wpad package to manage MSCHAPV2 authentication needed by WOWFI connection, and now I can connect several devices through the router.
Unfortunately I experience the same problem you're trying to solve.
I have two physical interfaces (radios), one on 2.4 and one on 5ghz
I use the ability to create a virtual interface, and use that as CLIENT to connect on 2.4ghz radio
I have a domestic network based on other virtual interfaces on both 2.4 and 5ghz

How can I modify the script you created to reset the connection, but only to the virtual interface created for WOWFI?
Can I provide you any log? I can connect on SSH, to help you understand.

Thank you very very much for your time.
Congratulations,
Gabriel

Thank you for your appreciation, I just wrote a couple of lines to reset the connection but i'm not an oper-wrt expert.

Probably what you need is to change the
"wifi"
in my script with
"ifup ---interfaceNameYouWantToReset---"

the logical interface you want to restart can be found on

/etc/config/network

and should be the one where the WOW-FI virtual wifi interface is connected. (You can check it in the /etc/config/wireless file).

Let me know if you are able to work it out. Regards.

1 Like

Hey Giulio, I guess I was able to install the script. I mainly used winSCP, even to make links in /etc/rc.d/
It was a very dirty job, but I think I made it. Instead of wifi I used ifup wifinet0, as it is the virtual interface created in /etc/config/wireless for the WOWFI station mode. Maybe I mistook your indications, though. Only the interfaces in /etc/config/network can be called?

I don't know how to verify that everything is working as expected. Unfortunately the bandwidth falls still very low, as low as 1 Mbit/s or a little more. As you noted, Fastweb implements both a renewal of IP, and a choke of bandwidth. It seems your script doesn't bypass the choke.

Question, for you @GiulioBen, or for someone with a more recent build (maybe @lleachii as he seems to master all things openwrt! ):
My build is based on 19.07.2. The manual solutions to the several problems I always do are:

  1. click on Disable/Enable button of the virtual interface assigned to WOWFI, as in picture 1

  2. click restart on the whole radio, but has the effect of dropping all ESSIDs on that radio, as in picture 2:

I would prefer to implement the first solution as it solves the problem completely, and does not interfere with the other wireless connections. What is the command (or the chain of commands) I have to change instead of this:

As usual, my total admiration and gratitude for the time you spend.
I'm happy I managed to install the script, but if you saw the procedure I executed, you would probably laugh a lot. I'm doing things with the mercy of luck.

Sincerely and humbly dumb,
Gabriel

From here:

Individual interfaces can be brought up with ifup name or down with ifdown name where name corresponds to the logical interface name of the corresponding config interface section. An ifup implies a prior ifdown so there is no need to invoke both when reloading an interface.

Note that wireless interfaces are managed externally and ifup may break the relation to existing bridges. In such a case it is required to run wifi up after ifup in order to re-establish the bridge connection.

My script just check is the connection is up by pinging google and, if not, after many attempts (maxDown) execute the part

#ifup wwan #which is better?
wifi
sleep 40

After 25 consecutives wifi restarts the entire device is rebooted.

So the point is: what to write instead of the quoted part above?

I suggest you to connect via ssh and then:

ifconfig wifinet0 | grep addr
and save your actual IP of the connection.

The try to restart the client network

ifup wifinet0

whait a minute and retry

ifconfig wifinet0 | grep addr

if the ip is changed and your access point has not released your devices, you have found what you need.

You can try other combos with ifup (or wifi up), just to check which command is more appropriate.

Let me know!

Ok thanks for the answer. So apparently ifup is a command only for interfaces of file network and not for interfaces of wireless, then?

Regarding:

Unfortunately this happens:

root@OpenWrt:~# ifconfig wifinet0 | grep addr
ifconfig: wifinet0: error fetching interface information: Device not found

if i run ifconfig alone these are the only interfaces I see, and ifconfig *** | grep addr is answering only to the following interfaces...

root@OpenWrt:~# ifconfig
**br-lan**    Link encap:Ethernet  HWaddr B0:7F:B9:C8:95:E0
          inet addr:192.168.1.1  Bcast:192.168.1.255  Mask:255.255.255.0
          inet6 addr: fd52:66c3:41ef::1/60 Scope:Global
          inet6 addr: fe80::b27f:b9ff:fec8:95e0/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:1225861 errors:0 dropped:5 overruns:0 frame:0
          TX packets:2589123 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:125501612 (119.6 MiB)  TX bytes:2872996437 (2.6 GiB)

**eth0**      Link encap:Ethernet  HWaddr B0:7F:B9:C8:95:E0
          inet6 addr: fe80::b27f:b9ff:fec8:95e0/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:1186038 errors:0 dropped:0 overruns:0 frame:0
          TX packets:2817208 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:143152605 (136.5 MiB)  TX bytes:2799353773 (2.6 GiB)
          Interrupt:17

**eth0.1**    Link encap:Ethernet  HWaddr B0:7F:B9:C8:95:E0
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:1178370 errors:0 dropped:0 overruns:0 frame:0
          TX packets:2538353 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:121458697 (115.8 MiB)  TX bytes:2754118481 (2.5 GiB)

**eth0.2**    Link encap:Ethernet  HWaddr B0:7F:B9:C8:95:E1
          inet6 addr: fe80::b27f:b9ff:fec8:95e1/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:0 errors:0 dropped:0 overruns:0 frame:0
          TX packets:25781 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:0 (0.0 B)  TX bytes:8700238 (8.2 MiB)

**lo**        Link encap:Local Loopback
          inet addr:127.0.0.1  Mask:255.0.0.0
          inet6 addr: ::1/128 Scope:Host
          UP LOOPBACK RUNNING  MTU:65536  Metric:1
          RX packets:138777 errors:0 dropped:0 overruns:0 frame:0
          TX packets:138777 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:13970981 (13.3 MiB)  TX bytes:13970981 (13.3 MiB)

**wlan0**     Link encap:Ethernet  HWaddr B0:7F:B9:C8:95:E0
          inet addr:100.93.5.173  Bcast:100.93.63.255  Mask:255.255.192.0
          inet6 addr: fe80::b27f:b9ff:fec8:95e0/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:50926 errors:0 dropped:0 overruns:0 frame:0
          TX packets:42155 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:33661475 (32.1 MiB)  TX bytes:9353240 (8.9 MiB)

**wlan0-1**   Link encap:Ethernet  HWaddr B2:7F:B9:C8:95:E0
          inet6 addr: fe80::b07f:b9ff:fec8:95e0/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:0 errors:0 dropped:0 overruns:0 frame:0
          TX packets:2069 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:0 (0.0 B)  TX bytes:234272 (228.7 KiB)

**wlan1**     Link encap:Ethernet  HWaddr B0:7F:B9:C8:95:E4
          inet6 addr: fe80::b27f:b9ff:fec8:95e4/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:47543 errors:0 dropped:0 overruns:0 frame:0
          TX packets:71851 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:4711608 (4.4 MiB)  TX bytes:125363307 (119.5 MiB)

but as in /etc/config/wireless

root@OpenWrt:~# cat /etc/config/wireless

config wifi-device 'radio0'
        option type 'mac80211'
        option channel '11'
        option hwmode '11g'
        option path 'pci0000:00/0000:00:01.0/0000:02:00.0'
        option legacy_rates '0'
        option country 'US'
        option txpower '20'
        option htmode 'HT20'

config wifi-iface 'default_radio0'
        option device 'radio0'
        option network 'lan'
        option mode 'ap'
        option key 'mypassword'
        option ssid 'Genius'
        option encryption 'psk2'

config wifi-device 'radio1'
        option type 'mac80211'
        option channel '36'
        option hwmode '11a'
        option path 'pci0000:00/0000:00:00.0/0000:01:00.0'
        option country 'US'
        option htmode 'VHT40'
        option txpower '19'

config wifi-iface 'default_radio1'
        option device 'radio1'
        option network 'lan'
        option mode 'ap'
        option key 'mypassword'
        option encryption 'psk2'
        option wpa_disable_eapol_key_retries '1'
        option ssid 'Genius AC'
>
**config wifi-iface 'wifinet0'**              .................. **<---- QUESTA!!!**
        option ssid 'WOW FI - FASTWEB'
        option device 'radio0'
        option mode 'sta'
        option network 'WOWFI'
        option password 'mypassword'
        option encryption 'wpa2'
        option eap_type 'peap'
        option identity 'myidentity'
        option auth 'EAP-MSCHAPV2'
        option disassoc_low_ack '0'
        option eap_reauth_period '0'
        option skip_inactivity_poll '1'
        option short_preamble '0'
        option wpa_group_rekey '780'

config wifi-iface 'wifinet4'
        option ssid 'androidAP'
        option device 'radio0'
        option mode 'sta'
        option key 'mypassword'
        option network 'androidTether'
        option encryption 'psk2'
        option disabled '1'

config wifi-device 'radio2'
        option type 'mac80211'
        option path 'platform/1e1c0000.xhci/usb1/1-2/1-2:1.0'
        option hwmode '11g'
        option channel 'auto'
        option disabled '1'

config wifi-iface 'default_radio2'
        option device 'radio2'
        option network 'lan'
        option mode 'ap'
        option ssid 'OpenWrt'
        option encryption 'none'
        option disabled '1'

config wifi-iface 'wifinet5'
        option ssid 'WOW FI - FASTWEB'
        option device 'radio2'
        option mode 'sta'
        option network 'WOWFIusb'
        option password 'mypassword'
        option encryption 'wpa2'
        option eap_type 'peap'
        option identity 'myidentity'
        option auth 'EAP-MSCHAPV2'
        option disabled '1'

wifinet0 is my target. If I succeed using this I think I have no problems no more.
But ifconfig wifinet0 | grep addr doesn't work. Dumbly dunno why. :grimacing:

Strange fact:
I think I witnessed a script action. The WOWFI connection was just 1Mbit/s, and suddenly the Virtual Interface wifinet0 went down and up, recovering its usual 130 Mbit/s.
It took some seconds to reappear. So I might have proof of work!
Now, @GiulioBen, suggested tweaks, since you know how to write a script! :yum:

  • Can we change somehow this:
intCheck() {
ping -c1 openwrt.org &>/dev/null
if [ $? -eq 0 ]; then
return 0
else
ping -c1 www.google.com &>/dev/null
if [ $? -eq 0 ]; then
return 0
else
return 1
fi
fi

so that besides absence of ping, it will not tolerate a low bandwidth too?
(l'assenza di ping si può manifestare anche molto tempo dopo l'inizio di degradazione di banda, per cui prima che lo script riconosca il problema e agisca la rete può essere inutilizzabile già da molto tempo. Suggerisco, se possibile, una verifica che attivi il trigger di "reset interface" anche in presenza di una connessione sotto i 12Mbit/s, per esempio. Sarebbe una soluzione sia per il necessario cambio di IP ogni 15 minuti che per la rete strozzata.)

  • What do we have to change in the script to make your magic happen in the smallest possible time?

What of these two happen?

  1. Your script finds the problem, waits 40 seconds and reset

  2. Your script finds the problem, immediately resets and wait 40 seconds to start again ping

What happens if we reduce
sleep 40
to
sleep 10 ???

Sorry for all these questions. Do I look like a scholar exposing his report? :laughing: :laughing: it is exactly like I feel. Nice, considering my age.

Hope I'm not bothering you too much. I'm very happy, because your (relatively) simple script is giving me chance to learn, and understand. So thank you @GiulioBen, really.

Aspetterò la risposta con calma, dato che solo per leggere tutto questo ci vuole un pò. Non ho il dono della sintesi, purtroppo.

Since the IP settings (static, dinamic) and all the firewall rules are linked to the 'interface' (i.e. the one in /etc/config/network) it's more logical to reset this one instead of the mere wifi-iface.

Yes, my fail.
I wrote it in a rush and I made this mistake.

Ifconfig refers to the kernel names of the network interfaces. So you want to check the wlan0.

The scheme should be the following

look at the /etc/config/wireless:

wifi-device: radio0

wifi-iface: wifinet0
-> this uses the device radio0 (option device 'radio0')
-> this is linked to the network WOWFI

so in /etc/wireless/network you have (I guess, because you have not posted it, correct me if i'm mistaking)

config 'interface' 'WOWFI'
___option 'proto' 'dhcp'

and this interface it what you want to restart!

Instead of the changes in the IP address, which is not necessarily changed on wifi restart, check the network traffic:

ifconfig wlan0 | grep bytes

this displays the bytes you transmitted through the interface.

Launch

ifup WOWFI

and it should restart only the interface (/etc/config/network) to which the wifinet0 is linked.

If repeating

ifconfig wlan0 | grep bytes

the counter is resetted you have found what you need.

If it works I suggest you to change "wifi" in my script with "ifup WOWFI".

I'll think about the bandwidth issue you mentioned. I might not be immediate since if you are downloading the script might detect a low bandwidth and reset the interface, which is not what we want.

When you notice a decrease in the network speed, do you observe a lower synchronization speed? I mean, in the web interface of the router you see the network sync speed, which is the maximum speed you can achieve through the connection in this moment...
If this speed is decreased by the fastweb router, there might be a chance to make things easier...

If the speed is decreased through QoS, it might be more complicated.

Best

I added a couple of lines to the script.

Now I introduced the feature you need. You have to carefully set all the options, because if you hava a fast connection you risk to full all the /tmp/ file system in few seconds. Furthermore please notice that wget does not download in parallel, so try when your connection is working fine what's the normal speed you get.

If you want to use the speed instead of the ping, change set the useSpeed variable to 1.

Adjust the repetition rate of the test (sleep $(expr 5 + 55 * $useSpeed)) just to avoid downloading GB of data for this small check.

I had to introduce waitTime to avoid underestimating the connection speed due to server lag. Set the variable as low as possible for your router.

Please note that saturating your connection you cause the script to see a slow connection and to reset the wifi. To avoid this set maxTimesSlow to higher numbers (i guess that once FastWeb slow you down you stays slow for hours, so just use something like 30 in this case.

Let me know if it works!

#!/bin/sh

################ settings ###############

maxRestart=5 # how many times consecutively restart the interface before restarting the router

#for ping

maxDown=3 # how many times the ping can fail before restarting the network interface

#for speed

useSpeed=0 # 0 = use ping; 1 = use speed
minSpeed=20  # kB/s = kBYTES per second
maxTimesSlow=2 # it needs to find a slow connection for maxTimesSlow before resetting the interface
waitTime=4 #seconds to wait before speed test, transient part
downTime=4 #seconds of additional downloading to check the speed

# WARNING: carefully check if the space in your device is enough and adjust times accordingly!
# df /tmp -h # <---- check the available free space
# estimatedFileSize = estimatedSpeed * (waitTime + downTime) # <---- estimate the file size
# where estimatedSpeed is the MAX speed you ever achieved with your connection

########################################

pingCheck() {  #try to ping google and openwrt. Return 0 if no errors, 1 if cannot ping
	ping -c1 openwrt.org &>/dev/null
	if [ $? -eq 0 ]; then
		return 0
	else
		ping -c1 www.google.com &>/dev/null
		if [ $? -eq 0 ]; then return 0 ;	fi
    return 1
	fi
}

speedCheck() {
  wget http://speedtest.wdc01.softlayer.com/downloads/test500.zip -O /tmp/tmpdwn >/dev/null 2>/dev/null  & #start downloading a file
  sleep $waitTime #waits for the steady state
  downSize=$(du /tmp/tmpdwn | cut -d$'\t' -f1) #save the actual size
  sleep $downTime
  killall wget
  downSize=$(expr $(du /tmp/tmpdwn | cut -d$'\t' -f1) - $downSize) # differential size
  downSpeed=$(expr $downSize / $downTime) #speed in kB/s
  if [ $downSpeed -ge $minSpeed ]; then return 0 ; fi
  return 1
}

updatePingCounter() { #update the counters of ping
	if pingCheck; then
		downCounter=0
    rebootCounter=0
	else
		downCounter=$(expr $downCounter + 1)
		touch /root/wifiRebootsCounter.log
	fi
  return 0
}

updateSpeedCounter() { #update the counters of speed
	if speedCheck; then
		slowCounter=0
    rebootCounter=0
	else
		slowCounter=$(expr $slowCounter + 1)
		touch /root/wifiRebootsCounter.log
	fi
  return 0
}

act() {
	downCounter=0
  slowCounter=0
	rebootCounter=$(expr $rebootCounter + 1)
	echo $(date) >> /root/wifiRebootsCounter.log
	if [ $rebootCounter -gt $maxRestart ]; then
    echo $(date) >> /root/fonRebootsCounter.log
		reboot
	fi
#	what to do when the connection is not working?
	wifi
	sleep 40
}

#resetting counters
downCounter=0
rebootCounter=0
slowCounter=0

while [ 1 ]; do
	[ $useSpeed -eq 0 ] && updatePingCounter || updateSpeedCounter
	sleep $(expr 5 + 55 \* $useSpeed)
	if [ $downCounter -gt $maxDown ] || [ $slowCounter -gt $maxTimesSlow ]; then act; fi
done

1 Like

Giulio, thanks again for your answers.

Sorry I forgot network but you're totally correct.

The big picture is getting every time more clear, thanks to your explanations.

I will report soon about the implementation of your actual script, and hope to just say "it works perfectly".

About the improvements I was suggesting, I'd like to help more than I know how.

In this image you can see what I'm referring to:


In the RX / TX field you can see now an acceptable value. 39Mbit is not bad, but it gradually decreases. Once it shows 5.5Mbit, the WOWFI connection is already unusable since several time.
This suggests that number is only statistic, and not a real-time indication of the bandwidth, because 95% of times if it shows 5.5Mbit it is already dead.
I hope this answers to the question about the synchronization speed. I've never heard of it. Dunno precisely what you mean, but I hope this answer opens the door to a possible "bandwidth check and reset method" instead of the one with ping.
Same for QoS. Quality of Service? How does it relate? Why is it bad news? Dumbly don't know.
But as I have some tiiiiiiiiny know how, and I can post logs here, if I can help improving your script I'm more than happy to do it.
As you know reading forums around in Italy, this problem with WOWFI is a very common issue for a lot of people. You can tell everybody "I found a definitive solution to this stupid problem!"

My deepest regards,
Gabriel

P.S: a little detail. The modem I'm hooking is just on the other side of the wall. The interferences and degradation of wireless signal are not a problem for me. Therefore, all behaviour is almost "100% pure FASTWEB fault", and not some other variable that would make things more difficult to debunk. I thought it was good to mention.

Ahahahahahah!
How modest.

Are these a couple of lines for you?

I'll take ages to vaguely understand how to tweak it!

Immensely grateful. Will post soon (hopefully) and say "it works perfectly"

You deserve a prize.
Regards,
Gabriel

Ok. Installed the script. I have 60Mb of free space in /tmp, but very lazy connection times, so I set

waitTime=6
downTime=5

and

maxTimesSlow=2

and hope the salvaged Netgear R6220 survives it. I'm basically staring at the screen as an alien looking for malfunctions. I don't know how to empirically verify things, on owrt.

This part makes me confused:

as I don't really know how to interpret this expression. Any suggestion, Master Giulio? What is 5 + 55 x 1? Sleep for 60 seconds? :exploding_head:

And finally

estimatedSpeed is the MAX speed you ever achieved with your connection

is Ookla set on "multi connection" a good reference?
I see

wget http://speedtest.wdc01.softlayer.com/downloads/test500.zip -O /tmp/tmpdwn >/dev/null 2>/dev/null

and a download of test500.zip averaged on the 4.6 to 5.3 Mbit/s, on the WOWFI I'm connected now, but I get way higher scores on "multi ookla" (90mbit/s download & 35mbit/s upload).

Thank you, Master. I'll report.
You get ready to tell the Italians you solved the hassle. :laughing:

A total of 11s, if you actually have 100Mb/s of connection might download 140MB, so I think you increased too much the time.

Pay attention to the units of measurements: 1B (Byte) = 8b (bit).

df gives you the B, so you probably have 60MB and not Mb of free space.
when you talk of connections, you usally adopt bits (speedtest, the web interface of the router

I'd use something like waitTime=2; downTime=3 so that in the limit case of a full 100Mb/s bandwidth you download 100Mb/s * 5s / 8b/B = 62MB.

maxTimesSlow=2
repeats the test sequentially, so you free up the space of the preceeding test. Increasing this value avoids that the slow connection due to a file download of a few minutes triggers the script.

If you want to test the script you can copy it to a notepad, (substitute the tabs with spaces), connect through ssh and launch part of the script. For instance, you can try

waitTime=4
downTime=4 
wget http://speedtest.wdc01.softlayer.com/downloads/test500.zip -O /tmp/tmpdwn >/dev/null 2>/dev/null  & 
sleep $waitTime 
downSize=$(du /tmp/tmpdwn | cut -d$'\t' -f1) 
sleep $downTime
killall wget
downSize=$(expr $(du /tmp/tmpdwn | cut -d$'\t' -f1) - $downSize)
downSpeed=$(expr $downSize / $downTime)

adding the line
echo $downSpeed
to see the connection speed. Use
du /tmp/tmpdwn
to see the size of the file you downloaded.

It's probably something makes real programmers horrify... you can change it with
[ $useSpeed ] && sleep 5 || sleep 60
or the corresponing if statement

if [  $useSpeed -ge 1 ]; then  sleep 55; fi
sleep 5

Let's do this check:

  1. connect through ssh
  2. launch this
wget http://speedtest.wdc01.softlayer.com/downloads/test500.zip -O /tmp/tmpdwn  & 
sleep 5
killall wget

what speed do you get? Be sure on the unit of measurement.

If it's slower than the speedtest from your computer there might be several reasons:

  1. Your flash memory (/tmp/) if full -> decrease the waitTime and downTime
  2. The file should be downloaded in parallel -> we can create multiple parallel wget instances but we have to decrease the file size again..
  3. the flash memory of your router is too slow -> we can write it to the ram but we have to check again how much ram is free (report the results of free command)

On the other hand, if you say the sync speed (RX/TX rate) is decreased we can look for the way to get it and reset the connection when it falls below a certain threshold. Or maybe force the connection to a certain values.

I'll think about it tonight.

Hope it helps!

Hello master.
So, I can confirm the script works. I'll post separately the result of the commands you asked.

This morning I made a video conference, as it happens often, in these days.
I can sadly confirm the "speed method" interferes quite a bit in the personal traffic. Everytime the script calls the speedtest there is a sudden degradation of quality in the video call, obviously.
On top of that, I still had to reset manually two times, as the wifi command works, but sometimes it needs to be repeated more than once.
If you have some spare time and enthusiasm to do it, I'll gladly test a version of the script that launches wifi when triggered by some sort of verification on the sync speed.
My limited deduction abilities suggest that this method does not require the speedtest part, and is therefore much lighter on prerequisites. Would it just nicely look at RX/TX sync speed and reset under set circumstances? My router is medium-good quality, but someone else could be running your script on a very limited device with almost no resources. (I think for example all the salvaged 4/16MB devices out there, luckily running owrt to be still useful devices nowadays).

If you manage making settings in the threshold like you did with the speedtest method, everyone could set his own threshold based on what knows to be the ideal value. I know my ideal case would be a range of 130Mbit/s (maxAchievable) and 24Mbit/s = do nothing. Lower than 24Mbit/s = reset repeatedly until back to acceptable range. Again, this suggestion is to keep the script light, and have 100% positive result with no fails, but I might be overlooking things I have no knowledge of.
RX/TX check & react method is looking promising to me as very light, effective and globally compatible, but you surely know better.

Again, as everytime, my most sincere applause to your know-how,
Gabriel

Hi Giulio, here are the details you where asking in the previous post.

Yes, my fault. The difference between bits and bytes is clear to me, sorry for making confusion.
Here is the available space on my router:

root@OpenWrt:~# df /tmp -h #
Filesystem                Size      Used Available Use% Mounted on
tmpfs                    60.5M    320.0K     60.2M   1% /tmp

Unfortunately, this script, copied and saved in linux:

gives this error:

root@OpenWrt:/# ./test.sh
-ash: ./test.sh: Permission denied

Surely there's something very very banal I'm doing wrong. :man_facepalming:

About this:

I'm sorry, I didn't mean it is ugly! I wouldn't dare, as i'm barely understanding what you do! I'm ignorant and I know it! I only mean that I don't know what is the function of this line!
Is it to make a speedtest every minute or so?

And finally, about this:

I'm having problems launching the command all together, because copying and pasting in putty the lines you wrote launches a download and it doesn't stop it after 5 seconds. Therefore this happens:

I removed the killall wget part because the router goes -stalled- before it can do anything else.
I then remove the tmpdwn file with winSCP, so no problem.
I repeated the process several times (on WIndows and on Linux VM), making different attempts with the three lines (tutto in una linea, a capo dopo sleep 5, a capo dopo &...), but it always continue the download until -stalled-, and it never show $downSpeed.
I'm very sorry I always need to ask for clarifications. I'm sure the solution is very easy, and I'm sure I'm not your best assistant, delivering logs with no hassle. I'm a goat.

Again,
with apologies and admiration,
Gabriel

probably you have to give him right to execute: go in the folder and type

chmod 777 test.sh

and it should be fine. If not, just use

chown root test.sh

Btw you overestimate me, I'm just a mid-low user of linux and openwrt.

these are 3 different lines!
wget ..... & (endline)
sleep 5 (endline)
killall wget

If you paste together the first two lines ash waits for the wget to finish before starting sleeping! Indeed the download full the free space without ending (stalled)!

I got a couple of ideas... but i'm not sure they will work.

The first one is:

  1. connect though ssh when the speed of the wifi is decrease due to the fastweb cap
  2. launching "iwconfig wlan0" you should be able to see the 'WOW-FI' settings, including something like Bit Rate: 1 Mb/s...if you can't find the WOW-FI ESSID just try "iwconfig" and scroll until the correct network.
  3. type

iwconfig wlan0 rate 54M

It should force the board to a defined bitrate. You can check it again with iwconfig or with the router web-page.
If is solve the problem, it's done.

If not I will write a new function to reset the wifi when the bitrate is too low.

Let me know!!

Have a nice week.

Ciao Giulio. Grazie mille per la pazienza e la perseveranza. Magari non sei il programmatore migliore su questa piattaforma, ma sei di gran lunga migliore di tutti quelli che sbuffano quando gli chiedi aiuto. Tanta roba. Grazie. Di seguito le cose che chiedevi:

This is the test script:

waitTime=4
downTime=4 
wget http://speedtest.wdc01.softlayer.com/downloads/test500.zip -O /tmp/tmpdwn >/dev/null 2>/dev/null  & 
sleep $waitTime 
downSize=$(du /tmp/tmpdwn | cut -d$'\t' -f1) 
sleep $downTime
killall wget
downSize=$(expr $(du /tmp/tmpdwn | cut -d$'\t' -f1) - $downSize)
downSpeed=$(expr $downSize / $downTime)
echo $downSpeed

After change to rights in the test.sh

root@OpenWrt:/# chmod 777 test.sh

the result of the script is

root@OpenWrt:/# ./test.sh
4411

I guess 4411 Kbps is fine, but not stellar. The server is not very fast.
Anyway, this result is while the WOWFI connection is with RX TX sync speed at 130/130. So while Fastweb allows connection to the host modem at full speed. By the way, the tmpdwn file does not get erased after. Is it meant to stay in the tmp folder?

Then I launched on my pc a download of

http://debian.fastweb.it/debian-cd/10.6.0/amd64/iso-bd/debian-edu-10.6.0-amd64-BD-1.iso

Because it is on Fastweb server and I reached an average of 36Mbps. That was enough for WOW-FI! :laughing:
After only a few minutes they capped my connection, and I started launching the commands...but...in 19.07.2 apparently iwconfig has been superseeded by iw and iwinfo. I took ages to learn, but the steps you asked have been accomplished with these two new commands:

root@OpenWrt:~# iw dev wlan0 link
Connected to 9e:97:26:62:78:0a (on wlan0)
        SSID: WOW FI - FASTWEB
        freq: 2412
        RX: 12362372 bytes (24213 packets)
        TX: 2118300 bytes (8849 packets)
        signal: -85 dBm
        rx bitrate: 1.0 MBit/s
        tx bitrate: 6.5 MBit/s MCS 0

        bss flags:      short-preamble short-slot-time
        dtim period:    3
        beacon int:     100

And I tried to apply a fixed bitrate for the interface, by running:
root@OpenWrt:~# iw dev wlan0 set bitrates ht-mcs-2.4 11

but unfortunately this applies only to the RX, and not the TX, which remains the same...
(I choose the number 11 having a look at this table)

(ignore the RX speed, I had to reset the interface)

So, today I feel a bit more intelligent, but all around there are no good news.
iwconfig is ufficially deprecated.

RAGIONAMENTI:
Provo ad ipotizzare una cosa. il sync speed che vediamo nella GUI non è altro che l'adattamento delle interfacce wifi alla velocità della banda passante. Se Fastweb strozza, dopo un pò il router riduce le velocità, anche per una questione di consumi, immagino. Se poi vede di nuovo tanta banda passante, le ri-aumenta. Questo però non succederà, perchè Fastweb ha ridotto la banda, e non aumenta finchè non si lancia un reset.
Se lo script legge il sync speed e lo trova sotto HT-MCS 9 (di nuovo da quì) può dedurre con un certo margine di certezza che qualcosa non va, e vale la pena di resettare la rete. Spero che tu riesca a scrivere qualcosa del genere, con i nuovi standard di trasmissione su 2.4 e 5GHz...

Questo è l'help che mi da iw per capire come si setta il comando riguardo al bitrate...magari ti può essere utile!

root@OpenWrt:~# iw help set bitrates
Usage:  iw [options] command
Options:
        --debug         enable netlink debugging
        --version       show version (5.0.1)
Commands:
        dev <devname> set bitrates [legacy-<2.4|5> <legacy rate in Mbps>*] [ht-mcs-<2.4|5> <MCS index>*] [vht-mcs-<2.4|5> <NSS:MCSx,MCSy... | NSS:MCSx-MCSy>*] [sgi-2.4|lgi-2.4] [sgi-5|lgi-5]
                Sets up the specified rate masks.
                Not passing any arguments would clear the existing mask (if any).


Commands that use the netdev ('dev') can also be given the
'wdev' instead to identify the device.

You can omit the 'phy' or 'dev' if the identification is unique,
e.g. "iw wlan0 info" or "iw phy0 info". (Don't when scripting.)

Do NOT screenscrape this tool, we don't consider its output stable.

O magari ti può essere ancora più utile iwinfo, più snello e rapido:

root@OpenWrt:~# iwinfo wlan0 info
wlan0     ESSID: "WOW FI - FASTWEB"
          Access Point: B0:7F:B9:C8:95:E0
          Mode: Client  Channel: 1 (2.412 GHz)
          Tx-Power: 20 dBm  Link Quality: 61/70
          Signal: -49 dBm  Noise: unknown
          Bit Rate: 130.0 MBit/s
          Encryption: WPA2 802.1X (CCMP)
          Type: nl80211  HW Mode(s): 802.11bgn
          Hardware: 14C3:7603 14C3:7603 [MediaTek MT7603E]
          TX power offset: none
          Frequency offset: none
          Supports VAPs: yes  PHY name: phy0

Ah, un'altra considerazione importante...in risposta a quello che chiedevi all'inizio...

posso dirti con certezza che nel mio caso ifup WOWFI funziona egregiamente e risolve nel giro di pochissimi attimi, mentre il comando wifi crea un terremoto su TUTTE le radio del router, e fra riavvio delle radio e handshake da parte dei dispositivi connessi ci vogliono svariati secondi. Io continuerei con ifup, che è snello e funziona bene, in particolare per non dover mettere sleep di svariati secondi fra una funzione e l'altra. Sarà anche un comando più completo di ifup, ma nel problema specifico causato da fastweb non serve altro che ifup <VirtualInterface> !

Spero di esserti stato utile. Scusa se sono sempre così prolisso. Ci siamo quasi Giulio!!!! (iwconfig permettendo)

Buonanotte e grazie ancora.

One (other) important thing!
Besides the sync speed function, the ping check is still necessary, as sync speed is not necessarily lowered every time.

So, combination of sync check and ping check is the way, IMHO.

Buona settimana a te,
Gabriel