|
| 1 | +# ESP32 CSI Data Collection Project |
| 2 | + |
| 3 | +This project involves multiple ESP32 devices that communicate with each other using ESP-NOW to collect and log Channel |
| 4 | +State Information (CSI) data. Each device is flashed with the same program, with the default device ID changing the |
| 5 | +first time. The device ID is persisted, allowing the same program to be flashed to all devices. Device 0 logs all sent |
| 6 | +and received payloads, which contain CSI data. The system uses a timeout mechanism and follows a round-robin protocol |
| 7 | +where each device sends a packet once the previous device has sent a packet. |
| 8 | + |
| 9 | +## Project Structure |
| 10 | + |
| 11 | +- `CMakeLists.txt`: CMake build configuration file. |
| 12 | +- `app_init.c/h`: Source and header file for application initialization. |
| 13 | +- `app_main.c`: Main application source file. |
| 14 | +- `app_nvs.c/h`: Source and header file for non-volatile storage (NVS) operations. |
| 15 | +- `constants.h`: Defines constants used throughout the project. |
| 16 | +- `csi_data.c/h`: Source and header file for handling CSI data. |
| 17 | +- `idf_component.yml`: Component configuration file. |
| 18 | + |
| 19 | +## Files |
| 20 | + |
| 21 | +### `CMakeLists.txt` |
| 22 | + |
| 23 | +This file contains the build configuration for the project using CMake. |
| 24 | + |
| 25 | +### `app_init.c` and `app_init.h` |
| 26 | + |
| 27 | +These files handle the initialization of the application, including setting up the ESP-NOW communication and configuring |
| 28 | +the device. |
| 29 | + |
| 30 | +### `app_main.c` |
| 31 | + |
| 32 | +This is the main application file where the primary logic of the project is implemented. |
| 33 | + |
| 34 | +### `app_nvs.c` and `app_nvs.h` |
| 35 | + |
| 36 | +These files handle operations related to non-volatile storage (NVS), such as storing and retrieving the device ID. |
| 37 | + |
| 38 | +### `constants.h` |
| 39 | + |
| 40 | +Defines various constants used in the project, such as device IDs, timeout values, and buffer sizes. |
| 41 | + |
| 42 | +### `csi_data.c` and `csi_data.h` |
| 43 | + |
| 44 | +These files define structures and functions for handling CSI data. Key structures include: |
| 45 | + |
| 46 | +- `csi_data_t`: Holds CSI data received from a device. |
| 47 | +- `payload_t`: Holds the payload of CSI data received from all devices. |
| 48 | + |
| 49 | +Key functions include: |
| 50 | + |
| 51 | +- `send_csi_data()`: Sends the CSI data to the broadcast address using ESP-NOW. |
| 52 | +- `print_csi_data(const csi_data_t *csi_data)`: Prints the CSI data to the console. |
| 53 | +- `print_payload(const payload_t *payload)`: Prints the payload to the console. |
| 54 | +- `wifi_csi_rx_cb(void *ctx, wifi_csi_info_t *info)`: Callback function to handle received CSI data. |
| 55 | +- `turns_away(const uint8_t device_id)`: Returns the number of devices between the current and last device IDs. |
| 56 | + |
| 57 | +## How It Works |
| 58 | + |
| 59 | +1. **Flashing the Devices**: Each ESP32 device is flashed with the same program. The default device ID is set during the |
| 60 | + first run and is persisted for subsequent runs. |
| 61 | +2. **Device 0**: Device 0 logs all sent and received payloads, which contain CSI data. |
| 62 | +3. **Timeout System**: The system uses a timeout mechanism where each device waits for a certain number of iterations |
| 63 | + before sending a packet. The number of iterations is based on how many devices away the device is from the previous |
| 64 | + device. |
| 65 | +4. **Round-Robin Protocol**: The devices follow a round-robin protocol where each device sends a packet once the |
| 66 | + previous device has sent a packet. |
| 67 | +5. **Piggybacking CSI Data**: The devices piggyback CSI data on the ESP-NOW packets they send to the broadcast address. |
| 68 | + |
| 69 | +## Building and Flashing |
| 70 | + |
| 71 | +First, add the ports for the ESP32 devices to the `Makefile`: |
| 72 | + |
| 73 | +```makefile |
| 74 | +PORTS = /dev/ttyUSB0 /dev/ttyUSB1 /dev/ttyUSB2 |
| 75 | +``` |
| 76 | + |
| 77 | +To build and flash the firmware to the ESP32 devices, use the following commands: |
| 78 | + |
| 79 | +```sh |
| 80 | +make install |
| 81 | +make build |
| 82 | +make flash DEVICE=<device_id> |
| 83 | +make monitor DEVICE=<device_id> |
| 84 | +``` |
| 85 | + |
| 86 | +Replace `<device_id>` with the device ID of the ESP32 device you want to flash. The device ID should be an integer. |
| 87 | +If the device ID is not specified, the default device ID is 0. |
| 88 | + |
| 89 | +To flash the firmware and then monitor the serial output, use: |
| 90 | + |
| 91 | +```sh |
| 92 | +make flash-monitor DEVICE=<device_id> |
| 93 | +``` |
| 94 | + |
| 95 | +To clean the build directory, use: |
| 96 | + |
| 97 | +```sh |
| 98 | +make clean |
| 99 | +``` |
| 100 | + |
| 101 | +## Contributing |
| 102 | + |
| 103 | +Contributions are welcome! For feature requests, bug reports, or questions, please open an issue. |
| 104 | + |
| 105 | +## License |
| 106 | + |
| 107 | +This project is licensed under the MIT License. See the `LICENSE` file for more information. |
| 108 | + |
| 109 | +## Appendix |
| 110 | + |
| 111 | +### Obtaining payload data from callback function `wifi_csi_rx_cb` |
| 112 | + |
| 113 | +#### Vendor Specific Action Frame |
| 114 | + |
| 115 | +| MAC Header | Category Code | Organization Identifier | Random Values | Vendor Specific Content | FCS | |
| 116 | +|------------|---------------|-------------------------|---------------|-------------------------|---------| |
| 117 | +| 24 bytes | 1 byte | 3 bytes | 4 bytes | 7-1532 bytes | 4 bytes | |
| 118 | + |
| 119 | +#### Vendor Specific Element Frame |
| 120 | + |
| 121 | +| Element ID | Length | Organization Identifier | Type | Reserved | More data | Version | Body | |
| 122 | +|------------|--------|-------------------------|--------|----------|-----------|----------|--------------| |
| 123 | +| 1 byte | 1 byte | 3 bytes | 1 byte | 7-5 bits | 1 bit | 3-0 bits | 0-1490 bytes | |
| 124 | + |
| 125 | +The payload data of the Wi-Fi packet is obtained from the `wifi_csi_info_t` structure using the `payload` field. |
| 126 | +It starts with the Category Code of the Vendor Specific Action frame. This means, the payload of the ESP-NOW packet |
| 127 | +begins at index 15. |
0 commit comments