I tried writing a script in python (python3, but works in 2 as well) that you can use for that. I've tried it until the connecting and disconnecting part, so that you can use the method that you prefer:
with open("/proc/net/wireless", "r") as f:
data = f.read()
link = int(data[177:179])
level = int(data[182:185])
noise = int(data[187:192])
# print("{}{}{}".format(link, level, noise))
lmtqlty = -80
if(link < lmtqlty):
os.system(nmcli c down id NAME`) # Will disconnect the network NAME
else:
os.system(nmcli c down id NAME`) # Will connect the network NAME
You have to run it as sudo, but it's no problem since you will now put it into a cron service. I have not used cron services yet, but if you can't manage yourself I will give it a try.
EDIT explanation: When you read the contents of "/proc/net/wireless", you get the following long string:
Inter-| sta-| Quality | Discarded packets | Missed | WE
face | tus | link level noise | nwid crypt frag retry misc | beacon | 22
wlan0: 0000 31. -79. -256 0 0 0 7 0 0
So you want to extract the correct values from the Quality column. This file gives you information about the connection between this system and the network. Here you have more information about it, and to explain what each Quality subcolumn means let me quote this other post:
Decibel is a logarithmic unit (1 dB = 1/10 Bel, 1 Bel = power ratio 1.259 = amplitude ratio 1.122) that describes a relative relationship between signals. See wikipedia for details and a table. Negative decibels mean the received signal is weaker then the sent signals (which of course happens naturally).
Level means how strong the signal is when received compared to how strong it was / it was assumed to be when sent. This is a physical measurement, and in principle the same for every Wifi hardware. However, often it's not properly calibrated etc.
Link is a computed measurement for how good the signal is (i.e. how easy it is for the hardware/software to recover data from it). That's influenced by echoes, multipath propagation, the kind of encoding used, etc.; and everyone uses their own method to compute it. Often (but not always) it is computed to some value that's on the same scale as the "level" value.
From experience, for most hardware I've seen, something around -50
means the signal is ok-ish, something around -80
means it's pretty weak, but just workable. If it goes much lower, the connection becomes unreliable.
These values should be read just as a rough indication, and not as something scientific you can depend on, and you shouldn't expect them to be similar or even comparable on different hardware, not even "level". The best way to learn to interpret it is to take your hardware, carry it around a bit, watch how the signal changes and what the effects on speed, error rate etc. are.
So I think you are interested in link (just changed it up there).
Just to give you more ideas I searched, you have this one-line-script that shows you dynamically the link value:
watch -n 1 "awk 'NR==3 {print \"WiFi Signal Strength = \" \$3 \"00 %\"}''' /proc/net/wireless"
You could integrate it in a bash script rather than python :)