0

I've recently moved my headless PI to a hard to get at location, and now am having problems with my WIFI connection dropping out.

I'd previously installed a script to reconnect the WIFI if it didn't see an IP address present, and all was dandy; but since moving it's resulted patchy reception.

1) Does this script actually work if iv'e hard coded the IP address to be static, not to use DCHP?

2) It only reconnects if I pull the power and reboot, why could this be?

network interfaces file:

allow-hotplug wlan0
auto wlan0
iface wlan0 inet manual

wpa-roam /etc/wpa_supplicant/wpa_supplicant.conf

iface default inet static

address 192.168.1.41
gateway 192.168.1.1
netmask 255.255.255.0

wifi_test_1.sh script :

#!/bin/bash

################################################
# Which Interface do you want to check/fix
wlan='wlan0'


# call using crontab -e 
# */5 * * * * /usr/src/scripts/wifi_test_1.sh


################################################

# perform check

#echo "----------------------------------"
#echo "Performing Network check for $wlan"
#echo "----------------------------------"
#echo

if ifconfig $wlan | grep -q "inet addr:" ; then
#   echo
    echo "==============="
    echo "Network is Okay"
    echo "==============="
#   echo

else
#   echo
    echo "================================================="
    echo "Network connection down! Attempting reconnection."
    echo "================================================="
#   echo

    ifdown $wlan
    sleep 10
    ifup --force $wlan
    ifconfig $wlan | grep "inet addr"
fi

#echo "----------------------------------"
#echo "Current Setting:"
#echo
#ifconfig $wlan | grep "inet addr:"
#echo "----------------------------------"
#echo
exit 0

I have a good power supply that worked flawlessly before the move.

  • 1
    This script won't work with a fixed IP. If you want, I can provide you with the script I use, to add a secondary fixed IP to the Pi, without disabling DHCP. – Gerben Jun 28 '14 at 9:42
  • 1) I suspected that the script wouldn't work with a static IP, but thanks for confirming it Gerben. I don't understand how you can have a static address and DCHP at the same time. Maybe I should try a script that pings an external site to see if there's an internet connection? – reggie Jun 28 '14 at 20:24
  • 2) I think Iv'e made progress today. I disabled dongle power saving mode by placing wireless-power off in my network interfaces file. This has seamed to make the connection reliable, but I'm not counting my chickens yet! I don't understand when the power saving mode is applied, but I bet it's not just after a reboot; and hence this may be why I, historically, generally only get reliable connection following a reboot. Does this make sense? – reggie Jun 28 '14 at 20:25
  • Kind of makes sense. PS I created a second IP by creating a virtual network interface. Seems complicated by is pretty easy, and works just fine. PPS try pinging you router's IP. Something like ping -c1 -t1 192.168.1.1, if [ "$?" -ne 0 ]; then – Gerben Jun 29 '14 at 9:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.