Last active
August 9, 2019 08:44
-
-
Save Darkbat91/5fbcbacb60f1ba33acc5601726937ca3 to your computer and use it in GitHub Desktop.
Fixes wifi Issues with the OpenWRT Routers with both client mode and AP Mode being active at the same time
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
# Make the python file | |
mkdir -p /usr/share/wififix/ | |
cat >/usr/share/wififix/fix.py <<EOL | |
import subprocess | |
def updatewireless(): | |
edit = False | |
needdisable = True | |
# Open our temp wireless config with Write | |
tmp = open('/etc/config/wireless.tmp', "w") | |
# Open the file with read only permit | |
with open("/etc/config/wireless", "r") as f: | |
# use readline() to read the first line | |
line = f.readline() | |
while line: | |
# Find the character count of the space | |
count = line.find(' ') | |
# If the space is after the first character we have a heading | |
if count == 6: | |
# We found the next header | |
# Header of the config option | |
if 'radio' not in line: | |
# This is what we care about means we are on a client interface | |
edit = True | |
else: | |
# Radio interface lets not disable that | |
edit = False | |
# reset the need disable flag | |
needdisable = True | |
elif edit and needdisable and count == -1: | |
# We need to add the disable line since it doesnt already exist count being -1 | |
# means we are at the end of a configuration block | |
# needdisable being true means we have not found that line in this block | |
tmp.write("\toption disabled '1'\n") | |
else: | |
# We are on a config line | |
if 'option disabled' in line and edit: | |
needdisable = False | |
# If the line containes a disabled option make sure we flip it to true | |
line = line.replace('0','1') | |
# write the line to the file | |
tmp.write(line) | |
# use realine() to read next line | |
line = f.readline() | |
# we are done gracefully close the file | |
tmp.close() | |
subprocess.call(["mv", "/etc/config/wireless.tmp", "/etc/config/wireless"]) | |
ipcommand = subprocess.check_output(["ip", "a"]) | |
if 'NO-CARRIER' in ipcommand: | |
print "Fixing wireless" | |
updatewireless() | |
subprocess.call("/etc/init.d/network restart", shell=True) | |
else: | |
print "All good" | |
EOL | |
# Inject the fix python to the init but after system has finalized | |
if grep -q "wififix" /etc/rc.local; | |
then | |
echo "Nothing to do WifiFix Already installed" | |
else | |
echo "writing Installing Wifi fix" | |
sed -i '/exit 0/i python /usr/share/wififix/fix.py' /etc/rc.local | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Problem
OpenWrt wireless connections will not open the access point network if the client network is defined but the client network is unable to connect.
The below process indicates a solution to this problem.
Good wireless
Bad wireless
Config Example
fix
Flip all non connecting clients to disabled
service network restart
python Code
Make run on system after initialization
save somewere and add below line in /etc/rc.local
python /path/to/wififix