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?
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.
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?
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