There are a number of different articles on “patching” the AR Drone to connect to infrastructure. I’m going to talk a little about the technical details of what is going on, based on my own experience.
Background
The ARDrone, in its stock configuration, is an embedded linux device that runs Busybox. By default, on boot it starts an ad-hoc wiki network of the form ardrone_xxxxxx, where the last bit is the ID of the drone. When you connect to the ad-hoc network, the drone can assign an IP address from the 192.168.1.xxx range, where 192.168.1.1 is reserved for the drone itself.
At this point, the drone is accessible over the network via telnet
, simply use:
telnet 192.168.1.1
If you use ifconfig
, you can see the wifi device ath0
. I believe the drone simply uses mostly stock atheros wifi drivers. Now, on boot, the drone executes the initialiation script /bin/wifi_setup.sh
. You can look inside and actually see the drone configure its wireless and startup the DHCP server.
Connecting to infrastructure wifi
So if we want to connect to an infrastructure access point, we have a couple of key steps:
- Shut down the DHCP server.
- Bring down the
ath0
interface - Bring up the
ath0
interface in managed mode, connecting to SSID of choice - Run DHCP client to get IP address
The first 3 steps of this are well described in a lot of other posts like this one at Shellware, so lets talk about the DHCP client.
Busybox includes a DHCP client called udhcpc
. Running it is simple, and by default it will get an IP address and netmask:
udhcpc -b -i ath0
So now, the process of starting up the wifi is to do the following block:
killall udhcpd
ifconfig ath0 down
iwconfig ath0 mode managed essid $INFRA_ESSID ap any channel auto commit
ifconfig ath0 up
udhcpc -b -i ath0
If we want to start up ad-hoc networking again, we can do:
killall udhcpc
udhcpd /tmp/udhcpd.conf
ifconfig ath0 down
iwconfig ath0 mode Ad-Hoc essid $DRONE_SSID channel auto commit
ifconfig ath0 192.168.1.1 netmask 255.255.255.0 up
At this point, we can make scripts to manually switch between an infrastructure network and an ad-hoc network. As long as we don't run anything at boot, the drone will always safely reboot into ad-hoc mode.
Automatically connecting to infrastructure wifi
So I found an existing tool that autoloads a startup script for connecting to infrastructure APs called ARAutoConnect. It was open source, so I extracted the underlying script, which runs a loop that scans every 10s for the SSID network and connects to it, and added DHCP support. The resulting script, which can be downloaded here (autoconnect.sh), runs the same loop, but also tries to get a DHCP lease.
To use the script, simply put it in some directory. I prefer /home/default/wifi
. Now, create a file in the same directory called essid
, and put the name of the network in it. If you run the script directly, it will now search for the specified wifi network, and if it finds one, it will close the ad-hoc network and connect to the infrastructure network instead. If you want this to run at startup, simply append a line to /bin/wifi_setup.sh
that goes something like:
/home/default/wifi/autoconnect.sh &
Be warned however, if an infrastructure network is available but the drone can't complete a connection to it, it will keep trying, possibly locking any ad-hoc connections out until you move the drone out of range. Anyway, it's all free for anyone to use/adapt as they wish.