RF24Mesh - Automated Networking for nrf24L01 radios v2.0.0
TMRh20 2020 - A user friendly mesh overlay for sensor neworks using RF24Network
|
#include <RF24Mesh.h>
Classes | |
struct | addrListStruct |
A struct for storing a nodeID and an address in a single element of the ESBMesh::addrList array. More... | |
Public Member Functions | |
RF24Mesh | |
The mesh library and class documentation is currently in active development and usage may change. | |
ESBMesh (radio_t &_radio, network_t &_network) | |
bool | begin (uint8_t channel=MESH_DEFAULT_CHANNEL, rf24_datarate_e data_rate=RF24_1MBPS, uint32_t timeout=MESH_RENEWAL_TIMEOUT) |
uint8_t | update () |
bool | write (const void *data, uint8_t msg_type, size_t size, uint8_t nodeID=0) |
void | setNodeID (uint8_t nodeID) |
uint16_t | renewAddress (uint32_t timeout=MESH_RENEWAL_TIMEOUT) |
Reconnect to the mesh and renew the current RF24Network address. | |
void | DHCP () |
Deprecated | |
Methods provided for backwards compatibility with old/testing code. | |
void | setStaticAddress (uint8_t nodeID, uint16_t address) |
Public Attributes | |
uint8_t | _nodeID |
Address list struct | |
helping members for managing the list of assigned addresses
| |
addrListStruct * | addrList |
A array of addrListStruct elements for assigned addresses. | |
uint8_t | addrListTop |
The number of entries in the addrListStruct of assigned addresses. | |
Advanced Operation | |
For advanced configuration and usage of the mesh | |
uint16_t | mesh_address |
int16_t | getNodeID (uint16_t address=MESH_BLANK_ID) |
bool | checkConnection () |
bool | releaseAddress () |
int16_t | getAddress (uint8_t nodeID) |
Convert a nodeID into an RF24Network address. | |
bool | write (uint16_t to_node, const void *data, uint8_t msg_type, size_t size) |
Write to a specific node by RF24Network address. | |
void | setChannel (uint8_t _channel) |
void | setChild (bool allow) |
void | setCallback (void(*meshCallback)(void)) |
void | setAddress (uint8_t nodeID, uint16_t address, bool searchBy=false) |
void | saveDHCP () |
void | loadDHCP () |
network_t | The network object's type. Defaults to RF24Network 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. |
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. |
Definition at line 71 of file RF24Mesh.h.
ESBMesh< network_t, radio_t >::ESBMesh | ( | radio_t & | _radio, |
network_t & | _network | ||
) |
Construct the mesh.
v2.0 supports a backward compatible constructor:
_radio | The underlying radio driver instance |
_network | The underlying network instance |
Definition at line 14 of file RF24Mesh.cpp.
bool ESBMesh< network_t, radio_t >::begin | ( | uint8_t | channel = MESH_DEFAULT_CHANNEL , |
rf24_datarate_e | data_rate = RF24_1MBPS , |
||
uint32_t | timeout = MESH_RENEWAL_TIMEOUT |
||
) |
Call this in setup() to configure the mesh and request an address.
This may take a few moments to complete.
The following parameters are optional:
channel | The radio channel (0 - 125). Default is 97. |
data_rate | The data rate (RF24_250KBPS, RF24_1MBPS, RF24_2MBPS). Default is RF24_1MBPS. |
timeout | How long to attempt address renewal in milliseconds. Default is 7500. |
Definition at line 26 of file RF24Mesh.cpp.
uint8_t ESBMesh< network_t, radio_t >::update |
Very similar to network.update(), it needs to be called regularly to keep the network and the mesh going.
NO_MASTER
Definition at line 63 of file RF24Mesh.cpp.
bool ESBMesh< network_t, radio_t >::write | ( | const void * | data, |
uint8_t | msg_type, | ||
size_t | size, | ||
uint8_t | nodeID = 0 |
||
) |
Automatically construct a header and send a payload. Very similar to the standard network.write() function, which can be used directly.
data | Send any type of data of any length (maximum length determined by RF24Network layer). |
msg_type | The user-defined (1 - 127) message header_type to send. Used to distinguish between different types of data being transmitted. |
size | The size of the data being sent |
nodeID | Optional: The nodeID of the recipient if not sending to master. |
Definition at line 118 of file RF24Mesh.cpp.
void ESBMesh< network_t, radio_t >::setNodeID | ( | uint8_t | nodeID | ) |
Set a unique nodeID for this node.
This needs to be called before ESBMesh::begin(). The parameter value passed can be fetched via serial connection, EEPROM, etc when configuring a large number of nodes.
nodeID | Can be any unique value ranging from 1 to 255 (reserving 0 for the master node). |
Definition at line 416 of file RF24Mesh.cpp.
uint16_t ESBMesh< network_t, radio_t >::renewAddress | ( | uint32_t | timeout = MESH_RENEWAL_TIMEOUT | ) |
Reconnect to the mesh and renew the current RF24Network address.
This is used to re-establish a connection to the mesh network if physical location of a node or surrounding nodes has changed (or a routing node becomes unavailable).
timeout | How long to attempt address renewal in milliseconds. Default is 7500 |
Definition at line 283 of file RF24Mesh.cpp.
void ESBMesh< network_t, radio_t >::DHCP |
This is only to be used on the master node because it manages allocation of network addresses for any requesting (non-master) node's ID, similar to DHCP.
Definition at line 510 of file RF24Mesh.cpp.
int16_t ESBMesh< network_t, radio_t >::getNodeID | ( | uint16_t | address = MESH_BLANK_ID | ) |
Convert an RF24Network address into a nodeId.
address | If no address is provided, returns the local nodeID, otherwise a lookup request is sent to the master node |
Definition at line 211 of file RF24Mesh.cpp.
bool ESBMesh< network_t, radio_t >::checkConnection |
Tests connectivity of this node to the mesh.
Definition at line 159 of file RF24Mesh.cpp.
bool ESBMesh< network_t, radio_t >::releaseAddress |
Releases the currently assigned address lease. Useful for nodes that will be sleeping etc.
Definition at line 268 of file RF24Mesh.cpp.
int16_t ESBMesh< network_t, radio_t >::getAddress | ( | uint8_t | nodeID | ) |
Convert a nodeID into an RF24Network address.
Results in a lookup request being sent to the master node.
nodeID | The unique identifier of the node in the range [1, 255]. |
Definition at line 173 of file RF24Mesh.cpp.
bool ESBMesh< network_t, radio_t >::write | ( | uint16_t | to_node, |
const void * | data, | ||
uint8_t | msg_type, | ||
size_t | size | ||
) |
Write to a specific node by RF24Network address.
Definition at line 107 of file RF24Mesh.cpp.
void ESBMesh< network_t, radio_t >::setChannel | ( | uint8_t | _channel | ) |
Change the active radio channel after the mesh has been started.
_channel | The value passed to RF24::setChannel() |
Definition at line 141 of file RF24Mesh.cpp.
void ESBMesh< network_t, radio_t >::setChild | ( | bool | allow | ) |
Allow child nodes to discover and attach to this node.
allow | True to allow children, False to prevent children from attaching automatically. |
Definition at line 151 of file RF24Mesh.cpp.
void ESBMesh< network_t, radio_t >::setCallback | ( | void(*)(void) | meshCallback | ) |
RF24Mesh ID and Address lookups as well as address renewal can take some time. Set a callback function to enable additional processing while the mesh is working
meshCallback | The name of a function to call. This function should consume no required input parameters. |
Definition at line 601 of file RF24Mesh.cpp.
void ESBMesh< network_t, radio_t >::setAddress | ( | uint8_t | nodeID, |
uint16_t | address, | ||
bool | searchBy = false |
||
) |
Set or change a nodeID : node address (key : value) pair manually. This function is for use on the master node only.
nodeID | The nodeID to assign |
address | The octal RF24Network address to assign |
searchBy | Optional parameter. Default is search by nodeID and set the address. True allows searching by address and setting nodeID. |
Definition at line 433 of file RF24Mesh.cpp.
void ESBMesh< network_t, radio_t >::saveDHCP |
Save the addrList to a binary file named "dhcplist.txt".
Definition at line 495 of file RF24Mesh.cpp.
void ESBMesh< network_t, radio_t >::loadDHCP |
Load the addrList from a binary file named "dhcplist.txt".
Definition at line 471 of file RF24Mesh.cpp.
void ESBMesh< network_t, radio_t >::setStaticAddress | ( | uint8_t | nodeID, |
uint16_t | address | ||
) |
Definition at line 425 of file RF24Mesh.cpp.
uint16_t ESBMesh< network_t, radio_t >::mesh_address |
The assigned RF24Network (Octal) address of this node
Definition at line 208 of file RF24Mesh.h.
uint8_t ESBMesh< network_t, radio_t >::_nodeID |
The unique identifying number used to differentiate mesh nodes' from their assigned network address. Ideally, this is set before calling begin() or renewAddress(). It is up to the network administrator to make sure that this number is unique to each mesh/network node.
This nodeID number is typically in the range [0, 255], but remember that 0
is reserved for the master node. Other external systems may reserve other node ID numbers, for instance RF24Gateway/RF24Ethernet reserves the node ID number 1
in addition to the master node ID 0
.
Definition at line 312 of file RF24Mesh.h.
addrListStruct* ESBMesh< network_t, radio_t >::addrList |
A array of addrListStruct elements for assigned addresses.
Definition at line 341 of file RF24Mesh.h.
uint8_t ESBMesh< network_t, radio_t >::addrListTop |
The number of entries in the addrListStruct of assigned addresses.
Definition at line 343 of file RF24Mesh.h.