[19. June 2013] Soundcloud® available now | [7. June 2013] Youporn available now | [11 Jan. 2013] Customize your A-400 Home Screen

Firmware: A-400 [13 May 2013] | C-300 [30 Nov. 2012] | A-300 [30 Nov. 2012] | C-200 RC1 [13 June 2013] | A-200/A-210 RC1 [13 June 2013]

Just got your NMT | WIKI has the answers | Search the forum | Forum Rules/Policy | Firmware & Official NMT News | Popcornhour manuals



User(s) browsing this thread: 1 Guest(s)
Thread Closed 
[Script] Automatic wifi connection drop detection and reconnect
06-28-2010, 11:32 PM (This post was last modified: 06-28-2010 11:36 PM by mgtroyas.)
Post: #1
Lightning [Script] Automatic wifi connection drop detection and reconnect
Hello,

First of all, I must say I absolutely love my PCH A-110, and the ability to directly download FullHD media to the HDD via torrent and wifi, for local storage and playback.

But it also has some problems. One of them, perhaps not really fault of the NMT, is random wifi connection drop. Sometimes it stays connected for days, and others fail each half an hour. In order to fix it, I need to enter the NMT's network configuration, and re-apply the wifi settings. So it connects to the wifi network again. But for all the time it has been disconnected, it hasn't been downloading anything.

So I developed a little script which pings to my router 4 times and, if any of the ICMP packets gets lost, kills and restarts the WPA supplicant proccess, reconnecting to the wifi network. It also mantains a log of reconnections on a text file:

Code:
suc=$(ping -c 4 -q 192.168.100.254 | awk '{if($1==4){print $4}}')
if [ "$suc" != 4 ]; then
        echo $(date) >> /share/restart.txt
        kill $(ps cu | grep wpa_supplicant | awk '{print $1;}')
        /opt/wifi/bin/wpa_supplicant -B -Dotus -iwlan0 -c/opt/wifi/config/wpa_supplicant.conf
        route add default gw 192.168.100.254
fi

Replace 192.168.100.254 with your router's IP. Also, make sure it answers to ping.

Save the code on a text file on the hard disk, i.e. as "/share/cron.txt".

Now we need this script to be executed periodically. Perhaps each hour. That's what cron is designed for. So we could append the script to the hourly cron file. It's simple:

Code:
cat /share/cron.txt >> /etc/cron.hourly

But the problem is, as soon as we reboot the NMT, the crontab will be reset to default, losing our change. No problem: in order to apply it in each boot, we must simply append the line to the end of the "/share/start_app.sh" script, which gets executed exactly on every boot.

Code:
[...]
#M_A_R_K_E_R_do_not_remove_me
cat /share/cron.txt >> /etc/cron.hourly

So in every boot, the crontab will be modified, then the script will be executed hourly, and our wifi connection will be magically resumed whenever it has failed, with less of an hour of downtime. Also we will get a fancy log file with all the days and hours the router (Linksys WRT-120N in my case) has been so unkind to drop our beloved PCH.

I've used this method for months and has server me very well. I hope it's also useful for many others!
Find all posts by this user
[+] 2 users say Thank You to mgtroyas for this post
Thread Closed 


Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  [HOWTO] Ralink RT2870 wifi chipset artbern 8 11,602 02-04-2012 09:13 PM
Last Post: anilech
  [myiHome] linux package and daemon script Shaika-Dzari 8 6,526 01-12-2010 03:46 AM
Last Post: JonnyRocket
Thumbsup [HOWTO] Ralink RT73 wifi chipsets tiagor 13 14,124 10-14-2009 11:34 AM
Last Post: frendeze
  HOWTO: Use secure password for your WiFi ssuukk 2 2,867 08-13-2009 06:03 AM
Last Post: ssuukk
  A script to re-mux all the files in a folder npc100 0 2,725 07-19-2009 08:23 PM
Last Post: npc100
  MKV transcoding script for Linux/*BSD/Mac users onitake 4 6,599 12-01-2008 01:35 PM
Last Post: onitake

Forum Jump: