Using Python to implement auto-re-attach instances of Raspberry Pi WiFi disconnection (code attached)

Source: Internet
Author: User
Realize the WiFi disconnection automatically, the principle is to use Python to monitor whether the network is disconnected, if the disconnection will restart the network service. Next to everyone to share the implementation of code, need to refer to the friend

1.Python code autowifi.py, placed in the/HOME/PI directory:

#!/usr/bin/pythonimportos, Time whiletrue:  if ' 192 ' 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.Shell script autowifi.sh, also placed in the/HOME/PI directory:

#!/bin/shpython/home/pi/autowifi.py &

3. Boot automatically start the above script: 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

The above is a small part of the python to introduce the realization of the Raspberry Pi WiFi disconnection automatically re-connected, I hope that we have some help, if you have any questions please give me a message, small series will promptly reply to everyone. Thank you very much for the support of the Scripting House website!

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.