Raspberry Pi WiFi issue (Solarcam)

From Wurst-Wasser.net
Jump to navigation Jump to search
The printable version is no longer supported and may have rendering errors. Please update your browser bookmarks and please use the default browser print function instead.

The Problem

My Raspberry Pi kept disconnecting from wifi:

Apr  6 02:37:13 raspberrypi kernel: [ 1877.518479] wlan0: deauthenticated from 04:4f:4c:6c:01:f9 (Reason: 3=DEAUTH_LEAVING)
Apr  6 02:37:25 raspberrypi kernel: [ 1889.560586] rtl8192cu: MAC auto ON okay!
Apr  6 02:37:25 raspberrypi kernel: [ 1889.627062] rtl8192cu: Tx queue select: 0x05
Apr  6 04:57:20 raspberrypi kernel: [10284.578042] wlan0: deauthenticated from 04:4f:4c:6c:01:f9 (Reason: 6=CLASS2_FRAME_FROM_NONAUTH_STA)

The Solution

  • deinstalled wicd
apt-get remove wicd-daemon
  • configured /etc/network/interfaces to look like this:
auto lo

iface lo inet loopback
iface eth0 inet dhcp

allow-hotplug wlan0
auto wlan0

iface wlan0 inet dhcp
 wpa-ssid "MY_SSID"
 wpa-psk "MY_PRESHAREDKEY"

Installed this script in root's crontab

# wenn wlan0 down, up it
10,25,40,55 * * * * 	/home/pi/webcam/wifiTickle.sh > /dev/null 2>&1 #> /home/pi/webcam/wifiTickle.log
#!/bin/bash
#set -x

# since the wifi sometimes just fails, check and up it (execute in root's crontab)

GBASENAME="${0}"

# Diese Variablen beziehen sich aufs Interface
IFS="`/sbin/ifconfig wlan0 | grep inet | grep 192.168`"
DOWN=$?
NOW="`date +%s`" 
THEN="`cat ~pi/webcam/.lastup`"
DOWNMAX="3600"
# Diese Variablen beziehen sich auf das OS
UPTIME="`cat /proc/uptime | cut -d. -f1`" # seconds up
UPMIN="1800" # Maschine kann maximal alle n Sekunden rebooten -> somit laufen wir nicht einen Loop

function log
{
  logger "${GBASENAME}: $1"
  echo $1
}

#
# Main
#

#log "IFs: ${IFS}"
if [ "${DOWN}" -eq 1 ]; then
  DOWNFOR="`expr ${NOW} - ${THEN}`"

  #deb
  log "wlan0 has no IP. IFs: ${IFS}"
  #log "f: `ifconfig wlan0`"
  #log "f2: `ifconfig -a`"
  #ifconfig -a > ~/webcam/wifiTickle.log2

  if [ "$DOWNFOR" -gt "${DOWNMAX}" ]; then
     log "Last time up: $THEN Now: $NOW. Down for $DOWNFOR. Up for ${UPTIME}."
     if [ "${UPTIME}" -gt "${UPMIN}" ]; then
        log "Interface is down for $DOWNFOR. Machine is up for ${UPTIME}. Rebooting. Hope the best!"
        /sbin/shutdown -r now
     fi
  else
     # das bringt aber nicht immer was.
     # Ich sehe immer wieder DEAUTH_LEAVING. Mit iwconfig wlan0 power off habe ich das Powersaving schon ausgeschaltet.
     # Sieht mehr nach einem Bug im RealTek-Treiber aus.
     # Oder verschiedene WLAN-Manager ("Network Manager" oder "wicd" kommen sich in die Quere) -> apt-get remove wicd-daemon
     # Danach ganz vanilla nur in /etc/network/interfaces (s. https://raspberrypihq.com/how-to-add-wifi-to-the-raspberry-pi/ ) konfiguriert, das scheint es gewesen zu sein
     log "ifdown..." 
     /sbin/ifdown wlan0
     log "ifup..." 
     /sbin/ifup wlan0
  fi
else
  # Merk Dir mal, wann wir (zuletzt) up sind...
  #log up!
  echo "${NOW}" > ~pi/webcam/.lastup # sec since epoch
fi