gateway_example

Example of the component yangcong-bit/esp-now-tdma v1.6.0
# ESP-TDMA-MAC Gateway (Master) Example

This example demonstrates how to set up the **Master (Gateway)** role using the `esp_tdma_mac` component. 

The Gateway acts as the central coordinator in the TDMA network. It automatically initializes Wi-Fi (in STA mode) and ESP-NOW, registers the broadcast peer, and broadcasts synchronisation beacons every 10 ms (default). It also handles node registration and decrypts incoming sensor data packets from registered nodes using AES-128 encryption.

The slot step is derived from the beacon period and the highest node ID in use, and is broadcast
in every beacon so the nodes derive their own offsets from it. It can be changed at runtime with
`esp_tdma_master_set_target_node_count()`, and the new geometry needs no re-provisioning. This
example also signs every beacon with a CMAC key; nodes provisioned with the same key verify it and
drop forged beacons.

> **The key is a shared secret, and a mismatch does not look like one.** A node whose
> `beacon_cmac_key` differs by a single byte rejects every beacon as failing verification and
> stays silent, which reads as a broken CMAC rather than a configuration mistake. This example
> uses `01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F 10`; `node_example` ships with the same
> value. Note also that leaving the key unset entirely is NOT the same as setting it to zeros:
> unset means the gateway does not sign, so nodes configured with a key would still reject it.

## 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, you should see Wi-Fi and ESP-NOW initialization logs:
```text
I (xxx) esp_tdma_mac: Wi-Fi initialized in STA mode by esp_tdma_mac component
I (xxx) esp_tdma_mac: ESP-NOW initialized by esp_tdma_mac component
```

When a node (Slave) boots up and initiates the registration handshake, you will see registration and incoming data logs:
```text
I (xxx) gateway: Node 1 registered and admitted to the schedule
I (xxx) gateway: Received payload from node 1, seq=100, battery=100%, len=12
```

To create a project from this example, run:

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

or download archive (~4.53 KB)