Hi everyone,
I am working on a low-power wireless sensor node for my engineering degree thesis using the nRF7002 DK and nRF Connect SDK v3.4.2 (Zephyr v4.4.2). The application periodically sends a four-byte voltage measurement via UDP and suspends Wi-Fi between acquisitions.
I encountered a problem when trying to suspend the nRF7002 immediately after send(): although the socket call returned successfully, the datagram was not always received by the remote host. A fixed delay of approximately 1.5 seconds helped, but it kept the radio powered for an arbitrary amount of time.
I wanted to wait for the actual TX completion notification from the nRF7002 rather than implement an application-level ACK or modify the UDP server. I could not find a ready-to-use socket-level solution for this specific use case in the material I consulted, so I experimented with the FMAC driver.
Approach
The Nordic Host–RPU interface defines NRF_WIFI_CMD_TX_BUFF_DONE, handled by nrf_wifi_fmac_tx_done_event_process() in:
modules/lib/nrf_wifi/fw_if/umac_if/src/system/tx.c
The event includes a TX descriptor, the number of packet status entries and per-packet status codes. Simply reacting to any completion is insufficient because EAPOL, DHCP, ARP and other network traffic generate completion events as well.
My prototype identifies the outgoing IPv4 UDP datagram by destination port in tx_cmd_prep_callbk_fn(), before the buffer-mapping operation, and stores its descriptor and frame index. In the TX DONE handler, it checks and clears this association before tx_done_process() can reuse the descriptor. Once the original TX processing has completed and the TX lock has been released, it calls an application function:
extern void wifi_udp_tx_completed(int result);
The application owns the semaphore:
K_SEM_DEFINE(wifi_tx_done, 0, 1);
int wifi_tx_result = -1;
void wifi_udp_tx_completed(int result)
{
wifi_tx_result = result;
k_sem_give(&wifi_tx_done);
}
Before calling send(), the application resets the semaphore. It then waits for the matching completion event with a bounded timeout, checks the status and suspends Wi-Fi. No fixed post-send delay or server-side ACK is needed for this successful path.
I initially tried calling k_sem_give() directly in tx.c, but adding zephyr/kernel.h caused a pristine-build failure involving the generated zephyr/syscall_list.h header. Moving synchronization into the application callback resolved that build issue in my setup.
Preliminary results
The serial trace shows the expected matching completion:
*** OUR UDP - Desc: 1 | Frame: 0 ***
*** OUR UDP TX DONE - Status: 0 ***
UDP transmission completed!
With the fixed delay removed, I observed four out of four UDP datagrams at the receiving host using tcpdump. One log-to-log interval between the send announcement and interface-down notification was approximately 122 ms, compared with 1.827 s in an earlier fixed-delay cycle. Representative PPK2 captures also showed a shorter radio-on interval (9.24 s versus 8.49 s). These are preliminary individual observations, not yet a controlled benchmark.
I understand that a firmware TX completion status is not an end-to-end UDP delivery guarantee. This prototype is also currently specific to a single device and one monitored datagram per cycle. More work is required for aggregation, timeout races, driver teardown and moving blocking application operations out of the system workqueue.
I would be interested in feedback from the Nordic team and the community:
- Is there a supported API for obtaining the completion status of an ordinary socket-originated Wi-Fi transmission without modifying the FMAC driver?
- Are there additional driver or firmware constraints to consider before suspending Wi-Fi after a successful TX DONE?
- Is an optional TX completion callback at the Zephyr integration layer a reasonable approach for a more general implementation?
I hope this approach is useful to others building low-duty-cycle Wi-Fi sensor nodes. I can share the version-specific driver changes and the complete technical explanation for reproduction.