實(shí)現(xiàn) WiFi 斷線自動(dòng)重連。原理是用 Python 監(jiān)測(cè)網(wǎng)絡(luò)是否斷線,如果斷線則重啟網(wǎng)絡(luò)服務(wù)。
1.Python 代碼 autowifi.py,放在 /home/pi 目錄下:
1
2
3
4
5
6
7
8
9
10
11
|
#!/usr/bin/python import os, time while True : 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腳本autowifi.sh,也放在 /home/pi 目錄下:
1
2
|
#!/bin/sh python / home / pi / autowifi.py & |
3.開機(jī)自動(dòng)啟動(dòng)以上腳本:在終端窗口執(zhí)行以下命令即可
1
2
3
4
5
6
7
8
|
sudo cp - f / home / pi / autowifi.sh / etc / init.d / sudo chmod + x / etc / init.d / autowifi.sh sudo chown root:root / etc / init.d / autowifi.sh sudo update - rc.d autowifi.sh default |
以上所述是小編給大家介紹的Python實(shí)現(xiàn)樹莓派WiFi斷線自動(dòng)重連,希望對(duì)大家有所幫助,如果大家有任何疑問請(qǐng)給我留言,小編會(huì)及時(shí)回復(fù)大家的。在此也非常感謝大家對(duì)服務(wù)器之家網(wǎng)站的支持!
原文鏈接:http://blog.csdn.net/iyjr38/article/details/62421479