/RPiAdHocWiFi

Simple ad-hoc wireless network support for Raspberry Pi

Primary LanguageShell

RPiAdHocWiFi

Simple ad-hoc wireless network support for Raspberry Pi.

The RaspberryPi 3 and RaspberryPi Zero W come with a Broadcom wifi chip onboard, making it easy to setup an ad-hoc wifi network for remote sensing, Internet of Things, and related projects. This little repository will help you do that.
You should be running the Raspbian operating system on your Raspberry Pi.

NOTE: Following these instructions will clobber your existing startup script (/etc/rc.local) and DHCP configuration (/etc/udhcpd.conf, /etc/dhcpcd.conf). Proceed with caution!

After logging into your Raspberry Pi and cloning this repository, do the following from the command line:

% cd RPiAdHocWiFi
% sudo ./install.sh
% sudo reboot

Connecting to your ad-hoc network from another Raspberry Pi

If you have more than one Raspberry Pi, you can use one to serve up the ad-hoc network as shown above, and the other(s) to connect to the network as clients. To do that, you'll want the /etc/rc.local file on your client(s) to look like this:

#!/bin/sh -e
#
# rc.local
#
# This script is executed at the end of each multiuser runlevel.
# Make sure that the script will "exit 0" on success or any other
# value on error.

# Make me a client on the wireless ad-hoc network being served by Raspberry-Pi-1
iwconfig wlan0 mode Ad-Hoc
ifconfig wlan0 essid Raspberry-Pi-1

exit 0

Now when you open the network preferences on your desktop or laptop computer, you should see Raspberry-Pi-1 as a wifi network you can join. From there, you can connect to the Raspberry Pi using ssh:

% ssh pi@192.168.2.2

Important note

If you have an /etc/udhcpd.conf on your client, you should make sure that it is empty (so that the client is not trying to serve up an ad-hoc network). You should also make sure that the /etc/network/interfaces on the Raspberry Pi has no specifications for wlan0 (since those are being specified in /etc/rc.local). Otherwise you will likely see a different IP address (169.254....) instead of the expected 192.168.2.2.

Reversion

After installing the ad-hoc network and connecting you your Pi via SSH or a physical connection, you can revert to your previous Wi-Fi settings by running:

sudo ./revert.sh

This will keep the programs installed but undo the changes made by the installation.

Uninstallation

To completely uninstall the settings and packages (udhcp and busybox) and revert to your previous Wi-Fi settings run:

sudo ./uninstall.sh

WEP Key

If you would like to prevent anyone in range from connecting to your ad-hoc network, you can add a WEP key by adding this line:

iwconfig wlan0 key 3b205742624039762d586f4f3e

under

ifconfig wlan0 essid Raspberry-Pi-1

where 3b205742624039762d586f4f3e is your key. This key must be a hex-key and you can generate one here: http://www.andrewscompanies.com/tools/wep.asp Use a 128 bit key. A 256 bit key does not seem to work.