Montag, 22. Juni 2015, 17:48 Uhr

Raspberry Pi 2 einrichten (2/n): WLAN USB-Stick konfigurieren

Für meinen zweiten Raspberry habe ich in meinem Elektronik-Lager einen unbenutzten WLAN USB-Stick Linksys WUSB54GC v3 gefunden. Mit der Standard-Stromversorgung (1.2A) funktioniert dieser Stick problemlos (keine andere Peripherie an den USB-Anschlüssen) und Raspbian erkennt den WLAN-Stick automatisch.

Als erstes gilt es, den Raspberry Pi 2 zu booten. Angeschlossen an einen HDMI-Monitor und mit einem USB-Keyboard geht man danach an die Konfiguration des WLAN-Adapters, damit man die restliche Konfiguration per SSH vornehmen kann.

Nachdem man nach dem ersten booten in raspi-config landet, vergrössert man zuerst die Partition und startet den Taschencomputer neu. Beim nächsten Neustart loggt man sich mit dem Standardbenutzer pi und dem Passwort raspberry in die Shell ein. Dort startet man raspi-config erneut, und wechselt das Keyboard-Layout im Menupunkt „INTERNATIONALISATION OPTIONS“ auf „Deutsch (Schweiz)“. Anschliessend wechselt man das Passwort des Standardbenutzers. Sicher ist sicher.

Da in der Standardinstallation vim noch nicht vorhanden ist, nehmen wir nano und bearbeiten folgende Datei:

/etc/network/interfaces

auto lo
iface lo inet loopback

auto eth0
allow-hotplug eth0
iface eth0 inet manual

auto wlan0
allow-hotplug wlan0
iface wlan0 inet dhcp
   wpa-ssid EMEIDI-LEGACY
   wpa-psk ********

iface default inet dhcp

Um die Verbindung herzustellen, habe ich den WLAN-Stick kurzerhand aus- und wieder eingestöpselt. Nach gefühlten 10 Sekunden führte der Befehl ifconfig für das Interface wlan0 dann eine gültige IP-Adresse auf (sofern der in dieser Konfiguration zwingend benötigte DHCP-Server im Netzwerk sauber funktioniert).

Nachdem man sich die IP unter dem Interface wlan0 notiert hat, geht es an den Mac mini, von welchem aus man mittels SSH die restliche Konfiguration des Systems vornimmt.

WLAN nach Komplikationen automatisch neu starten

Falls man mit gelegentlichen Verbindungsproblemen kämpft, welche einen automatischen Neustart des WLAN-Interfaces nötig machen, sollte man einen entsprechenden Cron-Job einrichten:

/etc/crontab

...
* * * * *	root	/usr/local/bin/check-wifi.sh > /dev/null 2>&1
...

Das Script liest sich folgendermassen:

#!/bin/bash
##################################################################
# A Project of TNET Services, Inc
#
# 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
#
# Instructions:
#
# o Install where you want to run it from like /usr/local/bin
# o chmod 0755 /usr/local/bin/WiFi_Check
# o Add to crontab
#
# Run Every 5 mins - Seems like ever min is over kill unless
# this is a very common problem.  If once a min change */5 to *
# once every 2 mins */5 to */2 ... 
#
# */5 * * * * /usr/local/bin/WiFi_Check 
#
##################################################################
# 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'
##################################################################
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"
if ifconfig $wlan | grep -q "inet addr:" ; then
    echo "Network is Okay"
else
    echo "Network connection down! Attempting reconnection."
    ifdown $wlan
    sleep 5
    ifup --force $wlan
    ifconfig $wlan | grep "inet addr"
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

##################################################################
# End of Script
##################################################################

Quelle: dweeber/WiFi_Check

Tags: , , ,
Labels: IT, Linux

Kommentar erfassen