RF24Mesh  V1.0.3b
A user friendly mesh overlay for sensor networks using RF24Network and nRF24L01 radio modules
RF24Mesh.h
Go to the documentation of this file.
1 
2 
3 
4 
5 
6 
7 #ifndef __RF24MESH_H__
8 #define __RF24MESH_H__
9 
10 #include <stdio.h>
11 #include <stdlib.h>
12 
20 // Network ACK types
21 #define MESH_ADDR_CONFIRM 129
22 // No Network ACK types
23 #define MESH_ADDR_LOOKUP 196
24 #define MESH_ADDR_RELEASE 197
25 #define MESH_ID_LOOKUP 198
26 
27 #define MESH_BLANK_ID 65535
28 
35 #if defined (__AVR_ATtiny85__) || defined (__AVR_ATtiny84__)
36  #define RF24_TINY
37 #endif
38 
39 
40 #include "RF24Mesh_config.h"
41 
42 #if defined (__linux) && !defined(__ARDUINO_X86__)
43  #include <RF24/RF24.h>
44  #include <RF24Network/RF24Network.h>
45  #define RF24_LINUX
46 #else
47  #include <RF24.h>
48  #include <RF24Network.h>
49 #endif
50 
51  #include <stddef.h>
52  #include <stdint.h>
53 
54 
55 
56 class RF24;
57 class RF24Network;
58 
59 
60 class RF24Mesh
61 {
69 public:
70 
83  RF24Mesh( RF24& _radio,RF24Network& _network );
84 
96  bool begin(uint8_t channel = MESH_DEFAULT_CHANNEL, rf24_datarate_e data_rate = RF24_1MBPS, uint32_t timeout=MESH_RENEWAL_TIMEOUT );
97 
102  uint8_t update();
103 
118  bool write(const void* data, uint8_t msg_type, size_t size, uint8_t nodeID=0);
119 
127  void setNodeID(uint8_t nodeID);
128 
133  void DHCP();
134 
148  int16_t getNodeID(uint16_t address=MESH_BLANK_ID);
149 
156  bool checkConnection();
157 
169  uint16_t renewAddress(uint32_t timeout=MESH_RENEWAL_TIMEOUT);
170 
176  bool releaseAddress();
177 
182  uint16_t mesh_address;
183 
192  int16_t getAddress(uint8_t nodeID);
193 
198  bool write(uint16_t to_node, const void* data, uint8_t msg_type, size_t size );
199 
203  void setChannel(uint8_t _channel);
204 
209  void setChild(bool allow);
210 
224  void setAddress(char nodeID, uint16_t address);
225 
226  void saveDHCP();
227  void loadDHCP();
228 
239  uint8_t _nodeID;
240 
241 
242 #if !defined RF24TINY
243  typedef struct{
244  uint8_t nodeID;
245  uint16_t address;
247 
248  // Pointer used for dynamic memory allocation of address list
250  uint8_t addrListTop;
251 #endif
252 
263  void setStaticAddress(char nodeID, uint16_t address);
264 
265  private:
266  RF24& radio;
267  RF24Network& network;
268  bool findNodes(RF24NetworkHeader& header, uint8_t level, uint16_t *address);
269  bool requestAddress(uint8_t level);
270  bool waitForAvailable(uint32_t timeout);
271  bool doDHCP;
272  uint32_t lastSaveTime;
273  uint32_t lastFileSave;
274  uint8_t radio_channel;
275 
276 
277  };
278 
279  #endif
280 
281 
bool 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.
Definition: RF24Mesh.cpp:16
uint8_t _nodeID
Definition: RF24Mesh.h:239
int16_t getAddress(uint8_t nodeID)
Convert a nodeID into an RF24Network address.
Definition: RF24Mesh.cpp:139
RF24Mesh(RF24 &_radio, RF24Network &_network)
Construct the mesh:
Definition: RF24Mesh.cpp:11
bool releaseAddress()
Releases the currently assigned address lease.
Definition: RF24Mesh.cpp:198
int16_t getNodeID(uint16_t address=MESH_BLANK_ID)
Convert an RF24Network address into a nodeId.
Definition: RF24Mesh.cpp:168
#define MESH_RENEWAL_TIMEOUT
Definition: RF24Mesh_config.h:13
uint16_t mesh_address
The assigned RF24Network (Octal) address of this node.
Definition: RF24Mesh.h:182
#define MESH_DEFAULT_CHANNEL
Definition: RF24Mesh_config.h:12
bool 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.
Definition: RF24Mesh.cpp:89
void DHCP()
Only to be used on the master node.
Definition: RF24Mesh.cpp:474
bool checkConnection()
Tests connectivity of this node to the mesh.
Definition: RF24Mesh.cpp:118
Definition: RF24Mesh.h:60
void loadDHCP()
Definition: RF24Mesh.cpp:416
#define MESH_BLANK_ID
Definition: RF24Mesh.h:27
uint8_t update()
Very similar to network.update(), it needs to be called regularly to keep the network and the mesh go...
Definition: RF24Mesh.cpp:43
void setChannel(uint8_t _channel)
Change the active radio channel after the mesh has been started.
Definition: RF24Mesh.cpp:102
void saveDHCP()
Definition: RF24Mesh.cpp:442
uint8_t nodeID
NodeIDs and addresses are stored in the addrList array using this structure.
Definition: RF24Mesh.h:244
Definition: RF24Mesh.h:243
void setStaticAddress(char nodeID, uint16_t address)
Calls setAddress()
Definition: RF24Mesh.cpp:381
void setAddress(char nodeID, uint16_t address)
Set/change a nodeID/RF24Network Address pair manually on the master node.
Definition: RF24Mesh.cpp:387
addrListStruct * addrList
See the addrListStruct class reference.
Definition: RF24Mesh.h:249
uint8_t addrListTop
The number of entries in the assigned address list.
Definition: RF24Mesh.h:250
uint16_t renewAddress(uint32_t timeout=MESH_RENEWAL_TIMEOUT)
Reconnect to the mesh and renew the current RF24Network address.
Definition: RF24Mesh.cpp:213
void setNodeID(uint8_t nodeID)
Set a unique nodeID for this node.
Definition: RF24Mesh.cpp:375
void setChild(bool allow)
Allow child nodes to discover and attach to this node.
Definition: RF24Mesh.cpp:109
uint16_t address
NodeIDs and addresses are stored in the addrList array using this structure.
Definition: RF24Mesh.h:245