Skip to content

Commit

Permalink
Modify checkConnection()
Browse files Browse the repository at this point in the history
- Define MESH_CONNECTION_CHECK_ATTEMPTS
- Return from checkConnection() if -2 received, retry if -1, success if address matches, fail otherwise
  • Loading branch information
TMRh20 committed Jun 16, 2024
1 parent 8f030b4 commit 63d451c
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 4 deletions.
17 changes: 13 additions & 4 deletions RF24Mesh.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -159,12 +159,21 @@ template<class network_t, class radio_t>
bool ESBMesh<network_t, radio_t>::checkConnection()
{
// getAddress() doesn't use auto-ack; do a double-check to manually retry 1 more time
if (getAddress(_nodeID) < 1) {
if (getAddress(_nodeID) < 1) {
return false;
for (uint8_t i = 0; i < MESH_CONNECTION_CHECK_ATTEMPTS; i++) {

int16_t result = getAddress(_nodeID);
switch (result) {
case -2: return false; break; // Address not found in list or is default
case -1: continue; break; // Write failed or timed out
case 0: return false; break; // This is a master node
default:
if ((uint16_t)result == mesh_address) {
return true;
}
break; // Successful address lookup if result == RF24Network address
}
}
return true;
return false;
}

/*****************************************************/
Expand Down
11 changes: 11 additions & 0 deletions RF24Mesh_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,17 @@
#define MESH_MEM_ALLOC_SIZE 10
#endif // MESH_MEM_ALLOC_SIZE

/**
* @brief Number of attempts to verify a connection
*
* On child nodes, when calling `mesh.checkConnection();`, configure how many attempts will be made to contact the master node to verify connectivity
* Raising this number can result in a more stable mesh, since nodes can more easily verify that a connection is active
*/

#ifndef MESH_CONNECTION_CHECK_ATTEMPTS
#define MESH_CONNECTION_CHECK_ATTEMPTS 3
#endif

/**************************/
/*** Debug ***/
//#define RF24MESH_DEBUG_MINIMAL /** Uncomment for the Master Node to print out address assignments as they are assigned */
Expand Down

0 comments on commit 63d451c

Please sign in to comment.