Python implements the example code of Raspberry Pi WiFi disconnection automatic reconnection, pythonwifi

Source: Internet
Author: User

Python implements the example code of Raspberry Pi WiFi disconnection automatic reconnection, pythonwifi

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.

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

The above is a small series of Python Implementation of Raspberry Pi WiFi disconnection automatic reconnection, I hope to help you, if you have any questions, please leave a message, the editor will reply to you in a timely manner. Thank you very much for your support for the help House website!

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.