Hi,
meine Fritzbox macht Nachts Sendepause, mein Raspi mit Edimax Wlan USB Stick verliert dabei die WLAN Verbindung (was ja logisch ist), connectet aber morgens um 6 nicht mehr automatisch.
Nun habe ich einige Scripte im Netz gefunden, die per cron aufgerufen werden, um das wlan morgens wieder zu verbinden.
Die Schose schaut so aus:
#!/bin/bash
##################################################################
# Modified by Robert Cudmore (20131212, 20131220)
# (1) Added ping instead of
# if ifconfig $wlan | grep -q "inet addr:" ; then
# echo "Network is Okay"
# (2) Added a log of date/time we had a dropped connection /home/pi/wifi.ok
# (3) Added email alert when we come back up (startup_mailer.py)
#
# Title: WiFi_Check
# Author: Kevin Reed (Dweeber)
# dweeber.dweebs@gmail.com
# Project: Raspberry Pi Stuff
#
# Copyright: Copyright (c) 2012 Kevin Reed
# https://github.com/dweeber/WiFi_Check
#
# Purpose:
#
# Script checks to see if WiFi has a network IP and if not
# restart WiFi
#
# Uses a lock file which prevents the script from running more
# than one at a time. If lockfile is old, it removes it
#
##################################################################
#
##################################################################
# Settings
# Where and what you want to call the Lockfile
lockfile='/var/run/WiFi_Check.pid'
# Which Interface do you want to check/fix
wlan='wlan0'
pingip='google.com'
##################################################################
echo
echo "Starting WiFi check for $wlan"
date
echo
# Check to see if there is a lock file
if [ -e $lockfile ]; then
# A lockfile exists... Lets check to see if it is still valid
pid=`cat $lockfile`
if kill -0 &>1 > /dev/null $pid; then
# Still Valid... lets let it be...
#echo "Process still running, Lockfile valid"
exit 1
else
# Old Lockfile, Remove it
#echo "Old lockfile, Removing Lockfile"
rm $lockfile
fi
fi
# If we get here, set a lock file using our current PID#
#echo "Setting Lockfile"
echo $$ > $lockfile
# We can perform check
echo "Performing Network check for $wlan"
/bin/ping -c 1 -I $wlan $pingip > /dev/null 2> /dev/null
if [ $? -ge 1 ] ; then
echo "Network connection down! Attempting reconnection."
echo "`date` Network Down ..........." >> /home/pi/wifi.ok
ifdown $wlan
sleep 5
ifup --force $wlan
else
echo "Network is Okay"
#echo "`date` is Okay" >> /home/pi/wifi.ok
fi
echo
echo "Current Setting:"
ifconfig $wlan | grep "inet addr:"
echo
# Check is complete, Remove Lock file and exit
#echo "process is complete, removing lockfile"
rm $lockfile
exit 0
Alles anzeigen
wenn ich das wlan mit
deaktiviere, dann ich es durch das Aufrufen des Scripts wieder aktivieren.
Nach der Nachtschaltung funktioniert das aber nur bedingt.
wenn der Ping auf google.com nicht funktioniert, dann schreibe ich das in ein Logfile
Für den Fall: WLAN war aus, WLAN kommt wieder, Script wird ausgeführt, wird Network Down ........... geschrieben, WLAN 0 bekommt wieder IP Adresse, ifup --force $wlan wird ausgeführt. Rufe ich das Script auf
./check_wlan.sh
Starting WiFi check for wlan0
Tue Jun 10 14:32:04 CEST 2014
Performing Network check for wlan0
Network connection down! Attempting reconnection.
ifdown: interface wlan0 not configured
ioctl[SIOCSIWAP]: Operation not permitted
ioctl[SIOCSIWENCODEEXT]: Invalid argument
ioctl[SIOCSIWENCODEEXT]: Invalid argument
RTNETLINK answers: File exists
Failed to bring up wlan0.
Current Setting:
inet addr:192.168.155.22 Bcast:192.168.155.255 Mask:255.255.255.0
Alles anzeigen
wird also erkannt, das wlan down sein soll. Rufe ich es erneut auf, erscheint das gleiche (WLAN down, weil ping auf google.com nicht funzt)
[ifconfig]
wlan0 Link encap:Ethernet HWaddr 80:1f:02:e2:8a:13
inet addr:192.168.155.22 Bcast:192.168.155.255 Mask:255.255.255.0
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:16803 errors:0 dropped:4567 overruns:0 frame:0
TX packets:121 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:8050425 (7.6 MiB) TX bytes:4070963 (3.8 MiB)
schaut gut aus
ping klappt zwar innerhalb meines Netzwerks, aber nach außen eben nicht.
ping -I wlan0 192.168.0.1 > OK
ping -I wlan0 wlan0 193.99.144.80 > NOK
Bedeutet für mich, es gibt ein Problem mit dem Gateway.
Ich könnte jetzt jeden Morgen den Raspi per Cron rebooten, wäre jetzt aber irgendwie nicht wirklich die Lösung des Problems.