Optimized RF24Network Layer v2.0.2
2024 - Optimized RF24 Network Layer for NRF24L01 & NRF52x radios
|
#include <RF24Network.h>
Public Member Functions | |
Primary Interface | |
These are the main methods you need to operate the network | |
ESBNetwork (radio_t &_radio) | |
void | begin (uint16_t _node_address) |
uint8_t | update (void) |
bool | available (void) |
uint16_t | peek (RF24NetworkHeader &header) |
void | peek (RF24NetworkHeader &header, void *message, uint16_t maxlen=MAX_PAYLOAD_SIZE) |
uint16_t | read (RF24NetworkHeader &header, void *message, uint16_t maxlen=MAX_PAYLOAD_SIZE) |
bool | write (RF24NetworkHeader &header, const void *message, uint16_t len) |
Advanced Operation | |
For advanced operation of the network | |
void | failures (uint32_t *_fails, uint32_t *_ok) |
bool | multicast (RF24NetworkHeader &header, const void *message, uint16_t len, uint8_t level=7) |
bool | write (RF24NetworkHeader &header, const void *message, uint16_t len, uint16_t writeDirect) |
bool | sleepNode (unsigned int cycles, int interruptPin, uint8_t INTERRUPT_MODE=0) |
uint16_t | parent () const |
uint16_t | addressOfPipe (uint16_t node, uint8_t pipeNo) |
bool | is_valid_address (uint16_t node) |
Deprecated | |
Maintained for backwards compatibility | |
void | begin (uint8_t _channel, uint16_t _node_address) |
Advanced Configuration | |
For advanced configuration of the network | |
bool | multicastRelay |
uint32_t | txTimeout |
Network timeout value. | |
uint16_t | routeTimeout |
Timeout for routed payloads. | |
void | multicastLevel (uint8_t level) |
void | setup_watchdog (uint8_t prescalar) |
External Applications/Systems | |
Interface for External Applications and Systems ( RF24Mesh, RF24Ethernet ) | |
uint8_t | frame_buffer [MAX_FRAME_SIZE] |
The raw system frame buffer. | |
std::queue< RF24NetworkFrame > | external_queue |
RF24NetworkFrame * | frag_ptr |
bool | returnSysMsgs |
uint8_t | networkFlags |
uint8_t | _multicast_level |
uint16_t | node_address |
2014-2021 - Optimized Network Layer for RF24 Radios
This class implements an OSI Network Layer using nRF24L01(+) radios driven by RF24 library.
radio_t | The radio object's type. Defaults to RF24 for legacy behavior. This new abstraction is really meant for using the nRF52840 SoC as a drop-in replacement for the nRF24L01 radio. For more detail, see the nrf_to_nrf Arduino library. |
ESBNetwork< radio_t >::ESBNetwork | ( | radio_t & | _radio | ) |
Construct the network
v2.0 supports a backward compatible constructor:
_radio | The underlying radio driver instance |
|
inline |
Bring up the network using the current radio frequency/channel. Calling begin brings up the network, and configures the address, which designates the location of the node within RF24Network topology.
04444
is reserved for RF24Mesh usage (when a mesh node is connecting to the network). RF24::begin()
to initialize the radio properly.Example 1: Begin on current radio channel with address 0 (master node)
Example 2: Begin with address 01 (child of master)
Example 3: Begin with address 011 (child of 01, grandchild of master)
_node_address | The logical address of this node. |
uint8_t ESBNetwork< radio_t >::update | ( | void | ) |
Main layer loop
This function must be called regularly to keep the layer going. This is where payloads are re-routed, received, and all the action happens.
bool ESBNetwork< radio_t >::available | ( | void | ) |
Test whether there is a message available for this node
uint16_t ESBNetwork< radio_t >::peek | ( | RF24NetworkHeader & | header | ) |
Read the next available header
Reads the next available header without advancing to the next incoming message. Useful for doing a switch on the message type.
[out] | header | The RF24NetworkHeader (envelope) of the next message. If there is no message available, the referenced header object is not touched |
void ESBNetwork< radio_t >::peek | ( | RF24NetworkHeader & | header, |
void * | message, | ||
uint16_t | maxlen = MAX_PAYLOAD_SIZE ) |
Read the next available payload
Reads the next available payload without advancing to the next incoming message. Useful for doing a transparent packet manipulation layer on top of RF24Network.
[out] | header | The RF24NetworkHeader (envelope) of this message |
[out] | message | Pointer to memory where the message should be placed |
maxlen | Amount of bytes to copy to message . If this parameter is left unspecified, the entire length of the message is fetched. Hint: Use peek(RF24NetworkHeader) to get the length of next available message in the queue. |
uint16_t ESBNetwork< radio_t >::read | ( | RF24NetworkHeader & | header, |
void * | message, | ||
uint16_t | maxlen = MAX_PAYLOAD_SIZE ) |
Read a message
[out] | header | The RF24NetworkHeader (envelope) of this message |
[out] | message | Pointer to memory where the message should be placed |
maxlen | The largest message size which can be held in message . If this parameter is left unspecified, the entire length of the message is fetched. Hint: Use peek(RF24NetworkHeader &) to get the length of next available message in the queue. |
message
bool ESBNetwork< radio_t >::write | ( | RF24NetworkHeader & | header, |
const void * | message, | ||
uint16_t | len ) |
Send a message
[in,out] | header | The header (envelope) of this message. The critical thing to fill in is the to_node field so we know where to send the message. It is then updated with the details of the actual header sent. |
message | Pointer to memory where the message is located | |
len | The size of the message |
void ESBNetwork< radio_t >::multicastLevel | ( | uint8_t | level | ) |
By default, multicast addresses are divided into 5 network levels:
Notice "n" (used in the list above) stands for an octal digit in range [0, 5]
This optional function is used to override the default level set when a node's logical address changes, and it can be used to create custom multicast groups that all share a single address.
level | Levels 0 to 4 are available. All nodes at the same level will receive the same messages if in range. Messages will be routed in order of level, low to high, by default. |
void ESBNetwork< radio_t >::setup_watchdog | ( | uint8_t | prescalar | ) |
Set up the watchdog timer for sleep mode using the number 0 through 10 to represent the following time periods:
wdt_16ms = 0, wdt_32ms, wdt_64ms, wdt_128ms, wdt_250ms, wdt_500ms, wdt_1s, wdt_2s, wdt_4s, wdt_8s
prescalar | The WDT prescaler to define how often the node will wake up. When defining sleep mode cycles, this time period is 1 cycle. |
void ESBNetwork< radio_t >::failures | ( | uint32_t * | _fails, |
uint32_t * | _ok ) |
Return the number of failures and successes for all transmitted payloads, routed or sent directly
#define ENABLE_NETWORK_STATS
in RF24Network_config.hbool ESBNetwork< radio_t >::multicast | ( | RF24NetworkHeader & | header, |
const void * | message, | ||
uint16_t | len, | ||
uint8_t | level = 7 ) |
Send a multicast message to multiple nodes at once Allows messages to be rapidly broadcast through the network
Multicasting is arranged in levels, with all nodes on the same level listening to the same address Levels are assigned by network level ie: nodes 01-05: Level 1, nodes 011-055: Level 2
header | reference to the RF24NetworkHeader object used for this message |
message | Pointer to memory where the message is located |
len | The size of the message |
level | Multicast level to broadcast to. If this parameter is unspecified, then the node's current multicastLevel() is used. |
bool ESBNetwork< radio_t >::write | ( | RF24NetworkHeader & | header, |
const void * | message, | ||
uint16_t | len, | ||
uint16_t | writeDirect ) |
Writes a direct (unicast) payload. This allows routing or sending messages outside of the usual routing paths. The same as write, but a physical address is specified as the last option. The payload will be written to the physical address, and routed as necessary by the recipient.
bool ESBNetwork< radio_t >::sleepNode | ( | unsigned int | cycles, |
int | interruptPin, | ||
uint8_t | INTERRUPT_MODE = 0 ) |
Sleep this node - For AVR devices only
#define ENABLE_SLEEP_MODE
in RF24Network_config.h setup()
if using sleep mode. This function will sleep the node, with the radio still active in receive mode. See setup_watchdog().The node can be awoken in two ways, both of which can be enabled simultaneously:
cycles | The node will sleep in cycles of 1s. Using 2 will sleep 2 WDT cycles, 3 sleeps 3WDT cycles... | ||||||||||
interruptPin | The interrupt number to use (0, 1) for pins 2 and 3 on Uno & Nano. More available on Mega etc. Setting this parameter to 255 will disable interrupt wake-ups. | ||||||||||
INTERRUPT_MODE | an identifying number to indicate what type of state for which the interrupt_pin will be used to wake up the radio.
|
uint16_t ESBNetwork< radio_t >::parent | ( | ) | const |
This node's parent address
uint16_t ESBNetwork< radio_t >::addressOfPipe | ( | uint16_t | node, |
uint8_t | pipeNo ) |
Provided a node address and a pipe number, will return the RF24Network address of that child pipe for that node.
bool ESBNetwork< radio_t >::is_valid_address | ( | uint16_t | node | ) |
Validate a network address as a proper logical address
node | The specified logical address of a network node. |
node
address is a valid network address, otherwise false. 0100
as it is the reserved NETWORK_MULTICAST_ADDRESS used for multicasted messages. void ESBNetwork< radio_t >::begin | ( | uint8_t | _channel, |
uint16_t | _node_address ) |
Bring up the network on a specific radio frequency/channel.
RF24::setChannel()
to configure the radio channel. Use ESBNetwork::begin(uint16_t _node_address) to set the node address.Example 1: Begin on channel 90 with address 0 (master node)
Example 2: Begin on channel 90 with address 01 (child of master)
Example 3: Begin on channel 90 with address 011 (child of 01, grandchild of master)
_channel | The RF channel to operate on. |
_node_address | The logical address of this node. |
bool ESBNetwork< radio_t >::multicastRelay |
Enabling this will allow this node to automatically forward received multicast frames to the next highest multicast level. Forwarded frames will also be enqueued on the forwarding node as a received frame.
This is disabled by default.
uint32_t ESBNetwork< radio_t >::txTimeout |
Network timeout value.
Sets the timeout period for individual payloads in milliseconds at staggered intervals. Payloads will be retried automatically until success or timeout. Set to 0 to use the normal auto retry period defined by radio.setRetries()
.
uint16_t ESBNetwork< radio_t >::routeTimeout |
Timeout for routed payloads.
This only affects payloads that are routed through one or more nodes. This specifies how long to wait for an ack from across the network. Radios sending directly to their parent or children nodes do not utilize this value.
uint8_t ESBNetwork< radio_t >::frame_buffer[MAX_FRAME_SIZE] |
The raw system frame buffer.
This member can be accessed to retrieve the latest received data just after it is enqueued. This buffer is also used for outgoing data.
std::queue<RF24NetworkFrame> ESBNetwork< radio_t >::external_queue |
Linux platforms only
Data with a header type of EXTERNAL_DATA_TYPE will be loaded into a separate queue. The data can be accessed as follows:
RF24NetworkFrame* ESBNetwork< radio_t >::frag_ptr |
ARDUINO platforms only
The frag_ptr
is only used with Arduino (not RPi/Linux) and is mainly used for external data systems like RF24Ethernet. When a payload of type EXTERNAL_DATA_TYPE is received, and returned from update(), the frag_ptr
will always point to the starting memory location of the received frame. This is used by external data systems (RF24Ethernet) to immediately copy the received data to a buffer, without using the user-cache.
Linux devices (defined as RF24_LINUX
) currently cache all payload types, and do not utilize frag_ptr
.
bool ESBNetwork< radio_t >::returnSysMsgs |
Variable to determine whether update() will return after the radio buffers have been emptied (DEFAULT), or whether to return immediately when (most) system types are received.
As an example, this is used with RF24Mesh to catch and handle system messages without loading them into the user cache.
The following reserved/system message types are handled automatically, and not returned.
System Message Types (Not Returned) |
---|
NETWORK_ADDR_RESPONSE |
NETWORK_ACK |
NETWORK_PING |
NETWORK_POLL (With multicast enabled) |
NETWORK_REQ_ADDRESS |
uint8_t ESBNetwork< radio_t >::networkFlags |
Network Flags allow control of data flow
Incoming Blocking: If the network user-cache is full, lets radio cache fill up. Radio ACKs are not sent when radio internal cache is full. This behaviour may seem to result in more failed sends, but the payloads would have otherwise been dropped due to the cache being full.
FLAGS | Value | Description |
---|---|---|
FLAG_FAST_FRAG | 4 (bit 2 asserted) | INTERNAL: Replaces the fastFragTransfer variable, and allows for faster transfers between directly connected nodes. |
FLAG_NO_POLL | 8 (bit 3 asserted) | EXTERNAL/USER: Disables NETWORK_POLL responses on a node-by-node basis. |
networkFlags
byte are no longer used as they once were during experimental development.
|
protected |
The current node's network level (used for multicast TX/RX-ing).
|
protected |
Logical node address of this unit, typically in range [0, 2925] (that's [0, 05555] in octal).