Enabling infrastructure wifi on the ARDrone with DHCP

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:

  1. Shut down the DHCP server.
  2. Bring down the ath0 interface
  3. Bring up the ath0 interface in managed mode, connecting to SSID of choice
  4. 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.

This entry was posted in Hardware Hacking, Projects, Uncategorized and tagged , , , .

4 Comments

  1. geek65535
    Posted 2011-06-26 at 18:02 | Permalink

    Thanks so much for your script. I have wanted to be able to use my Drone with my Android phone for well over a year, and I was finally able to fly the Drone without having to snag my wife’s iPod.

  2. Posted 2011-06-26 at 18:19 | Permalink

    Glad to be of help!

  3. Hursh
    Posted 2012-08-25 at 16:57 | Permalink

    If you added a count loop for trying to connect the specified SSID network, then when if it cannot find THAT network, it will again go in AD-HOC mode. Isn’t it?

  4. Posted 2012-08-28 at 19:25 | Permalink

    That’s correct, and it’s a good idea!

Post a Comment

Your email is never published nor shared. Required fields are marked *

*
*

You may use these HTML tags and attributes <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>