Close

A Debian-based Wi-Fi repeater

A project log for Controlling a JJRC H37 Elfie quad from a PC

The JJRC Elfie Quadcopter comes with an Android/iOS app to control it from the phone. Can we control it from our own software?

adriajunyent-ferreadria.junyent-ferre 02/13/2017 at 23:070 Comments

One of my first concerns as soon as I played with the Elfie for the first time was the limited range one could achieve due to the weak Wi-Fi connection between the quadcopter and the phone. I read somewhere that people had successfully used Wi-Fi repeaters to extend the range of the Parrot drones and I assumed there wasn't any reason why it wouldn't be possible to do the same with the Elfie (SPOILER: I was right).

I bought a random-branded usb wifi adapter + antenna combo with an alleged gain of 14 dBi (I haven't really thought if the specifications are realistic) and I thought I'd use an old laptop running Debian to act as a Wi-Fi repeater between the toy and my phone.

After a lot of tries and plenty of frustration trying to use NetworkManager to create a Wi-Fi my phone could see and connect to ("Access Point" or "AP" mode rather than "Ad-Hoc") I found the following procedure that is more or less easy to set up without breaking my normal configuration:

[EDIT] the credit for the procedure goes to this excellent thread: http://askubuntu.com/questions/180733/how-to-setup-an-access-point-mode-wi-fi-hotspot

    1. First I shut the network manager by doing
      # /etc/init.d/network-manager stop
    2. Then I replace /etc/network/interfaces to contain the following
      source /etc/network/interfaces.d/*
      
      auto lo
      iface lo inet loopback
      
      auto wlan1
      iface wlan1 inet dhcp
             wireless-essid JJRC-A3194E #SSID of the Wi-Fi of the quadcopter
    3. Then, I can make my laptop connect to the quadcopter using ifup:
      #ifup wlan1
    4. The next step is to create an access point using the second Wi-Fi card in the laptop. This can be done using hostapd. This wasn't installed in my computer by default, so I had to apt-get install it. Afterwards, I created a config file in /etc/hostapd/hostapd.conf containing the following self-explanatory definitions:
      interface=wlan0
      ssid=ElfieRepeater
      hw_mode=g
      channel=1
      macaddr_acl=0
      auth_algs=1
      ignore_broadcast_ssid=0
      wpa=3
      wpa_passphrase=1234567890
      wpa_key_mgmt=WPA-PSK
      wpa_pairwise=TKIP
      rsn_pairwise=CCMP
    5. The config file didn't exist at all and I had to modify another config file in order to make hostapd load my configuration. This was done by editing the file /etc/default/hostapd to include the following line:
      DAEMON_CONF="/etc/hostapd/hostapd.conf"
    6. Once that was done, it was possible to start the "repeater" Wi-Fi network by starting the hostapd daemon the Debian way:
      #/etc/init.d/hostapd start
    7. The status of hostapd can be checked by using the command "status" rather than start in init.d. The expected output should say that the service is active with no errors. Once this is active, the Wi-Fi network "ElfieRepeater" becomes visible for the mobile one and one can connect to it. However, no DHCP server has been set up, therefore the phone won't get any IP address assigned and an error will be shown in the phone. This issue can be fixed by installing a DHCP server, I've read some people use isc-dhcp-server but I didn't want to go through the process of setting that up and I simply configured the IP of the Wi-Fi adapter from the laptor and manually configured the IP of the mobile phone from the mobile phone. The first step, from the laptop is:
      #ifconfig wlan0 10.10.0.1
      Then in the mobile phone I chose "static" rather than "dhcp" in the advanced settings when connecting to the Wi-Fi and chose 10.10.0.2 as the ip of the phone and 10.10.0.1 as the gateway IP.
    8. The last step is to configure the iptables in the laptop to forward the traffic it receives in wlan0 so that the phone can connect to the quadcopter through the repeater, this can be done using the following commands:
      #echo 1 | tee /proc/sys/net/ipv4/ip_forward
      #iptables -t nat -A POSTROUTING -s 10.10.0.0/16 -o wlan1 -j MASQUERADE
    9. Voilà! Now the JJRC application can be run from the phone and it should be able to connect to the Elfie as if the phone had been connected straight to the Elfie.

    If the aforementioned procedure doesn't work because the forwarding doesn't work, the whole setup can be debugged by having the laptop connect to the wifi hotspot of the broadband modem and try to load webpages from the mobile phone. It didn't give much trouble to me, frankly.

    The way to go back to the original network setup in the laptop is relatively easy to follow: stop hostapd, switch /etc/network/interfaces to its original content and start the network-manager as if nothing had happened.

    Below are some pictures from the test I did: I put the quadcopter in a separate room and brought the antenna nearby while I connected to the phone through the repeater Wi-Fi in a different room. I did some clumsy FPV flying trying to get the quadcopter to exit the room but ended up crashing it against a wall.

    This is the Wi-Fi antenna+repeater thing mounter on a tripod. The USB cable is several metres long, which was convenient for the test:

    Here's the laptop that acts as the Wi-Fi repeater and the mobile phone connected to the quadcopter through the laptop:

    Here's a video capture from the quadcopter trying to leave the room through the door:

    I was afraid that the repeater trick would add terrible latency to the communication, which would make this setup totally impractical. However, the latency didn't seem to be too bad. I haven't made any measurements but it feels as if the latency was lower than the update cycle of the controls (UDP packets are sent every 50 ms from the mobile phone to the quadcopter).

    Final words:

    The reason why I did all this was because I was concerned about the weak Wi-Fi connection curtailing the distance I am able to reach with the quadcopter. However, the trick allows a range of other things to be done, including:

    - capturing the traffic between the phone and the quadcopter (being the Elfie's wifi an open network, this was already possible using a wifi adapter in monitor mode).

    - controlling the Elfie through the interwebs / lan (subject to latency, of course).

    I wish it was possible to configure more things in the Elfie. If for example we had control over its Wi-Fi settings, we could make it connect to a Wi-Fi infrastructure rather than host its own network. This would enable, for example, to have the quadcopter roam around a building or an entire campus seamlessly jumping from one Wi-Fi hotspot to the next one. I bet someone is doing that with small wheeled rovers, doing it with a cheap quadcopter is more challenging of course because of the lack of stability for autonomous flight.

    Discussions