Raspberry Pi ad-hoc networking

Andy picture Andy · Mar 15, 2013 · Viewed 23.7k times · Source

I want to try some networking projects with Raspberry Pis, and I need to just send packets between a pair of pis. I would be happy as a first step just being able to ping between to Raspberry Pis in ad-hoc mode. I have not successfully done this despite looking at several tutorials and examples online.

I have 2x Raspberry Pis with the Debian Wheezy OS installed. I am using the following USB adapter which I installed firmware for on both pis and tested that they work by connected them in managed mode to a router: Bus 001 Device 004: ID 050d:945a Belkin Components F7D1101 v1 Basic Wireless Adapter [Realtek RTL8188SU]

Here are is some printouts about the networking information:

/etc/network/interfaces at each pi:


pi1@raspberrypi ~ $ cat /etc/network/interfaces 
auto lo
iface lo inet loopback
iface eth0 inet dhcp
auto wlan0
iface wlan0 inet manual
    address 192.168.2.1
    netmask 255.255.255.0
    wireless-channel 4
    wireless-essid pi-ad-hoc
    wireless-mode ad-hoc
pi2@raspberrypi ~ $ cat /etc/network/interfaces 
auto lo
iface lo inet loopback
iface eth0 inet dhcp
auto wlan0
iface wlan0 inet manual
    address 192.168.2.2
    netmask 255.255.255.0
    wireless-channel 4
    wireless-essid pi-ad-hoc
    wireless-mode ad-hoc

ifconfig at each pi:


pi1@raspberrypi ~ $ ifconfig wlan0
wlan0     Link encap:Ethernet  HWaddr ec:1a:59:46:8e:5a  
          inet addr:192.168.2.1  Bcast:192.168.2.255  Mask:255.255.255.0
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:0 errors:0 dropped:26 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)
pi2@raspberrypi ~ $ ifconfig wlan0
wlan0     Link encap:Ethernet  HWaddr ec:1a:59:46:59:0a  
          inet addr:192.168.2.2  Bcast:192.168.2.255  Mask:255.255.255.0
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:0 errors:0 dropped:6 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)

iwconfig at each pi:


pi1@raspberrypi ~ $ iwconfig wlan0
wlan0     IEEE 802.11bg  ESSID:"pi-ad-hoc"  Nickname:"rtl_wifi"
          Mode:Ad-Hoc  Cell: 02:11:87:FA:4A:02   Bit Rate:54 Mb/s
Sensitivity:0/0
Retry:off RTS thr:off Fragment thr:off Power Management:off Link Quality:0 Signal level:0 Noise level:0 Rx invalid nwid:0 Rx invalid crypt:0 Rx invalid frag:0 Tx excessive retries:0 Invalid misc:0 Missed beacon:0 pi2@raspberrypi ~ $ iwconfig wlan0 wlan0 IEEE 802.11bg ESSID:"pi-ad-hoc" Nickname:"rtl_wifi" Mode:Ad-Hoc Cell: 02:11:87:C4:F2:01 Bit Rate:54 Mb/s
Sensitivity:0/0
Retry:off RTS thr:off Fragment thr:off Power Management:off Link Quality:0 Signal level:0 Noise level:0 Rx invalid nwid:0 Rx invalid crypt:0 Rx invalid frag:0 Tx excessive retries:0 Invalid misc:0 Missed beacon:0

route at one pi (identical on other pi):


pi1@raspberrypi ~ $ route
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
default         192.168.1.1     0.0.0.0         UG    0      0        0 eth0
192.168.1.0     *               255.255.255.0   U     0      0        0 eth0
192.168.2.0     *               255.255.255.0   U     0      0        0 wlan0

iwlist scan at each pi:


pi1@raspberrypi ~ $ sudo iwlist wlan0 scan
wlan0     Scan completed :
          Cell 01 - Address: 02:11:87:FA:4A:02
                    ESSID:"pi-ad-hoc"
                    Protocol:IEEE 802.11bg
                    Mode:Ad-Hoc
                    Frequency:2.427 GHz (Channel 4)
                    Encryption key:off
                    Bit Rates:1 Mb/s; 2 Mb/s; 5.5 Mb/s; 11 Mb/s; 6 Mb/s
                              9 Mb/s; 12 Mb/s; 18 Mb/s; 24 Mb/s; 36 Mb/s
                              48 Mb/s; 54 Mb/s
                    Quality:0  Signal level:0  Noise level:0
          Cell 04 - Address: 02:11:87:C4:F2:01
                    ESSID:"pi-ad-hoc"
                    Protocol:IEEE 802.11bg
                    Mode:Ad-Hoc
                    Frequency:2.427 GHz (Channel 4)
                    Encryption key:off
                    Bit Rates:1 Mb/s; 2 Mb/s; 5.5 Mb/s; 11 Mb/s; 6 Mb/s
                              9 Mb/s; 12 Mb/s; 18 Mb/s; 24 Mb/s; 36 Mb/s
                              48 Mb/s; 54 Mb/s
                    Signal level=100/100
pi2@raspberrypi ~ $ sudo iwlist wlan0 scan wlan0 Scan completed : Cell 01 - Address: 02:11:87:C4:F2:01 ESSID:"pi-ad-hoc" Protocol:IEEE 802.11bg Mode:Ad-Hoc Frequency:2.427 GHz (Channel 4) Encryption key:off Bit Rates:1 Mb/s; 2 Mb/s; 5.5 Mb/s; 11 Mb/s; 6 Mb/s 9 Mb/s; 12 Mb/s; 18 Mb/s; 24 Mb/s; 36 Mb/s 48 Mb/s; 54 Mb/s Quality:0 Signal level:0 Noise level:0 Cell 02 - Address: 02:11:87:FA:4A:02 ESSID:"pi-ad-hoc" Protocol:IEEE 802.11bg Mode:Ad-Hoc Frequency:2.427 GHz (Channel 4) Encryption key:off Bit Rates:1 Mb/s; 2 Mb/s; 5.5 Mb/s; 11 Mb/s; 6 Mb/s 9 Mb/s; 12 Mb/s; 18 Mb/s; 24 Mb/s; 36 Mb/s 48 Mb/s; 54 Mb/s Signal level=100/100

Ping does not work, and no networking seems to work between them. From iwconfig, you can see that they each have a different "Cell" address (not the same Cell as in the iwlist scan) which is the pseudo-base station ID that is used to define an ad-hoc network (my best understanding from what I've read). Also, from the iwlist, each pi can see their own plus the other pi's ad-hoc network. I assume they need to select the same Cell id to communicate, and I'm unsure how to get them to do this automatically. I tried statically forcing these to be the same with the following command at each pi which did not change the cell id and therefore did not work:

sudo iwconfig wlan0 ap (some address)

I also tried a solution which uses ap_scan=2 in the wpa_supplicant config which did not seem to help.

Anyone have any idea what I've done wrong?

Thanks, Andy.

Answer

Andy picture Andy · May 19, 2013

After some searching I found that the Belkin USB adapter I was using apparently didn't have ad-hoc mode support with the linux drivers. I bought some other wireless USB adapaters that worked great "Edimax EW-7811Un 150 Mbps Wireless 11n Nano Size USB Adapter". They are cheaper, smaller, and they worked in ad-hoc mode without even needing to worry drivers. The details I put for troubleshooting can be used as a guide if you are also wanting to do ad-hoc raspberry PI projects.