Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enhance checkConnection() function #240

Merged
merged 4 commits into from
Jun 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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; // Address not found in list or is default
case -1: continue; // Write failed or timed out
case 0: return false; // This is a master node
default:
if ((uint16_t)result == mesh_address) { // Successful address lookup if result == RF24Network address
return true;
}
break;
}
}
return true;
return false;
}

/*****************************************************/
Expand Down
10 changes: 10 additions & 0 deletions RF24Mesh_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,16 @@
#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