How to keep Yun connected to WIFI

Hi, a rather simple question. I set up my yun and my sketch, but if my internet connection drops for a bit. How do I make sure my Yun reconnects once the WIFI becomes available again.

I know that on boot if no wifi available its meant to go into ad hoc mode. thats fine. I just want to understand if there is something I can change to ensure if reestablished the wifi connection when it drops?

Stop wifi go into ad hoc mode:

Code:

nano /etc/rc.local
#wifi-live-or-reset

Schedule check internet connection and run command at no connection and restart python script automatically when internet is recover:

http://forum.arduino.cc/index.php?topic=222867.msg1621158#msg1621158

Code:

...
if [ $count -eq 0 ]; then
	# no internet do clean job, kill bridge  and your script
	/sbin/wifi
	/etc/init.d/network  restart
else
...

Thanks Sonnyyu,

Im very new to linux generally. Can I please check my understanding of the following

nano /etc/rc.local               // OK So this command edits the rc.local which appears to be a file which runs at boot time
#wifi-live-or-reset                        // This appears to be a daemon which monitors whether the wifi is up. 
                                                            // Does this same daemon constantly monitor the status of the wifi during runtime and if it
                                                           // drops reverts back to AD hoc mode. Or does it only run on boot to check for the presence of WIFI

Now comes the bit I am totally stuck on. Your code snippet:

...
if [ $count -eq 0 ]; then
	# no internet do clean job, kill bridge  and your script
	/sbin/wifi
	/etc/init.d/network  restart
else
...

Appears to come from some code on the link you kindly provided. I've tried to comment it to test my understanding but I dont understand the syntax of scripts so any correction is welcome

#!/bin/sh                                                                                                                                              // Use the sh shell
HOSTS="8.8.8.8"                                                                                                                                // Declare HOST to use googles public DNS
ping_attempts=1                                                                                                                               // Set ping attempts to 1
sleep_time=10                                                                                                                                    // Set initial time between tests to 10 seconds

while true                                                                                                                                            // While whats true? I dont understand
do                                                                                                                                                          // Start a do loop
        count=$(ping -c $ping_attempts $HOSTS | awk -F, '/received/{print $2*1}')    // Ping 8.8.8.8 once. Get the result 0 = down 
                                                                                                                                                              // 1 would = up
        #echo $count                                                                                                                          // I assume this isnt needed. Just user feedback
        if [ $count -eq 0 ]; then      # IF INTERNET DOWN                                                      // If count = 0 internet is down

                /sbin/wifi                                                                                                                         // Not sure why no switch here. Would
                                                                                                                                                            // have expected an argument
                                                                                                                                                            // i.e      /sbin/wifi down
	        /etc/init.d/network  restart                                                                                     // Restart the network
                                                                    
        else                                            # IF INTERNET UP                                                               // if count = 1 internet i up
        fi                                                                                                                                                   // End of the if
        sleep  $sleep_time                                                                                                                 // Put the calling thread to sleep for 10 seconds
done                                                                                                                                                   // End of do loop

Where does this code go, bearing in mind I have no experience of linux. It doesnt makes sense to me to put it in the rc.local as if I understand correctly that is only run at startup to start the #wifi-live-or-reset

Hope you can help with a bit more details on how to implement this in linino. Im sure newbies will ask this question again in future so it would be nice to get it pinned down.

Thanks

Chris

Does this same daemon constantly monitor the status of the wifi during runtime and if it drops reverts back to AD hoc mode.

Yes

does it only run on boot to check for the presence of WIFI

No, It constantly monitor.

It doesnt makes sense to me to put it in the rc.local as if I understand correctly that is only run at startup to start the #wifi-live-or-reset

Yes.

The Wifi Signal level could cause internet drop off, confirm wifi Signal level:

http://forum.arduino.cc/index.php?topic=188101.msg1583665#msg1583665

The Wifi has build in re-connection function, the code is really for back plan.

You said

The Wifi has build in re-connection function, the code is really for back plan.

Im sure I read somewhere that it would try for maybe 15 minutes then drop back to adhoc mode. In this case if the outage is > 15 minutes and it drops to ad hoc mode its not going to recover into normal wifi when the internet resumes

Can you please clarify where my above code should go. should it go in rc.local?

Any chance you could show me what the full rc.local would look like?

nano /usr/bin/internet-reconnect
chmod 755 /usr/bin/internet-reconnect
nano /etc/rc.local
#wifi-live-or-reset
/usr/bin/internet-reconnect &
exit 0

Please post output of:

/usr/bin/pretty-wifi-info.lua

UliZappe on github raised this issue once more. WiFi connection always breaks down after a few hours · Issue #15 · arduino/openwrt-yun · GitHub

I'm wondering if we could manage to finalize this script and make it a built-in wifi availability check (Jantje: I still haven't tried to keep a growing distance between my yun and the hotspot, sorry)

I've done some tests in order to see if the yun automatically reconnect to the network and It does. I configured my Yun to connect to an access point, and if I turn off the AP and then turn on again, the Yun recover the connection. I waited 5 minutes and 2 hours before turning on the AP and I tried with WPA2 and with no encryption. I have the latest version of the firmware on my Yun.

I did have many cases where the Yun never reconnect. To solve this I made a script that runs in the backgound that checks the Wifi link, and if broken will explicitly reconnect. See WLAN issues - Arduino Yún - Arduino Forum

Sonnyyu - we're so lucky to have you!