Named autowifi.py and then put it to /home/pi folder
#!/usr/bin/python
import os, time
while True:
if '192' not in os.popen('sudo wpa_cli status').read():
print '\n****** wifi is down, restart... ******\n'
os.system('sudo ifup wlan0')
time.sleep(300) #5 minutes
Named autowifi.sh and then put it to /home/pi folder
#!/bin/sh
python /home/pi/autowifi.py &
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 defaults
