|
| 1 | +# Wi-Fi FTM Initiator Arduino Example |
| 2 | + |
| 3 | +This example demonstrates how to use the Fine Timing Measurement (FTM) to calculate the distace from the Access Point and the device. This is calculated by the Wi-Fi Round Trip Time (Wi-Fi RTT) introduced on the [IEEE Std 802.11-2016](https://en.wikipedia.org/wiki/IEEE_802.11mc) standard. |
| 4 | + |
| 5 | +This example was based on the [ESP-IDF FTM](https://github.com/espressif/esp-idf/tree/master/examples/wifi/ftm). See the README file for more details about on how to use this feature. |
| 6 | + |
| 7 | +Some usages for this feature includes: |
| 8 | + |
| 9 | +* Indoor positioning systems. |
| 10 | +* Navigation. |
| 11 | +* Device Location. |
| 12 | +* Smart Devices. |
| 13 | +* Alarms. |
| 14 | + |
| 15 | +# Supported Targets |
| 16 | + |
| 17 | +Currently, this example supports the following targets: |
| 18 | + |
| 19 | +| Supported Targets | ESP32-S2 | ESP32-C3 | |
| 20 | +| ----------------- | -------- | -------- | |
| 21 | + |
| 22 | +## How to Use Example |
| 23 | + |
| 24 | +In order to use the FTM, you will need a Responder or Wi-Fi router with FTM capabilities. If you don't own one, you can use a second ESP32-S2 or ESP32-C3 to simulate one. |
| 25 | +See the **Responder** example to prepare the environment. |
| 26 | + |
| 27 | +* How to install the Arduino IDE: [Install Arduino IDE](https://github.com/espressif/arduino-esp32/tree/master/docs/arduino-ide). |
| 28 | + |
| 29 | +### Configure the Project |
| 30 | + |
| 31 | +To configure this project, you can change the following configuration related to FTM feature: |
| 32 | + |
| 33 | +```c |
| 34 | +// Change the SSID and PASSWORD here if needed |
| 35 | +const char * WIFI_FTM_SSID = "WiFi_FTM_Responder"; // SSID of AP that has FTM Enabled |
| 36 | +const char * WIFI_FTM_PASS = "ftm_responder"; // STA Password |
| 37 | + |
| 38 | +// FTM settings |
| 39 | +// Number of FTM frames requested in terms of 4 or 8 bursts (allowed values - 0 (No pref), 16, 24, 32, 64) |
| 40 | +const uint8_t FTM_FRAME_COUNT = 16; |
| 41 | +// Requested time period between consecutive FTM bursts in 100’s of milliseconds (allowed values - 0 (No pref) or 2-255) |
| 42 | +const uint16_t FTM_BURST_PERIOD = 2; |
| 43 | +``` |
| 44 | + |
| 45 | +* Change the Wi-Fi `SSID` and `PASSWORD` as the same as the Responder/Router. |
| 46 | +* Change `FTM_FRAME_COUNT` with the number of frames requested to the Responder. |
| 47 | +* Change `FTM_BURST_PERIOD` with the time between each FTM burst. |
| 48 | + |
| 49 | +To see more details about FTM, please see the [ESP-IDF docs](https://docs.espressif.com/projects/esp-idf/en/latest/esp32s2/api-reference/network/esp_wifi.html). |
| 50 | + |
| 51 | +#### Using Arduino IDE |
| 52 | + |
| 53 | +To get more information about the Espressif boards see [Espressif Development Kits](https://www.espressif.com/en/products/devkits). |
| 54 | + |
| 55 | +* Before Compile/Verify, select the correct board: `Tools -> Board`. |
| 56 | +* Select the COM port: `Tools -> Port: xxx` where the `xxx` is the detected COM port. |
| 57 | + |
| 58 | +#### Using Platform IO |
| 59 | + |
| 60 | +* Select the COM port: `Devices` or setting the `upload_port` option on the `platformio.ini` file. |
| 61 | + |
| 62 | +## Log Output |
| 63 | + |
| 64 | +Expected log output: |
| 65 | + |
| 66 | +``` |
| 67 | +ESP-ROM:esp32s2-rc4-20191025 |
| 68 | +Build:Oct 25 2019 |
| 69 | +rst:0x1 (POWERON),boot:0x8 (SPI_FAST_FLASH_BOOT) |
| 70 | +SPIWP:0xee |
| 71 | +mode:DIO, clock div:1 |
| 72 | +load:0x3ffe6100,len:0x4b0 |
| 73 | +load:0x4004c000,len:0xa6c |
| 74 | +load:0x40050000,len:0x25c4 |
| 75 | +entry 0x4004c198 |
| 76 | +Connecting to FTM Responder |
| 77 | +..... |
| 78 | +WiFi Connected |
| 79 | +Initiating FTM session with Frame Count 16 and Burst Period 200 ms |
| 80 | +FTM Estimate: Distance: 0.13 m, Return Time: 0 ns |
| 81 | +FTM Estimate: Distance: 0.13 m, Return Time: 0 ns |
| 82 | +FTM Estimate: Distance: 0.13 m, Return Time: 0 ns |
| 83 | +FTM Estimate: Distance: 0.00 m, Return Time: 0 ns |
| 84 | +... |
| 85 | +``` |
| 86 | + |
| 87 | +## Troubleshooting |
| 88 | + |
| 89 | +***Important: Make sure you are using a good quality USB cable and that you have a reliable power source.*** |
| 90 | + |
| 91 | +* **Programming Fail:** If the programming/flash procedure fails, try reducing the serial connection speed. |
| 92 | +* **COM port not detected:** Check the USB cable and the USB to Serial driver installation. |
| 93 | + |
| 94 | +If the error persist, you can ask for help at the official [ESP32 forum](https://esp32.com) or see [Contribute](#contribute). |
| 95 | + |
| 96 | +## Contribute |
| 97 | + |
| 98 | +To know how to contribute to this project, see [How to contribute.](https://github.com/espressif/arduino-esp32/blob/master/CONTRIBUTING.rst) |
| 99 | + |
| 100 | +If you have any **feedback** or **issue** to report on this example/library, please open an issue or fix it by creating a new PR. Contributions are more than welcome! |
| 101 | + |
| 102 | +Before creating a new issue, be sure to try the Troubleshooting and to check if the same issue was already created by someone else. |
| 103 | + |
| 104 | +## Resources |
| 105 | + |
| 106 | +* Official ESP32 Forum: [Link](https://esp32.com) |
| 107 | +* Arduino-ESP32 Official Repository: [espressif/arduino-esp32](https://github.com/espressif/arduino-esp32) |
| 108 | +* ESP32-S2 Datasheet: [Link to datasheet](https://www.espressif.com/sites/default/files/documentation/esp32-s2_datasheet_en.pdf) |
| 109 | +* ESP32-C3 Datasheet: [Link to datasheet](https://www.espressif.com/sites/default/files/documentation/esp32-c3_datasheet_en.pdf) |
| 110 | +* Official ESP-IDF documentation: [ESP-IDF](https://idf.espressif.com) |
0 commit comments