Skip to content

Commit

Permalink
Adj timeout, fix address release
Browse files Browse the repository at this point in the history
- Add MESH_RENEWAL_TIMEOUT defined to RF24Mesh_config.h
- Increase default renewal timeout to 1 minute from 3 seconds
- Fix address release function per #41
  • Loading branch information
TMRh20 committed Oct 30, 2015
1 parent d49dea1 commit 7d0548c
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 8 deletions.
14 changes: 9 additions & 5 deletions RF24Mesh.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ RF24Mesh::RF24Mesh( RF24& _radio,RF24Network& _network ): radio(_radio),network(

/*****************************************************/

bool RF24Mesh::begin(uint8_t channel, rf24_datarate_e data_rate){
bool RF24Mesh::begin(uint8_t channel, rf24_datarate_e data_rate, uint32_t timeout){
radio.begin();
if(getNodeID()){ //Not master node
mesh_address = MESH_DEFAULT_ADDRESS;
Expand All @@ -29,7 +29,7 @@ bool RF24Mesh::begin(uint8_t channel, rf24_datarate_e data_rate){
radio.setDataRate(data_rate);
network.returnSysMsgs = 1;
if(getNodeID()){ //Not master node
if(!renewAddress()){
if(!renewAddress(timeout)){
return 0;
}
}else{
Expand Down Expand Up @@ -189,10 +189,14 @@ int RF24Mesh::getNodeID(uint16_t address){
bool RF24Mesh::releaseAddress(){

if(mesh_address == MESH_DEFAULT_ADDRESS){ return 0; }
network.begin(MESH_DEFAULT_ADDRESS);
mesh_address=MESH_DEFAULT_ADDRESS;

RF24NetworkHeader header(00,MESH_ADDR_RELEASE);
return network.write(header,0,0);
if(network.write(header,0,0)){
network.begin(MESH_DEFAULT_ADDRESS);
mesh_address=MESH_DEFAULT_ADDRESS;
return 1;
}
return 0;
}

/*****************************************************/
Expand Down
4 changes: 2 additions & 2 deletions RF24Mesh.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ class RF24Mesh
* This may take a few moments to complete.
* The radio channel and data-rate can be specified optionally as well
*/
bool begin(uint8_t channel = MESH_DEFAULT_CHANNEL, rf24_datarate_e data_rate = RF24_1MBPS );
bool begin(uint8_t channel = MESH_DEFAULT_CHANNEL, rf24_datarate_e data_rate = RF24_1MBPS, uint32_t timeout=MESH_RENEWAL_TIMEOUT );

/**
* Very similar to network.update(), it needs to be called regularly to keep the network
Expand Down Expand Up @@ -151,7 +151,7 @@ class RF24Mesh
* @note Currently blocks until a connection is established and an address is received.
* @return Returns the newly assigned RF24Network address
*/
uint16_t renewAddress(uint32_t timeout=3000);
uint16_t renewAddress(uint32_t timeout=MESH_RENEWAL_TIMEOUT);

/**
* Releases the currently assigned address lease. Useful for nodes that will be sleeping etc.
Expand Down
1 change: 1 addition & 0 deletions RF24Mesh_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
/***Advanced User Config***/
#define MESH_WRITE_TIMEOUT 5550 /** How long mesh.write will retry failed payloads. */
#define MESH_DEFAULT_CHANNEL 97 /** Radio channel to operate on 1-127. This is normally modified by calling mesh.setChannel() */
#define MESH_RENEWAL_TIMEOUT 60000 /** How long to attempt address renewal */
/**************************/
/*** Debug ***/
//#define MESH_DEBUG_MINIMAL /** Uncomment for the Master Node to print out address assignments as they are assigned */
Expand Down
2 changes: 1 addition & 1 deletion library.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name=RF24Mesh
version=1.0
version=1.0.1
author=TMRh20
maintainer=TMRh20
sentence=A library for NRF24L01(+) devices mesh.
Expand Down

0 comments on commit 7d0548c

Please sign in to comment.