Hi.
I am trying to set priority for my WIFI network in the DB410C, but if DB410C is unable to find the configured one, it doesn’t go to the default ESSID and PWD as mentioned in the python script.
Script below-
import os, sys, configparser, logging, time, datetime, glob, socket
sys.path.append(’/usr/local/lib/python3.5/dist-packages’)
from pytz import timezone
from subprocess import Popen, PIPE
from shlex import split
Read in configuration
devnull = open(os.devnull,‘w’)
config = configparser.ConfigParser()
config.read(‘app.config’)
mac_sid = config.get(‘WIFI’,‘SSID’)
mac_pass = config.get(‘WIFI’,‘PASSWORD’)
mac_sid_default = config.get(‘WIFI’,‘DEFAULTSSID’)
mac_pass_default = config.get(‘WIFI’,‘DEFAULTPASSWORD’)
def internet_on():
try:
socket.create_connection((“aws.amazon.com”, 80))
return True
except:
return False
p1 = Popen(split(“echo $mypass”), stdout=PIPE)
p2 = Popen(split(‘sudo -S wpa_passphrase "’+mac_sid+’" “’+mac_pass+’”’), stdin=p1.stdout, stdout = PIPE)
(process_output_1, error) = p2.communicate()
file = open(".secret_folder/wpa.conf", “w”)
file.write(process_output_1.decode(‘ascii’))
file.close()
p3 = Popen(split(“echo $mypass”), stdout=PIPE)
p4 = Popen(split(‘sudo -S wpa_passphrase "’+mac_sid_default+’" “’+mac_pass_default+’”’), stdin=p3.stdout, stdout = PIPE)
file = open(".secret_folder/wpa_default.conf", “w”)
(process_output_2, error) = p4.communicate()
file.write(process_output_2.decode(‘ascii’))
file.close()
time.sleep(5)
p5 = Popen(split(“echo $mypass”), stdout=PIPE)
p6 = Popen(split(“sudo -S ifdown wlan0”), stdin=p5.stdout)
time.sleep(5)
p7 = Popen(split(“echo $mypass”), stdout=PIPE)
p8 = Popen(split(“sudo -S ifup wlan0”), stdin=p7.stdout)
p9 = Popen(split(“echo $mypass”), stdout=PIPE)
p10= Popen(split("sudo -S iwconfig wlan0 essid "+mac_sid), stdin=p9.stdout)
time.sleep(10)
p11 = Popen(split(“echo $mypass”), stdout=PIPE)
p12 = Popen(split(“sudo -S wpa_supplicant -B Wn180211 -i wlan0 -c .secret_folder/wpa.conf”), stdin=p11.stdout)
time.sleep(20)
p13 = Popen(split(“echo $mypass”), stdout=PIPE)
p14 = Popen(split(“sudo -S dhclient wlan0”), stdin=p13.stdout)
time.sleep(120)
if internet_on():
print(“Connected to configured Network”)
else:
print(“Connecting to default Network”)
time.sleep(10)
p15 = Popen(split(“echo $mypass”), stdout=PIPE)
p16 = Popen(split(“sudo -S ifdown wlan0”), stdin=p15.stdout)
time.sleep(10)
p17 = Popen(split(“echo $mypass”), stdout=PIPE)
p18 = Popen(split(“sudo -S ifconfig wlan0 up”), stdin=p17.stdout)
time.sleep(300)
p17 = Popen(split(“echo $mypass”), stdout=PIPE)
p18 = Popen(split(“sudo -S iwlist wlan0 scan”), stdin=p17.stdout)
p19 = Popen(split(“echo $mypass”), stdout=PIPE)
p20 = Popen(split("sudo -S iwconfig wlan0 essid "+mac_sid_default), stdin=p19.stdout)
time.sleep(10)
p21 = Popen(split(“echo $mypass”), stdout=PIPE)
p22 = Popen(split(“sudo -S wpa_supplicant -B Wn180211 -i wlan0 -c .secret_folder/wpa_default.conf”), stdin=p21.stdout)
time.sleep(20)
p23 = Popen(split(“echo $mypass”), stdout=PIPE)
p24 = Popen(split(“sudo -S dhclient wlan0”), stdin=p23.stdout)
time.sleep(120)
devnull.close()
The objective is make the DB410C connect to a configured WIFI and check if it can reach AWS. If not, then look for default WIFI ESSID, so if it doesn’t find the configured one it doesn’t connect to the default. Please guide where are we not doing it right, or what is a better way to do it.
Regards
Rajat