Enable automatic reconnection of Wi-Fi disconnection. The principle is to use Python to monitor whether the network is disconnected. if the network is disconnected, restart the network service. Next, I will share with you the implementation code. if you need a friend, refer to the implementation of automatic reconnection of Wi-Fi disconnection. The principle is to use Python to monitor whether the network is disconnected. if the network is disconnected, restart the network service. Next I will share with you the implementation code. For more information, see
1. put the Python code autowifi. py in the/home/pi Directory:
#! /Usr/bin/pythonimportos, time whileTrue: if '20140901' not in OS. popen ('ifconfig | grep 192 '). read (): print '\ n ***** wifi is down, restart... * ***** \ n' OS. system ('sudo/etc/init. d/networking restart') time. sleep (5*60) #5 minutes
2. the Shell script autowifi. sh is also stored in the/home/pi Directory:
#! /Bin/shpython/home/pi/autowifi. py &
3. start the above script automatically at startup: execute the following command in the terminal window.
Sudocp-f/home/pi/autowifi. sh/etc/init. d/sudochmod + x/etc/init. d/autowifi. shsudochown root: root/etc/init. d/autowifi. shsudoupdate-rc.d autowifi. sh default