|
1 |
| -# transmitter-linux |
| 1 | + |
| 2 | +# Open Drone ID transmitter example for Linux |
| 3 | + |
| 4 | +This program supports transmitting static drone ID data via Wi-Fi Beacon or Bluetooth on a desktop Linux PC. |
| 5 | + |
| 6 | +For further information about Open Drone ID and the related specifications, please see the documentation in [opendroneid-core-c](https://github.com/opendroneid/opendroneid-core-c). |
| 7 | + |
| 8 | +The drone ID data is just static data, since the main purpose is to demonstrate how to setup the Bluetooth and Wi-Fi Beacon HW + SW to transmit valid drone ID data. |
| 9 | +This could easily be extended to simulate a bit more dynamic flight example. |
| 10 | + |
| 11 | + |
| 12 | +## How to compile |
| 13 | + |
| 14 | +The below instructions have been tested on Ubuntu 20.04 and on Raspbian 10 (Buster). |
| 15 | + |
| 16 | +``` |
| 17 | +git clone [email protected]:opendroneid/transmitter-linux.git |
| 18 | +cd transmitter-linux |
| 19 | +git submodule update --init |
| 20 | +``` |
| 21 | +The Bluez source code repository has been set to version 5.53, since this matched the version installed on Ubuntu 20.04. |
| 22 | +It might be required to check what version of Bluez is installed on your environment and adjust accordingly: |
| 23 | +Check any of `btmon --version`, `btmgmt --version`, `bluetoothctl --version`, `hcitool` or `hciconfig`. |
| 24 | + |
| 25 | +Compile hostapd: |
| 26 | + |
| 27 | +``` |
| 28 | +sudo apt install build-essential git libpcap-dev libsqlite3-dev binutils-dev bc pkg-config libssl-dev libiberty-dev libdbus-1-dev libnl-3-dev libnl-genl-3-dev libnl-route-3-dev |
| 29 | +cd hostapd/hostapd |
| 30 | +cp defconfig .config |
| 31 | +make -j4 |
| 32 | +cd - |
| 33 | +``` |
| 34 | + |
| 35 | +Compile the transmitter example application: |
| 36 | +``` |
| 37 | +mkdir build && cd build |
| 38 | +cmake ../. |
| 39 | +make -j4 |
| 40 | +``` |
| 41 | + |
| 42 | +## Command line parameters |
| 43 | + |
| 44 | +* `b` Enable Wi-Fi Beacon transmission |
| 45 | +* `l` Enable Bluetooth 4 Legacy Advertising transmission using non-Extended Advertising API |
| 46 | +* `4` Enable Bluetooth 4 Legacy Advertising transmission using Extended Advertising API |
| 47 | +* `5` Enable Bluetooth 5 Long Range + Extended Advertising transmission |
| 48 | +* `p` Use message packs instead of single messages |
| 49 | + |
| 50 | + |
| 51 | +## Starting Wi-Fi Beacon transmission |
| 52 | + |
| 53 | +The Wi-Fi Beacon transmission only works properly when the PC is not connected to any Wi-Fi hotspots. |
| 54 | +If it is connected, it somehow prevents configuring the Wi-Fi HW to act as a local access point. |
| 55 | + |
| 56 | +On Ubuntu, open the system settings -> Wi-Fi and for each of the networks that are stored on the machine, click the gear icon and then click forget network. |
| 57 | + |
| 58 | +On the Raspberry Pi OS, try first to click the Wi-Fi icon in the top right corner. |
| 59 | +For each network that is already configured, right-click it and forget the network. |
| 60 | +It is also possible that there are connection settings stored in the file `/etc/wpa_supplicant/wpa_supplicant.conf`. |
| 61 | +Edit the file and delete/comment out all known Wi-Fi networks, then reboot. |
| 62 | + |
| 63 | +NOTE: When tested, the beacon transmit only partly worked on Raspberry Pi 3 and 4. |
| 64 | +The pre-defined single location message that can be uncommented in the beacon.conf file works okay. |
| 65 | +However, any data that the `transmit` program tries to write to the host ap daemon does not appear to be used. |
| 66 | +It is not clear why this is so. |
| 67 | + |
| 68 | +Check that there is nothing preventing the usage of the Wi-Fi HW by running the tool `rfkill`. |
| 69 | +Any SW block should be possible to unblock via the same tool. |
| 70 | + |
| 71 | +To start hostapd, a configuration file must be present with the following content. |
| 72 | +E.g. modify the beacon.conf that is provided in the root of the project folder. |
| 73 | +Make sure the second line matches the name of your WLAN device. |
| 74 | +Can be checked e.g. with `ip link show` or `iw dev`: |
| 75 | + |
| 76 | +``` |
| 77 | +country_code=DE |
| 78 | +interface=wlan0 |
| 79 | +ssid=DroneIDTest |
| 80 | +hw_mode=g |
| 81 | +channel=6 |
| 82 | +macaddr_acl=0 |
| 83 | +auth_algs=1 |
| 84 | +ignore_broadcast_ssid=0 |
| 85 | +wpa=2 |
| 86 | +wpa_passphrase=thisisaverylongpassword |
| 87 | +wpa_key_mgmt=WPA-PSK |
| 88 | +wpa_pairwise=TKIP |
| 89 | +rsn_pairwise=CCMP |
| 90 | +ctrl_interface=/var/run/hostapd |
| 91 | +beacon_int=200 # Does this work? Doesn't seem to have any effect? |
| 92 | +
|
| 93 | +#This is an empty information element. dd indicates hex. 01 is the length of the data and 00 the actual data: |
| 94 | +vendor_elements=dd0100 |
| 95 | +
|
| 96 | +#This information element has one fixed Location message: |
| 97 | +#vendor_elements=dd1EFA0BBC0D00102038000058D6DF1D9055A308820DC10ACF072803D20F0100 |
| 98 | +``` |
| 99 | + |
| 100 | +Open a separate shell at the top of the project and start the hostapd daemon. |
| 101 | +This only works with `sudo` rights: |
| 102 | +``` |
| 103 | +sudo hostapd/hostapd/hostapd beacon.conf |
| 104 | +``` |
| 105 | + |
| 106 | +In the original shell, start the opendroneid transmitter. |
| 107 | +Again, this only works with `sudo` rights: |
| 108 | +``` |
| 109 | +sudo ./transmit b p |
| 110 | +``` |
| 111 | + |
| 112 | +This has been tested on a [CometLake Z490 desktop](https://rog.asus.com/motherboards/rog-strix/rog-strix-z490-i-gaming-model) with built-in Wi-Fi HW on the motherboard. |
| 113 | +For some reason, a fair amount of the messages being sent to hostapd are not received or at least not properly acknowledged by the lower SW layers. |
| 114 | +This is clearly visible when following the command line output. |
| 115 | +It is not clear why this is happening. |
| 116 | + |
| 117 | +Another unclear issue is that setting the beacon interval in the beacon.conf file does not seem to have any effect. |
| 118 | + |
| 119 | +## Starting Bluetooth transmission |
| 120 | + |
| 121 | +The program must be run with `sudo` rights: |
| 122 | +``` |
| 123 | +sudo ./transmit 5 p |
| 124 | +``` |
| 125 | + |
| 126 | +For educational purposes, it is possible to follow the HCI command flow using the tool `sudo btmon`. |
| 127 | +This requires Bluez to be installed: `sudo apt install bluez`. |
| 128 | + |
| 129 | +This has been tested on a [CometLake Z490 desktop](https://rog.asus.com/motherboards/rog-strix/rog-strix-z490-i-gaming-model) with built-in Bluetooth HW on the motherboard. |
| 130 | +On this HW, BT4 Legacy Advertisements using the Extended Advertising API (`option 4`) and BT5 Long Range + Extended Advertisements (`option 5 p`) would work just fine when run individually. |
| 131 | +However, when configuring both simultaneously, for some reason the HW/driver SW would only broadcast the BT4 signals. |
| 132 | +Using the BT4 Legacy Advertising non-Extended Advertising HCI commands (`option l`) for some reason didn't work. |
| 133 | + |
| 134 | +When tested on a Raspberry Pi 3 and 4, the Extended Advertising HCI interface commands are not supported (`option 4` and `option 5 p`). |
| 135 | +Probably due to the HW/driver only supporting BT4 Legacy Advertising. |
| 136 | +The older BT4 Legacy non-Extended Advertising HCI commands (`option l`) worked okay. |
| 137 | + |
| 138 | +## How to clean up |
| 139 | + |
| 140 | +If the program is terminated abnormally, Beacon and Bluetooth broadcasts can remain running. |
| 141 | +* To stop Beacon broadcast, stop the `hostapd` instance. |
| 142 | + It can be difficult to stop the `transmit` instance. After stopping `hostapd`, use `sudo pkill transmit`. |
| 143 | +* To stop Bluetooth, use `sudo btmgmt power off` and then `sudo btmgmt power on`. |
0 commit comments