RF24Mesh - Automated Networking for nrf24L01 & nrf52x radios v2.0.2
2024 - A user friendly mesh overlay for sensor neworks using RF24Network
Loading...
Searching...
No Matches
RF24Mesh.h
Go to the documentation of this file.
1
8#ifndef __RF24MESH_H__
9#define __RF24MESH_H__
10
11#include <stdio.h>
12#include <stdlib.h>
13
21// Network ACK types
22// None defined
23
24// No Network ACK types
25#define MESH_ADDR_LOOKUP 196
26#define MESH_ADDR_RELEASE 197
27#define MESH_ID_LOOKUP 198
28
29#define MESH_BLANK_ID 65535
30
31#if defined(__AVR_ATtiny85__) || defined(__AVR_ATtiny84__)
32 #define RF24_TINY
33#endif
34
35#include "RF24Mesh_config.h"
36
37#if defined(__linux) && !defined(__ARDUINO_X86__) && !defined(USE_RF24_LIB_SRC)
38 #include <RF24/RF24.h>
39 #include <RF24Network/RF24Network.h>
40 #define RF24_LINUX
41#else
42 #include <RF24.h>
43 #include <RF24Network.h>
44 #if defined(ARDUINO_ARCH_NRF52) || defined(ARDUINO_ARCH_NRF52840)
45 #include <nrf_to_nrf.h>
46 #endif
47#endif
48
49#include <stddef.h>
50#include <stdint.h>
51
52class RF24;
53#if defined(ARDUINO_ARCH_NRF52) || defined(ARDUINO_ARCH_NRF52840) || defined(ARDUINO_ARCH_NRF52833)
54class nrf_to_nrf;
55#endif
56
57template<class radio_t>
59
70template<class network_t = ESBNetwork<RF24>, class radio_t = RF24>
72{
80public:
100 ESBMesh(radio_t& _radio, network_t& _network);
101
113 bool begin(uint8_t channel = MESH_DEFAULT_CHANNEL, rf24_datarate_e data_rate = RF24_1MBPS, uint32_t timeout = MESH_RENEWAL_TIMEOUT);
114
119 uint8_t update();
120
135 bool write(const void* data, uint8_t msg_type, size_t size, uint8_t nodeID = 0);
136
145 void setNodeID(uint8_t nodeID);
146
160 uint16_t renewAddress(uint32_t timeout = MESH_RENEWAL_TIMEOUT);
161
162#if !defined(MESH_NOMASTER)
170 void DHCP();
171
172#endif
173
188 int16_t getNodeID(uint16_t address = MESH_BLANK_ID);
189
204 bool checkConnection();
205
211 bool releaseAddress();
212
217 uint16_t mesh_address;
218
228 int16_t getAddress(uint8_t nodeID);
229
231 bool write(uint16_t to_node, const void* data, uint8_t msg_type, size_t size);
232
237 void setChannel(uint8_t _channel);
238
243 void setChild(bool allow);
244
258 void setCallback(void (*meshCallback)(void));
259
260#define MESH_CALLBACK \
261 if (meshCallback) meshCallback();
262
283 void setAddress(uint8_t nodeID, uint16_t address, bool searchBy = false);
284
285#if !defined(MESH_NOMASTER)
290 void saveDHCP();
291
296 void loadDHCP();
297
306 void setStaticAddress(uint8_t nodeID, uint16_t address);
307
308#endif // !defined(MESH_NOMASTER)
321 uint8_t _nodeID;
322
323#if !defined(MESH_NOMASTER)
330 typedef struct
331 {
333 uint8_t nodeID;
335 uint16_t address;
337
345 // Pointer used for dynamic memory allocation of address list
352 uint8_t addrListTop;
353
364 bool releaseAddress(uint16_t address);
365#endif
368private:
369 radio_t& radio;
370 network_t& network;
371
373 void (*meshCallback)(void);
374
376 bool requestAddress(uint8_t level);
377
378#if !defined(MESH_NOMASTER)
380 bool doDHCP;
382 bool addrMemAllocated;
383#endif
384
386 void beginDefault();
388 bool meshStarted;
390 uint8_t getLevel(uint16_t address);
391};
392
406#if defined(ARDUINO_ARCH_NRF52) || defined(ARDUINO_ARCH_NRF52840) || defined(ARDUINO_ARCH_NRF52833)
407typedef ESBMesh<ESBNetwork<nrf_to_nrf>, nrf_to_nrf> RF52Mesh;
408#endif
409
481#endif // define __RF24MESH_H__
ESBMesh< ESBNetwork< RF24 >, RF24 > RF24Mesh
Definition RF24Mesh.h:405
#define MESH_BLANK_ID
Definition RF24Mesh.h:29
#define MESH_DEFAULT_CHANNEL
Radio channel to operate on 1-127.
#define MESH_RENEWAL_TIMEOUT
How long to attempt address renewal in milliseconds.
int16_t getNodeID(uint16_t address=MESH_BLANK_ID)
Definition RF24Mesh.cpp:234
void setStaticAddress(uint8_t nodeID, uint16_t address)
Definition RF24Mesh.cpp:465
void loadDHCP()
Definition RF24Mesh.cpp:511
uint16_t renewAddress(uint32_t timeout=MESH_RENEWAL_TIMEOUT)
Reconnect to the mesh and renew the current RF24Network address.
Definition RF24Mesh.cpp:322
void setChild(bool allow)
Definition RF24Mesh.cpp:147
bool checkConnection()
Definition RF24Mesh.cpp:155
bool begin(uint8_t channel=MESH_DEFAULT_CHANNEL, rf24_datarate_e data_rate=RF24_1MBPS, uint32_t timeout=MESH_RENEWAL_TIMEOUT)
Definition RF24Mesh.cpp:26
void DHCP()
Definition RF24Mesh.cpp:550
bool releaseAddress()
Definition RF24Mesh.cpp:291
void saveDHCP()
Definition RF24Mesh.cpp:535
void setCallback(void(*meshCallback)(void))
Definition RF24Mesh.cpp:641
uint8_t update()
Definition RF24Mesh.cpp:63
uint8_t addrListTop
The number of entries in the addrListStruct of assigned addresses.
Definition RF24Mesh.h:352
ESBMesh(radio_t &_radio, network_t &_network)
Definition RF24Mesh.cpp:14
addrListStruct * addrList
A array of addrListStruct elements for assigned addresses.
Definition RF24Mesh.h:350
void setNodeID(uint8_t nodeID)
Definition RF24Mesh.cpp:456
bool write(const void *data, uint8_t msg_type, size_t size, uint8_t nodeID=0)
Definition RF24Mesh.cpp:114
void setChannel(uint8_t _channel)
Definition RF24Mesh.cpp:137
void setAddress(uint8_t nodeID, uint16_t address, bool searchBy=false)
Definition RF24Mesh.cpp:473
uint16_t mesh_address
Definition RF24Mesh.h:217
int16_t getAddress(uint8_t nodeID)
Convert a nodeID into an RF24Network address.
Definition RF24Mesh.cpp:196
A struct for storing a nodeID and an address in a single element of the ESBMesh::addrList array.
Definition RF24Mesh.h:331
uint8_t nodeID
The nodeID of an network node (child)
Definition RF24Mesh.h:333
uint16_t address
The logical address of an network node (child)
Definition RF24Mesh.h:335