node_example

Example of the component yangcong-bit/esp-now-tdma v1.2.0
# ESP-TDMA-MAC Node (Slave) Example

This example demonstrates how to set up a **Slave (Node)** role using the `esp_tdma_mac` component.

The Node synchronizes its transmission slots based on the beacons received from the Master (Gateway). It automatically initializes Wi-Fi and ESP-NOW, listens for beacons, dynamically transitions its state, and enqueues sensor data into a lock-free ring buffer for zero-latency transmission.

This example provisions the node through `esp_tdma_slave_set_config()`, passing the unicast LMK
and the shared beacon CMAC key. Pass `NULL` instead of the key to accept unauthenticated beacons
(development only). No slot offset is passed: the node derives it from the slot step carried in
every beacon, so the gateway can resize the frame without re-provisioning the fleet.

## How to Use

### 1. Build and Flash

Configure and compile the project using ESP-IDF:
```bash
idf.py set-target esp32s3
idf.py build
idf.py flash monitor
```

### 2. Expected Output

Upon startup, the Node will search for beacons. Once the gateway sets the node's bit in the
beacon, the Node transitions to `RUNNING` and starts enqueuing and sending data:
```text
W (xxx) esp_tdma_mac: Slave: node 1 admitted to the schedule (RUNNING)
I (xxx) node: Gateway user_state is now 0
I (xxx) node: Enqueued dummy sensor data: x=1.00, y=2.00, z=3.00
```

Periodically it prints telemetry counters to evaluate wireless channel quality. This log is
emitted at debug level (`ESP_LOGD`), so raise the component's log level to see it:
```text
D (xxx) esp_tdma_mac: TX Task SLOT REACHED! Seq: 501, State: 2, SlotStep: 700 | rb_empty=0 send_fail=0 send_ok=500 reg_ack_ok=5 reg_ack_fail=0
```

To create a project from this example, run:

idf.py create-project-from-example "yangcong-bit/esp-now-tdma=1.2.0:node_example"

or download archive (~2.93 KB)