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 be
I was unsuccessful with any adapter using the RTL8188CUS
chipset. Luckily, I had a number of Ralink RT5370
dongles (from this kit) that support the nl80211
interface and ad-hoc mode.
My solution involves using wpa_supplicant
and is configured with 2 files. Ensure that the nl80211
driver is installed:
sudo apt-get install libnl1
Next, create the following wpa_supplicant
configuration file called /etc/wpa_supplicant-adhoc.conf
on each Pi:
ctrl_interface=DIR=/run/wpa_supplicant GROUP=netdev
update_config=1
ap_scan=2
network={
ssid="pihoc_wpa"
mode=1
frequency=2462
proto=WPA
key_mgmt=WPA-NONE
pairwise=NONE
group=TKIP
psk="password"
}
where you can choose the ssid
, frequency
(look here for valid values), and psk
. Make sure that you are part of the user group net-dev
using the command
getent group netdev
and if not, you can add yourself using
sudo usermod -a -G netdev userName
Next, add the following block to the /etc/network/interfaces
file on each Pi:
auto wlan0
allow-hotplug wlan0
iface wlan0 inet static
address 10.10.2.1
netmask 255.255.255.0
pre-up wpa_supplicant -B -D nl80211 -i wlan0 -c /etc/wpa_supplicant-adhoc.conf
where each Pi has a different address
field beginning with 10.10.2.
. Also, if your RT5370
adapter is using an interface other than wlan0
(e.g. wlan1
, wlan2
, etc.), be sure to use that interface name instead.
At this point, the Pis should automatically join the network upon being rebooted. Test the connection by pinging or using ssh, for example run the following from the agent with IP address 10.10.2.1
:
ssh 10.10.2.2
to access the agent with IP address 10.10.2.2
.
The steps listed here are adapted from this Arch Linux wiki article and this Raspberry Pi forum discussion.
This works for me in /etc/network/interfaces:
auto wlan0
allow-hotplug wlan0
iface wlan0 inet static
wireless-essid "MYPINET"
wireless-channel 3
wireless-mode ad-hoc
wireless-ap 11:5F:02:38:5C:45
address 192.168.10.1
netmask 255.255.255.0
The essid, channel and ap can be any valid value (same on all your Pi's). Make sure to assign different addresses on the same subnet to your different Pi's and you should be fine. The ap defines the cell ID that was mentioned above. FWIW I am using a TP-link WN725N. It has the RTL8188CUS chipset and works fine out of the box even though dmesg indicates the Pi is treating it as an RTL8192.
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.