I am writing a python script where I am monitoring the network status. I have Raspberry pi
in which I am using Python 2.7
. If the network is not available, script first checks if the network credentials are still saved in file wpa_supplicant.conf
(/etc/wpa_supplicant/wpa_supplicant.conf)
. If it is not saved, then the script writes ssid and password in the file and run the below command to start the wlan0 to connect to wifi:
ret = subprocess.call(['sudo /sbin/ifup --force wlan0'], shell=True)
if ret is 0:
print("Connection successfully")
else:
print("Unable to connect")
This connects the wifi to the given ssid.
Now the problem is the above commands return 0 if it runs successfully. But lets say if the wifi network is not available at that moment it will still show 0. How can we detect the network which we are trying to connect is not available.
Thanks.