Multiple Parrot Anafi controlled via Olympe on Linux, configure IP

Hello,

I am trying to control multiple ANAFI drones via a single Olympe instance running on a linux computer. I use multiple WIFI USB modems to connect to every drone.

I need every drone to have a unique IP so I can send commands and receive data streams. However, seems like every drone has a hard-coded IP and I don’t know how to change it.

Question: is IP configurable on ANAFI? If not is there a work-around so multiple ANAFI drones can be controlled via Olympe?

Thanks
Mantas

Unfortunately no, the ANAFI IP address is not configurable through the SDK. You can’t modify it without a privileged access to the drone firmware.

Please note that each drone simulated by Sphinx gets a different IP address on its virtual ethernet interface in the 10.202.0.0/24 subnet. So for simulated drones, if you don’t need the wifi interface but just want to connect to your drones from the same host, this is the way to go.

There is a workaround but it ain’t pretty. On a recent debian/ubuntu machine, use the following “config_anafi_ip.sh” like this :

./config_anafi_ip.sh setup wlan0 192.168.44.1 201
./config_anafi_ip.sh setup wlan1 192.168.45.1 202
./config_anafi_ip.sh setup wlan2 192.168.46.1 203
...

where :

  • wlanX are the names of the wifi USB dongle interfaces on your system.
  • 192.168.4X.1 are the IP address alias you want to give to each drone.
  • 20X is a ([100-900] unique random integer used as a routing table id).

You can now use the 192.168.4X.1 IP addresses to connect to your drones.

When your done just clean things up like this :

./config_anafi_ip.sh cleanup wlan0 192.168.44.1 201
./config_anafi_ip.sh cleanup wlan1 192.168.45.1 202
./config_anafi_ip.sh cleanup wlan2 192.168.46.1 203
... 
    #!/bin/bash
    # ANAFI interface configuration script: configure one ANAFI interface

    # All ANAFIs have a default IP address set to 192.168.42.1 . Hence by default,
    # multiple ANAFIs connected to a host via multiple WiFi USB dongles are not
    # addressable. This script creates a new ip address (on an independent subnet) on
    # a wifi interface. This new address (and it's subnet) is intended to be
    # decicated to this interface and all traffic on this address is correclty
    # routed to the associated ANAFI.

    set -e

    action=$1
    interface=$2
    address=$3
    route_tableid=$4
    # shellcheck disable=SC2046,SC2116,SC2086
    address_hex=0x$(printf '%02X' $(echo ${address//./ }))

    # Outbound traffic iptables rules: packets addressed to the virtual ANAFI IP
    # address are marked in order to be routed on the correct interface and then get
    # NATed to match the actual ANAFI IP address on this interface
    OUT_RULES=$(cat <<EOF
    mangle:OUTPUT      --destination      $address     -j MARK --set-mark $address_hex
    nat:OUTPUT         -m mark --mark $address_hex     -j DNAT --to-destination 192.168.42.1 
    nat:POSTROUTING    -m mark --mark $address_hex     -j SNAT --to-source 192.168.42.254
    EOF
    )

    # Inbound traffic rules: equivalent to the outbound traffic rules except we are
    # only NATing the traffic from the ANAFI interface to the virtual ANAFI IP address
    # (there is no routing involved)
    IN_RULES=$(cat <<EOF
    mangle:PREROUTING  --in-interface     $interface   -j MARK --set-mark $address_hex
    nat:PREROUTING     -m mark --mark   $address_hex   -j DNAT --to-destination $address
    nat:INPUT          -m mark --mark   $address_hex   -j SNAT --to-source $address
    EOF
    )
    RULES=$(cat <<EOF
    $OUT_RULES
    $IN_RULES
    EOF
    )

    case $action in
    setup)
      echo "Setup $interface $address ($address_hex) $route_tableid"
      # Add the ANAFI "virtual" IP
      sudo ip addr del "$address"/24 dev "$interface" > /dev/null 2>&1|| true
      sudo ip addr add "$address"/24 dev "$interface"

      # Don't rely on the IP the ANAFI dhcp gave us
      sudo ip addr del 192.168.42.254/24 dev "$interface" > /dev/null 2>&1|| true
      sudo ip addr add 192.168.42.254/24 dev "$interface"
      sudo ip link set dev "$interface" down
      sudo sysctl -w "net.ipv4.conf.$interface.rp_filter=0"
      # FIXME: We shouldn't have to deactivate rp_filter for all interfaces
      sudo sysctl -w "net.ipv4.conf.all.rp_filter=0"
      while read -r rule; do
        table="${rule%:*}"
        rule="${rule#*:}"
        # shellcheck disable=SC2086
        if ! sudo iptables -t "$table" -C $rule > /dev/null 2>&1; then
          # Add the rule to the table
          sudo iptables --wait -t "$table" -A $rule
        fi
      done <<< "$RULES"
      sudo ip link set dev "$interface" up
      sudo ip route del default via 192.168.42.254 dev "$interface" table "$route_tableid" > /dev/null 2>&1|| true
      sudo ip route add default via 192.168.42.254 dev "$interface" table "$route_tableid"
      sudo ip rule del fwmark "$address_hex" table "$route_tableid" > /dev/null 2>&1|| true
      sudo ip rule add fwmark "$address_hex" table "$route_tableid"
      ;;
    cleanup)
      echo "Cleanup $interface $address ($address_hex) $route_tableid"
      sudo ip link set dev "$interface" up
      sudo ip addr del "$address"/24 dev "$interface" || true
      sudo ip addr del 192.168.42.254/24 dev "$interface" || true
      while read -r rule; do
        table="${rule%:*}"
        rule="${rule#*:}"
        # shellcheck disable=SC2086
        while sudo iptables -t "$table" -D $rule > /dev/null 2>&1; do :;done
      done <<< "$RULES"
      # sudo sysctl -w "net.ipv4.conf.$interface.rp_filter=1"
      sudo ip route del default via 192.168.42.254 dev "$interface" table "$route_tableid" > /dev/null 2>&1 || true
      sudo ip rule del fwmark "$address_hex" table "$route_tableid" > /dev/null 2>&1 || true
      ;;
    esac