From 7d0548c9755380241b7fe3144e54d0cd0a844afa Mon Sep 17 00:00:00 2001 From: TMRh20 Date: Fri, 30 Oct 2015 12:26:59 -0600 Subject: [PATCH] Adj timeout, fix address release - 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 --- RF24Mesh.cpp | 14 +++++++++----- RF24Mesh.h | 4 ++-- RF24Mesh_config.h | 1 + library.properties | 2 +- 4 files changed, 13 insertions(+), 8 deletions(-) diff --git a/RF24Mesh.cpp b/RF24Mesh.cpp index 7167a8b..99f9017 100644 --- a/RF24Mesh.cpp +++ b/RF24Mesh.cpp @@ -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; @@ -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{ @@ -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; } /*****************************************************/ diff --git a/RF24Mesh.h b/RF24Mesh.h index 4eaf86c..a720612 100644 --- a/RF24Mesh.h +++ b/RF24Mesh.h @@ -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 @@ -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. diff --git a/RF24Mesh_config.h b/RF24Mesh_config.h index ca09448..f390875 100644 --- a/RF24Mesh_config.h +++ b/RF24Mesh_config.h @@ -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 */ diff --git a/library.properties b/library.properties index 819a563..d0e1670 100644 --- a/library.properties +++ b/library.properties @@ -1,5 +1,5 @@ name=RF24Mesh -version=1.0 +version=1.0.1 author=TMRh20 maintainer=TMRh20 sentence=A library for NRF24L01(+) devices mesh.