INTEGRATION¶
Introduction¶
This section explains how to integrate the RFCOM communication component (node_espnow) into your ESP-IDF project, following the implementation style used in:
CODE/AIoTNode-ESPNOW-TX-BATCHCODE/AIoTNode-ESPNOW-RX-BATCH
Create a New Component¶
Warning
Before creating components in driver, ensure your project-level CMakeLists.txt includes the driver path in EXTRA_COMPONENT_DIRS.
In VSCode terminal:
Then create:
driver/node_espnow/include/node_espnow.hdriver/node_espnow/node_espnow.cdriver/node_espnow/CMakeLists.txt
Replace Component Code¶
Replace the generated files with the RFCOM implementation from the reference projects:
- Header/API:
driver/node_espnow/include/node_espnow.h - Core logic:
driver/node_espnow/node_espnow.c - Build file:
driver/node_espnow/CMakeLists.txt
Required component dependencies:
esp_wifiesp_eventesp_netifesp_timer
Project-Level Integration¶
In main/AIoTNode.cpp:
- Include
node_espnow.h. - Prepare
node_espnow_config_tfrom defaults. - Tune communication parameters.
- Call
node_espnow_init(...). - Register RX callback via
node_espnow_set_rx_batch_cb(...). - Use
node_espnow_send_to(...)for batch transfer.
Minimum TX/RX startup skeleton:
node_espnow_config_t cfg;
node_espnow_default_config(&cfg);
cfg.channel = 1;
cfg.qos_default = NODE_ESPNOW_QOS1;
cfg.chunk_payload_bytes = 160;
cfg.tx_window_size = 1;
cfg.ack_timeout_ms = 1200;
cfg.max_retries = 8;
cfg.session_timeout_ms = 30000;
cfg.max_batch_bytes = 16384;
node_espnow_handlers_t handlers = {
.tx_result_cb = tx_result_cb_or_null,
.user_ctx = NULL,
};
ESP_ERROR_CHECK(node_espnow_init(&cfg, &handlers));
ESP_ERROR_CHECK(node_espnow_set_rx_batch_cb(rx_batch_cb, NULL));
TX/RX Deployment Pattern¶
Use two boards:
- Board A: TX build (
AIoTNode-ESPNOW-TX-BATCH) - Board B: RX build (
AIoTNode-ESPNOW-RX-BATCH)
Behavior:
- RX waits and responds to discovery request.
- TX broadcasts discovery and locks peer MAC from response.
- TX enters staged payload transmission.
- RX validates each received case and prints result.
- Both iterate QoS rounds.
Compile and Flash¶
For each project terminal:
Verification Checklist¶
- Both sides print local MAC and start logs.
- Discovery request/response appears in logs.
- TX shows queued/complete transfer logs.
- RX shows per-case PASS/FAIL validation logs.
- Final matrix summary is printed for
QOS0,QOS1,QOS2.
Common Tuning Notes¶
- If packet loss is high:
- increase
ack_timeout_ms - increase
max_retries - reduce
chunk_payload_bytes - reduce
tx_window_size - If memory pressure appears:
- reduce
max_batch_bytes - reduce RX concurrent sessions
- Keep TX and RX on the same Wi-Fi channel (
cfg.channel).