實現 WiFi 斷線自動重連。原理是用 Python 監測網絡是否斷線,如果斷線則重啟網絡服務。
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.開機自動啟動以上腳本:在終端窗口執行以下命令即可
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實現樹莓派WiFi斷線自動重連,希望對大家有所幫助,如果大家有任何疑問請給我留言,小編會及時回復大家的。在此也非常感謝大家對服務器之家網站的支持!
原文鏈接:http://blog.csdn.net/iyjr38/article/details/62421479