ProtoCore v1.0.16
Deterministic, zero-heap network stack for embedded targets
Loading...
Searching...
No Matches
Nrf24Gateway - a real nRF24L01+ radio bridged to the gateway

Layer: Foundation ยท Build flags: PROTOCORE_ENABLE_NRF24, PROTOCORE_ENABLE_GATEWAY

What this example teaches

A second radio driver plugged into the gateway - the cheap, ubiquitous Nordic nRF24L01+ 2.4 GHz module. It shows that a different bus shape drops into the same gateway: where the SX127x is plain register read/write, the nRF24 uses an SPI command protocol and a separate CE pin, so its nrf_bus carries an SPI transfer plus a CE callback.

nRF24 RX --SPI--> protocore_nrf24_recv() -> pipe + payload -> protocore_gateway_uplink(port, pipe, ...)
|
envelope + topic nrf24/0/<pipe>
|
northbound publish (MQTT/HTTP/WS)

The nRF24 does its own hardware addressing: a received frame's source is the pipe number it arrived on, so there is no in-payload header (no codec) - the pipe is the address handed to protocore_gateway_uplink(). Payloads are a static width (PROTOCORE_NRF24_PAYLOAD, default 32); a short send is zero-padded.

nrf_config cfg = {}; cfg.address = addr5; cfg.channel = 76; cfg.data_rate = 0; cfg.tx_power = 3;
uint8_t buf[PROTOCORE_NRF24_PAYLOAD]; uint8_t pipe;
int n = protocore_nrf24_recv(&bus, buf, sizeof(buf), &pipe); // -> a frame, or -1
protocore_gateway_uplink(0, pipe, buf, n, 0); // pipe = source address
#define PROTOCORE_NRF24_PAYLOAD
nRF24 fixed payload width in bytes (1..32; the chip's static payload size).
proto_bool protocore_gateway_uplink(uint8_t *work, uint8_t port_id, uint16_t src_addr, const uint8_t *payload, uint16_t len, int16_t rssi)
Bridge a received southbound frame northbound: envelope it and .
int protocore_nrf24_recv(uint8_t *work, const nrf_bus *bus, uint8_t *buf, uint8_t cap, uint8_t *pipe)
If a frame is waiting, copy it into buf and report the pipe it .
proto_bool protocore_nrf24_init(uint8_t *work, const nrf_bus *bus, const nrf_config *cfg)
Configure the nRF24L01+ and power it up (standby).
void protocore_nrf24_set_rx(uint8_t *work, const nrf_bus *bus)
Enter receive mode (PRX + CE high); then poll protocore_nrf24_recv().
Radio configuration applied by protocore_nrf24_init().
Definition nrf24.h:57
uint8_t data_rate
0 = 1 Mbps, 1 = 2 Mbps, 2 = 250 kbps.
Definition nrf24.h:60
uint8_t tx_power
power level 0..3 (-18, -12, -6, 0 dBm).
Definition nrf24.h:61
uint8_t channel
RF channel 0..125 (2400 + channel MHz).
Definition nrf24.h:59
const uint8_t * address
5-byte pipe-0 / TX address (RX and TX share it here).
Definition nrf24.h:58

Wiring (ESP32 <-> nRF24L01+)

nRF24 ESP32
SCK GPIO 18
MISO GPIO 19
MOSI GPIO 23
CSN GPIO 5
CE GPIO 4
VCC 3V3
GND GND

Change the PIN_* constants for your board (a 10 uF cap across VCC/GND helps the module's TX current spikes). It needs the module wired to actually receive - the SPI command protocol is host-tested in test/test_nrf24.

Build-flag note

The flags must reach the library build, so pass them as build flags:

pio ci --board=esp32dev --project-option="framework=arduino" \
--project-option="build_flags=-DPROTOCORE_ENABLE_NRF24=1 -DPROTOCORE_ENABLE_GATEWAY=1" \
--lib="." examples/Drivers/Nrf24Gateway/Nrf24Gateway.ino