README

Wi-Fi CSI Occupancy Detection

Example Summary

The WiFi CSI Occupancy Detection example detects whether a room is empty or occupied using Wi-Fi Channel State Information (CSI) on the LP-EM-CC35X1. People moving in a room distort the Wi-Fi signal between the LaunchPad and an access point (AP). The device measures this distortion, extracts features on-device, and either streams them to TI’s Edge AI Studio to build a model or runs the trained model locally.

This example provides two projects:

Project What it does
edgeai_wifi_csi_occupancy_detection_data_capture Streams CSI features to Edge AI Studio so you can record and label “empty” and “presence” data for training.
edgeai_wifi_csi_occupancy_detection_live_preview Runs your trained model on the device and shows the live occupancy result in Edge AI Studio.

Workflow: run edgeai_wifi_csi_occupancy_detection_data_capture, record labeled data, train and compile a model in Edge AI Studio, then export the model into edgeai_wifi_csi_occupancy_detection_live_preview Example.

Requirements

Project Contents

File / folder Description
serial_automation.py, serial_config.json Script and settings that connect the device to your AP and start CSI.
csi_stream.c/.h edgeai_wifi_csi_occupancy_detection_data_capture only. CSI preprocessing and streaming to Edge AI Studio.
csi_presence.c/.h edgeai_wifi_csi_occupancy_detection_live_preview only. CSI preprocessing, model inference and result reporting to Edge AI Studio.
ai_artifacts/ edgeai_wifi_csi_occupancy_detection_live_preview only. The compiled model (mod.a, tvmgen_default.h, user_input_config.h). Replace these with the files generated by Edge AI Studio.
feature_extraction/ edgeai_wifi_csi_occupancy_detection_live_preview only. Feature extraction (FFT, normalization) feeding the model.
dap/ Device Agent Protocol, the UART link to Edge AI Studio.
adaptation/, freertos/ Board support, SysConfig file and linker script.
network_terminal.c, wlan_cmd.c, other files Wi-Fi console and networking from the SDK Network Terminal example.

Peripherals & Pin Assignments

Example Usage

1. Build and flash

Build and flash edgeai_wifi_csi_occupancy_detection_data_capture to collect training data. If you already have a trained model, use edgeai_wifi_csi_occupancy_detection_live_preview.

2. Connect to your access point and start CSI

Use the included script, or type the commands yourself.

  1. Install the dependency:

    pip install pyserial
  2. Edit serial_config.json in the project folder:

    {
      "port": "COMXY",
      "ssid": "MyAccessPoint",
      "password": "my-password",
      "mac_address": "aa:bb:cc:dd:ee:ff"
    }
    Key Required Default Description
    port yes Serial port of the LaunchPad, e.g. COM59 or /dev/ttyACM0
    ssid yes Access point name (no double quotes)
    password unless OPEN Access point password (no double quotes)
    mac_address yes MAC address of the access point, aa:bb:cc:dd:ee:ff
    security_type no WPA2 OPEN, WPA2, WPA2_PLUS, WPA3 or WPA2/WPA3
    connect_timeout no 60 Seconds to wait for the AP connection and IP address
    log_file no none Save all device output to this file

    The baud rate (921600) and CSI settings are fixed by the example. Timing and retry keys are listed at the top of serial_automation.py.

  3. Close any existing serial terminal, then reset the board, and run the following commands within a fresh terminal:

    python serial_automation.py

    Settings can also be given on the command line:

    python serial_automation.py --port /dev/ttyACM0 --ssid MyAP --password secret --mac aa:bb:cc:dd:ee:ff

    Use --config <file> to load a different settings file.

When it finishes, the script prints All commands sent successfully! and releases the serial port for Edge AI Studio. It exits with 0 on success, 1 if a step failed, and 2 for a settings error.

Option B: Manual

  1. Open the LaunchPad’s serial port in a terminal (921600 baud, 8N1, no flow control).
  2. Enter:

    wlan_start
    wlan_sta_role_up
    wlan_connect -s "<SSID>" -t WPA2 -p "<password>"
    csi_enable
    csi_config -s 1 -p 7
    csi_set_mac -a 1 -m <AP MAC address>
    csi_get_results

    csi_config -s 1 -p 7 is required: the example processes CSI at 128 Hz, which needs solicitation enabled (-s 1) with period -p 7.

3. Connect Edge AI Studio

After successful operation of step 2, the console prints DAP streaming ready and stops accepting input. Close the terminal, then open TI’s Edge AI Studio and select the serial port with baud rate 921600.

Note: Prior to launching the Edge AI Studio, flash the appropriate example to the LaunchPad.

Warning : The default value for Samples is 256 and in the current iteration no other Samples value is supported.

Example datasets

Pre-collected datasets are available if you want to train without capturing your own data:

Dataset Sample Size Download
wifi_presence_detection_dsd_4400 4400 zip
wifi_presence_detection_dsd_2000 2000 zip
wifi_presence_detection_dsi 800 zip

wifi_presence_detection_dsi is the default dataset enabled in CCStudio™ Edge AI Studio.

4. Train and deploy your model

  1. Train and compile the model in Edge AI Studio. For best results, select the WiFiPresDet_4.7k_CDE model. This presence detection model is tuned for the CSI pipeline in this example and the only one validated end to end on the LaunchPad.
  2. After compilation, export the compiled model from Edge AI Studio and extract the .zip file. Manually copy the following files into the edgeai_wifi_csi_occupancy_detection_live_preview project’s ai_artifacts/ folder, replacing the placeholder files:
Source directories File
golden_vectors/ user_input_config.h
artifacts/ mod.a
artifacts/ tvmgen_default.h

To validate the live preview and trained model performance, repeat sections 1-3.

How It Works

Both projects process each 2 s window of CSI the same way:

  1. Decode 54 subcarriers, drops DC subcarriers sub_26, sub_53, keeps 52 amplitudes.
  2. Interpolate the irregular packet arrival onto a uniform 128 Hz grid (256 points).

edgeai_wifi_csi_occupancy_detection_data_capture streams the result (timestamp + 52 subcarriers) to Edge AI Studio, which computes the remaining features for training. edgeai_wifi_csi_occupancy_detection_live_preview continues on the device: decimate to 128 rows, L2 normalize, RFFT over time (64 bins) and subcarriers (26 bins), log scale, giving a 64x26 model input. A 3-window soft average of the model output (threshold 0.5) gives the final decision.

Troubleshooting

Symptom Likely cause
Script cannot open the port Another program (terminal, Edge AI Studio) is using it, or the wrong port is set. The LaunchPad exposes two serial ports; use the application/user one.
Script reports pyserial is required Run pip install pyserial.
Connecting to the AP times out Wrong SSID, password or security_type, or the AP is out of range.
Device disconnects from the AP after a while The keepalive socket needs the access point, the LaunchPad and the host PC on the same network. Connect all three to the same AP / subnet.
Edge AI Studio cannot connect The serial port is still open in a terminal or the script.

Known Issues and Limitations