WOW-FI reconnection with fonera

4411 kBps = chilobaits not kb chilobits per second.
It's actually not that bad! more than 30Mbps

It's overwrited at the next check. Anyway add

rm /tmp/tmpdwn

after downSpeed=$(expr $downSize / $downTime) #speed in kB/s
if you want to erase it to free space

It's impressive how scarce is the documentation on this point. I found a couple of forums but nothing official.

Sorry, I used the first openwrt device I found to test the script and it was very old. I'll go on with the new functions.

You argue that the host router throttle the band and that the lower bitrate is a consequence whereas I was guessing the opposite (i.e. that the router was lowering the band to decrease the available speed). In the first case I'll be useless to increase the bitrate since the speed is managed from the QoS of the host fastweb router and we can only hope to reset the connection. Maybe someone more expert might help us!

Let's move to the other solution. I can't verify by myself that the code is working since I don't have a recent openwrt device. Anyway you should check if all these commands extract the bit rate from the iwinfo and iw commands.

iwinfo wlan0 info | grep "Bit Rate" | cut -d$':' -f2 | cut -d$'M' -f1
iw dev wlan0 link | grep "rx bitrate" | cut -d$':' -f2 | cut -d$'M' -f1
iw dev wlan0 link | grep "tx bitrate" | cut -d$':' -f2 | cut -d$'M' -f1

I don't even know the difference between them...I'll use the first one.

I rewrote the entire script removing the useless stuffs

#!/bin/sh
################ settings ###############

minSpeed=8 #Mbps

debouncerMax=3   #how many times check before resetting
waitBetweenChecks=10 #second between checks

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

syncCheck() {
  if command -v iwinfo &> /dev/null
  then
    actSpeed=$(iwinfo wlan0 info | grep "Bit Rate" | cut -d$':' -f2 | cut -d$'M' -f1)
  else
    actSpeed=$(iwconfig ath0 | grep Bit | cut -d$':' -f2 | cut -d$' ' -f1)
  fi
  [ $actSpeed -lt $minSpeed ] && touch /root/wifiRebootsCounter.log && return 1
  return 0
}

act() {
  echo $(date) >> /root/wifiRebootsCounter.log
  #  what to do when the connection is not working?
  ifup WOWFI
}

debouncer=0  
while [ 1 ]; do
  syncCheck && debouncer=0 || debouncer=$(expr $debouncer + 1 )
  sleep $waitBetweenChecks
  [ $debouncer -gt $debouncerMax ] && act
done

I used ifup in this case. Wifi disconnect and reconnect all the wifi devices.

In the upper part you can change the wait time (between checks) and a couple of other stuffs...take care of not adding spaces before and after the =!

If you prefer you can schedule a systematic reboot (E.g. at 4.00 am?).

Let me know if it works!

1 Like

Another night spent tinkering! Yessss! :grin:
I'll immediately check what is the result with the new script!

Thank you a huge bunch! This is getting very exciting, thanks to your collaboration!

Hello Giulio, timely update on the script

All these commands work as expected.
The first only looks for the highest bitrate managed by wlan0 (in my case TX is always higher than RX)
The second looks for the INCOMING sync speed
The third looks for the OUTGOING sync speed

So everything fine. In your script I substituted the first "Bit rate" command with the second "rx bitrate" as it is the most variable sync speed.

But still, the sync speed alone is not enough to warrant constant connection.
I can demonstrate it with these commands I launched during a tipical WOW-FI lock:

root@OpenWrt:~# iwinfo wlan0 info | grep "Bit Rate" | cut -d$':' -f2 | cut -d$'M
' -f1
 130.0
root@OpenWrt:~# iw dev wlan0 link | grep "rx bitrate" | cut -d$':' -f2 | cut -d$
'M' -f1
 130.0
root@OpenWrt:~# iw dev wlan0 link | grep "tx bitrate" | cut -d$':' -f2 | cut -d$
'M' -f1
 130.0
root@OpenWrt:/# ping openwrt.org
ping: bad address 'openwrt.org'
root@OpenWrt:/# ping google.com
ping: bad address 'google.com'

You can see the sync speed is still full throttle, but there is no PING from openwrt.org and google.com

Therefore, after

syncCheck() {
  if command -v iwinfo &> /dev/null
  then
    actSpeed=$(iw dev wlan0 link | grep "rx bitrate" | cut -d$':' -f2 | cut -d$'M' -f1)  # OPPURE iwinfo wlan0 info | grep "Bit Rate" | cut -d$':' -f2 | cut -d$'M' -f1 #
  else
    actSpeed=$(iwconfig ath0 | grep Bit | cut -d$':' -f2 | cut -d$' ' -f1)
  fi
  [ $actSpeed -lt $minSpeed ] && touch /root/wifiRebootsCounter.log && return 1
  return 0
}

I think we still need some sort of else PING check and act ifup virtual-interface.
So basically a combination of this last script and the first one you wrote.

I would be SOOOOOO happy to do it and propose it to you, but still, being who I am, I still cannot understand how to write the script and add functions, unfortunately.
But I immagine this is very very very close to ultimate solution.

Again, get ready to tell the Italians you solved this STUUUUUUPID problem caused by fastweb,
and take care.

Regards,
Gabriel

P.S: everyday a tiny bit less n00b with your guidance. I'm honoured. :pray:

Hi Gabriel, thank you again for your appreciation, even though i repeat i'm not the expert you think :smiley:
I recycled the pingCheck function from the first script and added is a sequential check before calling the act function.

Remember to change the actSpeed variable and the initial settings as you prefer.

Best!

#!/bin/sh
################ settings ###############

minSpeed=8 #Mbps

debouncerMax=3   #how many times check before resetting
waitBetweenChecks=10 #second between checks

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

syncCheck() {
  if command -v iwinfo &> /dev/null
  then
    actSpeed=$(iwinfo wlan0 info | grep "Bit Rate" | cut -d$':' -f2 | cut -d$'M' -f1)
  else
    actSpeed=$(iwconfig ath0 | grep Bit | cut -d$':' -f2 | cut -d$' ' -f1)
  fi
  [ $actSpeed -lt $minSpeed ] && touch /root/wifiRebootsCounter.log && return 1
  return 0
}

pingCheck() {  #try to ping google and openwrt. Return 0 if no errors, 1 if cannot ping
  ping -c1 openwrt.org &>/dev/null && return 0
  ping -c1 www.google.com &>/dev/null && return 0
  touch /root/wifiRebootsCounter.log && return 1
}

act() {
  echo $(date) >> /root/wifiRebootsCounter.log
  #  what to do when the connection is not working?
  ifup WOWFI
}


debouncer=0
while [ 1 ]; do
  syncCheck && pingCheck && debouncer=0 || debouncer=$(expr $debouncer + 1 )
  sleep $waitBetweenChecks
  [ $debouncer -gt $debouncerMax ] && act
done
1 Like

Installed!

I'll make it settle comfortably and check tonight, during a Netflix session!

Giulio, be proud of yourself in any case. You are clever, and gentle. If you solved the problem you might even become famous, in the italian geek community! :joy:

Later,
Gabriel

Hi Giulio.
I won't say ultimately, but it looks like your script, with some tinkering, is able to solve the problem with WOW FI. Or at least, it resets the connection fast enough to be invisible during streaming, apparently. Dunno if this applies for videocalls too. I'll discover in the next days.
I will just post my settings, but I'll take some more days to double check everything is working fine!

Congrats Giulio! You (probably) made it!

#!/bin/sh
################ settings ###############

minSpeed=39 #Mbps

debouncerMax=1   #how many times check before resetting
waitBetweenChecks=5 #second between checks

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

syncCheck() {
  if command -v iwinfo &> /dev/null
  then
    actSpeed=$(iw dev wlan0 link | grep "rx bitrate" | cut -d$':' -f2 | cut -d$'M' -f1)
  else
    actSpeed=$(iwconfig ath0 | grep Bit | cut -d$':' -f2 | cut -d$' ' -f1)
  fi
  [ $actSpeed -lt $minSpeed ] && touch /root/wifiRebootsCounter.log && return 1
  return 0
}

pingCheck() {  #try to ping google and openwrt. Return 0 if no errors, 1 if cannot ping
  ping -c1 openwrt.org &>/dev/null && return 0
  ping -c1 www.google.com &>/dev/null && return 0
  touch /root/wifiRebootsCounter.log && return 1
}

act() {
  echo $(date) >> /root/wifiRebootsCounter.log
  #  what to do when the connection is not working?
  ifup WOWFI
}


debouncer=0
while [ 1 ]; do
  syncCheck && pingCheck && debouncer=0 || debouncer=$(expr $debouncer + 1 )
  sleep $waitBetweenChecks
  [ $debouncer -gt $debouncerMax ] && act
done

Some quirks...
I think it is all working, with the settings above mentioned, but still, from time to time, the connections does not reset. Now that I set 39 Mbps, everytime that it gets lower than that should trigger a reset, am I right?

Well, launching the script from SSH, this is the strange result.

root@OpenWrt:/# ./restartConnection.sh
sh: 13.0: bad number
sh: 6.5: bad number
sh: 13.0: bad number
sh: 6.5: bad number
sh: 6.5: bad number
sh: 13.0: bad number
sh: 6.5: bad number
sh: 5.5: bad number
sh: 5.5: bad number
sh: 5.5: bad number
sh: 5.5: bad number
sh: 5.5: bad number
sh: 5.5: bad number
sh: 1.0: bad number
sh: 13.0: bad number
sh: 6.5: bad number
sh: 6.5: bad number
^C

But ping from sites is still present

root@OpenWrt:/# ping google.com
PING google.com (172.217.21.78): 56 data bytes
64 bytes from 172.217.21.78: seq=0 ttl=117 time=11.853 ms
64 bytes from 172.217.21.78: seq=1 ttl=117 time=11.989 ms
64 bytes from 172.217.21.78: seq=2 ttl=117 time=12.796 ms
64 bytes from 172.217.21.78: seq=3 ttl=117 time=12.052 ms
64 bytes from 172.217.21.78: seq=4 ttl=117 time=13.127 ms
64 bytes from 172.217.21.78: seq=5 ttl=117 time=15.600 ms
64 bytes from 172.217.21.78: seq=6 ttl=117 time=12.076 ms
64 bytes from 172.217.21.78: seq=7 ttl=117 time=11.665 ms
64 bytes from 172.217.21.78: seq=8 ttl=117 time=12.494 ms
64 bytes from 172.217.21.78: seq=9 ttl=117 time=36.224 ms
64 bytes from 172.217.21.78: seq=10 ttl=117 time=38.523 ms
^C

I have to manually run ifup WOWFI for the interface to be reset. :man_shrugging:

Maybe it does not trigger because there still is some ping from the sites?

Anyway, the situation here is already improved al lot!
I think it is a matter of fine tune, but it is already excellent!

CONSIDERATIONS:
is there a way to say something like this:
given prerequisites 1) - most important -> check if there is ping, and 2) - for usability -> check if bitrate is in or out the set margin,
then,
if ping fails, immediately reset
if ping does not fail, check for sync speed
if sync speed is out the margin, immediately reset
if sync speed is in the margin,
check again after some seconds

OBVIOUSLY, I dunno shit, so you can always bug me off anytime you want.

Ah, by the way, my installation of the script was very...creative. I used only WinSCP, and I don't know if something is broken. Particularly the links in
/etc/rc.common
/etc/rc.d/

Would you mind explaining the correct way to install and automate your script?
It will be useful when you will explain this to others too!

As usual,
my total admiration and gratitude.

Ciao,
Gabriel

I completely forgot to answer you!!

Regarding the error, probably the number is not correctly extracted from the syncCheck function! May there is a white space before the number or maybe it's a problem with the decimal separator!

Since I don't have access to your device it's very difficult to me to debug the code.. if you want you can provide me via pm a way to access the device so that we can check together what's not working.
Anyway, the first attempt is to

  1. start ssh
  2. paste this
minSpeed=39 #Mbps

debouncerMax=1   #how many times check before resetting
waitBetweenChecks=5 #second between checks

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

syncCheck() {
  if command -v iwinfo &> /dev/null
  then
    actSpeed=$(iw dev wlan0 link | grep "rx bitrate" | cut -d$':' -f2 | cut -d$'M' -f1)
  else
    actSpeed=$(iwconfig ath0 | grep Bit | cut -d$':' -f2 | cut -d$' ' -f1)
  fi
  [ $actSpeed -lt $minSpeed ] && touch /root/wifiRebootsCounter.log && return 1
  return 0
}
  1. launch the syncCheck function

syncCheck

and check if it provide the error.

root@OpenWrt:~# cd /
root@OpenWrt:/# ./test.sh
root@OpenWrt:/# syncCheck
ash: 130.0: bad number
root@OpenWrt:/#

I don't know what you mean by "paste this"...but I copied the text in a shell file and launched it, as you can see.
Maybe your guess is correct. It might be a problem with the decimal separator!

Ah, my owrt version is 19.07.2...and in the versions a lot of things have changed! Yours and mine might differ substantially!

Regards Giulio! Waiting for your help!

i just remembered that expr does not accept non-integer numbers!!

add | cut -d$'.' -f1 to the pipeline to trim the trailing part!

iwinfo wlan0 info | grep "Bit Rate" | cut -d$':' -f2 | cut -d$'M' -f1 | cut -d$'.' -f1
iw dev wlan0 link | grep "rx bitrate" | cut -d$':' -f2 | cut -d$'M' -f1 | cut -d$'.' -f1
iw dev wlan0 link | grep "tx bitrate" | cut -d$':' -f2 | cut -d$'M' -f1 | cut -d$'.' -f1

this shoul solve the problem!

Giulio, you were right, again.
Something in the syncCheck had to be adjusted, and it is now working, I think. It does not say "bad number" anymore. It does not say anything now. If I run the "test.sh" in SSH it does not respond anything.
Following is my test.sh

minSpeed=39 #Mbps

debouncerMax=1   #how many times check before resetting
waitBetweenChecks=5 #second between checks

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

syncCheck() {
  if command -v iwinfo &> /dev/null
  then
    actSpeed=$(iw dev wlan0 link | grep "rx bitrate" | cut -d$':' -f2 | cut -d$'M' -f1 | cut -d$'.' -f1)
  else
    actSpeed=$(iwconfig ath0 | grep Bit | cut -d$':' -f2 | cut -d$' ' -f1)
  fi
  [ $actSpeed -lt $minSpeed ] && touch /root/wifiRebootsCounter.log && return 1
  return 0
}
echo $actSpeed   <----- MY STUPID ATTEMPT TO READ A VALUE

that responds like this in SSH

root@OpenWrt:/# ./test.sh

root@OpenWrt:/#

But...still:
after some minutes downloading a big file, the connection get blocked. Not because of the choke, but because of the other reason...the block of the IP.
Therefore, with the script in this actual form:

#!/bin/sh
################ settings ###############

minSpeed=39 #Mbps

debouncerMax=1   #how many times check before resetting
waitBetweenChecks=5 #second between checks

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

pingCheck() {  #try to ping google and openwrt. Return 0 if no errors, 1 if cannot ping
  ping -c1 openwrt.org &>/dev/null && return 0
  ping -c1 www.google.com &>/dev/null && return 0
  touch /root/wifiRebootsCounter.log && return 1
}

syncCheck() {
  if command -v iwinfo &> /dev/null
  then
    actSpeed=$(iw dev wlan0 link | grep "rx bitrate" | cut -d$':' -f2 | cut -d$'M' -f1 | cut -d$'.' -f1)
  else
    actSpeed=$(iwconfig ath0 | grep Bit | cut -d$':' -f2 | cut -d$' ' -f1)
  fi
  [ $actSpeed -lt $minSpeed ] && touch /root/wifiRebootsCounter.log && return 1
  return 0
}

act() {
  echo $(date) >> /root/wifiRebootsCounter.log
  #  what to do when the connection is not working?
  ifup WOWFI
}


debouncer=0
while [ 1 ]; do
  pingCheck && syncCheck && debouncer=0 || debouncer=$(expr $debouncer + 1 )
  sleep $waitBetweenChecks
  [ $debouncer -gt $debouncerMax ] && act
done

When the connection is blocked I run:

root@OpenWrt:~# iw dev wlan0 link | grep "rx bitrate" | cut -d$':' -f2 | cut -d$
'M' -f1 | cut -d$'.' -f1
 130

And everything seems ok, but running

root@OpenWrt:~# ping google.com
ping: bad address 'google.com'
root@OpenWrt:~# ping openwrt.org
ping: bad address 'openwrt.org'

it clearly shows that WOWFI is inhibited.

By my sense of logic, now that the commands are properly understood by the box, the syntax of the script might be this, dealing with the two methods of Fastweb to inhibit the connection to the host:

Tell me if it makes sense for you too, or maybe your script is already doing this logic, and I simply didn't understand.

P.S: You're very generous and curious. 99% of the population would already have dropped, but not you. Big up!

To conclude the topic: this script appears to work for resetting the connection when fastweb drop it, but it's not enough to keep downloads and web calls alive.

Since I can't update the first post I report here the last optimal configuration:

#!/bin/sh
################ settings ###############

pingDebouncer=1 #how many times attempt ping before resetting the connection
minSpeed=10 #Mbps
waitBetweenChecks=5 #second between checks

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

pingCheck() {  #try to ping google and openwrt. Return 0 if no errors, 1 if cannot ping
  for i in $(seq 1 1 ${pingDebouncer})
  do
    ping -c1 openwrt.org &>/dev/null || ping -c1 www.google.com &>/dev/null && return 0
    sleep 1
  done
  return 1
}

syncCheck() { # return 0 if the speed is more than the minSpeed
  if command -v iwinfo &> /dev/null
  then
    actSpeed=$(iw dev wlan0 link | grep "rx bitrate" | cut -d$':' -f2 | cut -d$'M' -f1 | cut -d$'.' -f1)
  else
    actSpeed=$(iwconfig ath0 | grep Bit | cut -d$':' -f2 | cut -d$' ' -f1 | cut -d$'.' -f1)
  fi
  [ $actSpeed -lt $minSpeed ] && return 1
  return 0
}

act() {
  #  what to do when the connection is not working?
  ifup WOWFI #### <- IMPORTANT change WOWFI with the name of your network interface as seen in /etc/config/networks
  sleep 120 # allows some time to the router to reset the connection 
}


while [ 1 ]; do
  pingCheck || ( echo "resetted due to ping - $(date)" >> /root/wifiRebootsCounter.log && act )
  syncCheck || ( echo "resetted due to sync - $(date)" >> /root/wifiRebootsCounter.log && act )
  [ $(du -k wifiRebootsCounter.log  | cut -f1) -ge 100 ] && $(tail -25 wifiRebootsCounter.log > wifiRebootsCounter.log)
  sleep $waitBetweenChecks
done

carefully change the network name and the configuration variables.

the script must be placed in /root/ .

I hope it helps

1 Like

Hello fellows.
I congratulate with Giulio, as he developed a tool that with proper tuning will help mitigate a lot the problems with the WOWFI interruptions.
I'm trying it extensively, and I can confirm it working with some inevitable limitations.
May you live long and happy. The world needs inventive people!

HELLO I READ YOUR POST IN 2022 AND I AM INTERESTED in the question of disconnecting from fastweb wowfi. I own a router with openwrt and I would like to understand more but at the moment I have a little solid basis that does not allow me to trivially understand how to insert the script that giulio did for us. could you help me?

Hello Nick,
I sincerely apologise for the delay, but moving to a new house in the last months made my life chaotic.
I'll be surely happy to help you, if Giulio doesn't reach you sooner.
But please allow a few days, if not weeks for me to be able to guide you.
What I can tell is the script works. Wonderfully. Particularly with more recent builds.

I'll be back soon. Promise.

i use the wowfi netwrork daily.
but lately have had issues connetcting.
manually disabling and renabling interfaces isn't helping.
sometimes reconnection can occur even after 1 or 2 days although signal strength is stable at 70-80%
anybody thinks those scripts can solve my problem.
thanks

I don't know the actual situation with Fastweb, and if the company is still offering the service as granted, but giving a go to the script is quite easy, and if it does not improve the situation you can easily remove it. I launched it on two different routers and on the second, with owrt 21, the improvement in reconnection times was massive. I then moved to optical fiber, so I'm not using WOWFI anymore...

loads of scripts on this thread.
which of 'em ? pasted on router openwrt firmware sheduled task ?

Hello @batsam, you can find the definitive version of the script just a few posts above yours. But in order to understand what you're doing I would suggest to read the whole thread, as the logic is clearly explained.

Happy thinkering!