Difference between revisions of "BBB WiFi"

From Klaus' wiki
Jump to: navigation, search
Line 133: Line 133:
 
In cron add this line
 
In cron add this line
 
  #m h dom mon dow user  command
 
  #m h dom mon dow user  command
  /5  *    * * *  root  /opt/wifi-reset/wifi-reset.sh
+
  */5  *    * * *  root  /opt/wifi-reset/wifi-reset.sh
 
which will cause cron to execute the script every five minutes. It can probably run more often if needed but this works for me and i OK.
 
which will cause cron to execute the script every five minutes. It can probably run more often if needed but this works for me and i OK.

Revision as of 08:45, 2 May 2015

If you are going to add a WiFi adapter you should search eBay, Alibaba or your local HW pusher for a Realtek RTL8188CUS or similar adapter. They will usually work right out of the box without any external power.

Plug in the adapter into the USB interface.

Issue

]$ lsusb

expect a result like this

root@beaglebone:~# lsusb
Bus 001 Device 002: ID 0bda:8176 Realtek Semiconductor Corp. RTL8188CUS 802.11n WLAN Adapter
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 002 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub

Next issue

root@beaglebone:~# ifconfig -a

expect something like this output

eth0      Link encap:Ethernet  HWaddr 1c:ba:8c:e7:40:03  
          UP BROADCAST MULTICAST  MTU:1500  Metric:1
          RX packets:0 errors:0 dropped:0 overruns:0 frame:0
          TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:0 (0.0 B)  TX bytes:0 (0.0 B)
          Interrupt:40 

lo        Link encap:Local Loopback  
          inet addr:127.0.0.1  Mask:255.0.0.0
          inet6 addr: ::1/128 Scope:Host
          UP LOOPBACK RUNNING  MTU:65536  Metric:1
          RX packets:0 errors:0 dropped:0 overruns:0 frame:0
          TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0 
          RX bytes:0 (0.0 B)  TX bytes:0 (0.0 B)

usb0      Link encap:Ethernet  HWaddr f6:7f:36:73:b5:93  
          inet addr:192.168.7.2  Bcast:192.168.7.3  Mask:255.255.255.252
          inet6 addr: fe80::f47f:36ff:fe73:b593/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:774 errors:0 dropped:0 overruns:0 frame:0
          TX packets:540 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:62696 (61.2 KiB)  TX bytes:94951 (92.7 KiB)

wlan0     Link encap:Ethernet  HWaddr 00:13:ef:20:06:33  
          UP BROADCAST MULTICAST  MTU:1500  Metric:1
          RX packets:0 errors:0 dropped:5 overruns:0 frame:0
          TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:0 (0.0 B)  TX bytes:0 (0.0 B)

From this we can see that the WiFi adapter was recognised by the Linux OS and given the device name wlan0.

In order to have the wiFi to auto connect at boot time issue

root@beaglebone:~# vi /etc/network/interfaces

In this file uncomment the lines following the #WiFi example

auto wlan0
iface wlan0 inet dhcp
   wpa-ssid "YourSSID"
   wpa-psk  "YourVerySecretPassword"

save the file and execute this command

]$ ifconfig wlan0 up

This will start the wlano, but nothing is output for your information.

Issue

]$ ifup wlan0

This will give you an output like the one shown below

ioctl[SIOCSIWAP]: Operation not permitted
ioctl[SIOCSIWENCODEEXT]: Invalid argument
ioctl[SIOCSIWENCODEEXT]: Invalid argument
Internet Systems Consortium DHCP Client 4.2.2
Copyright 2004-2011 Internet Systems Consortium.
All rights reserved.
For info, please visit https://www.isc.org/software/dhcp/

Listening on LPF/wlan0/00:NN:NN:NN:NN:NN
Sending on   LPF/wlan0/00:NN:NN:NN:NN:NN
Sending on   Socket/fallback
DHCPDISCOVER on wlan0 to 255.255.255.255 port 67 interval 7
DHCPDISCOVER on wlan0 to 255.255.255.255 port 67 interval 12
DHCPREQUEST on wlan0 to 255.255.255.255 port 67
DHCPOFFER from 192.168.10.1
DHCPACK from 192.168.10.1
bound to 192.168.10.110 -- renewal in 35998 seconds.

You have got a new IP address for the WiFi interface. Note it, most accesspoints re-issue the same IP address if the device reconnects frequently - otherwise it may be an idea to consult the accesspoint to see if it is possible to configure that a specific MAC addresse is connected to a specific IP addresse often it is possible.

Now in order to check if the WiFi comes up automagically after a reboot perform a reboot of the system.

Sometime my BBB does not get an IP address. After digging into the log files I found that the driver does not always get the device ready for DHCP'ing in time.

I stumbled upon this on AdaFruit.

]$ apt-get update && apt-get install git
]$ git clone https://github.com/adafruit/wifi-reset.git
]$ cd wifi-reset
]$ chmod +x install.sh
]$ ./install.sh

after installing this the BBB always come up on WiFi - but sometimes it takes minutes to get everything registered and running.

Sometimes this is enough, so I improved the wifi-reset.sh script and run it every five minutes from cron. So now the waiting time is no more than five minutes.

The improved script look like this

#!/bin/bash
# Bring all wifi interfaces down.
# Identify wifi interfaces as rows from standard output of iwconfig (NOT standard
# error, those are non-wifi interfaces) which start without whitespace.
ASSOC=`iwconfig wlan0|grep -o "Not-Associated"`
while [ ! -z ${ASSOC} ]; do
        echo "Running wlan setup"
        iwconfig 2> /dev/null | grep -o '^[[:alnum:]]\+' | while read x; do ifdown $x; done
        # Bring all wifi interfaces up.
        iwconfig 2> /dev/null | grep -o '^[[:alnum:]]\+' | while read x; do ifup $x; done
        sleep 30
        ASSOC=`iwconfig wlan0|grep -o "Not-Associated"`
done

the script looks for the phrase "Not-Associated" in the output from iwconfig. If there is no association with an accesspoint we will reset all the wlans and after that enable them once again. The script will loop every thirty seconds until we get an association with an accesspoint.

In cron add this line

#m h dom mon dow user  command
*/5  *    * * *   root   /opt/wifi-reset/wifi-reset.sh

which will cause cron to execute the script every five minutes. It can probably run more often if needed but this works for me and i OK.