Skip to content

Commit

Permalink
mesh.checkConnection via parent not master
Browse files Browse the repository at this point in the history
- Adjust mesh.checkConnection function to verify connectivity with parent only. Leave old functionality in place with a #define
- Suggestions in place per @2bndy5
closes #249
  • Loading branch information
TMRh20 committed Jun 28, 2024
1 parent 3d26ba7 commit a2b8135
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 1 deletion.
20 changes: 19 additions & 1 deletion RF24Mesh.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,24 @@ void ESBMesh<network_t, radio_t>::setChild(bool allow)
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 (!nodeID) return false;
if (mesh_address == MESH_DEFAULT_ADDRESS) return false;

// Connection check via parent node
#if RF24MESH_CONN_CHECK_TYPE == RF24MESH_CONN_CHECK_PARENT
RF24NetworkHeader header;
header.to_node = network.parent();
header.type = NETWORK_PING;
for (uint8_t i = 0; i < MESH_CONNECTION_CHECK_ATTEMPTS; i++) {
if (network.write(header, 0, 0)) {
return true;
}
}
return false;

#else // Connection check via master node
// getAddress() doesn't use auto-ack; check connectivity multiple times
for (uint8_t i = 0; i < MESH_CONNECTION_CHECK_ATTEMPTS; i++) {

int16_t result = getAddress(_nodeID);
Expand All @@ -170,6 +187,7 @@ bool ESBMesh<network_t, radio_t>::checkConnection()
}
}
return false;
#endif
}

/*****************************************************/
Expand Down
17 changes: 17 additions & 0 deletions RF24Mesh_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,23 @@
#define MESH_CONNECTION_CHECK_ATTEMPTS 3
#endif

/**
* @brief How to verify a connection
*
* On child nodes, determine how they verify/check their connection periodically, or when writes start to fail via the `mesh.checkConnection();`
* function.
* Set RF24MESH_CONN_CHECK_TYPE to RF24MESH_CONN_CHECK_PARENT for the new behaviour of verifying connectivity only with their parent node
* Set RF24MESH_CONN_CHECK_TYPE to RF24MESH_CONN_CHECK_MASTER for the old behaviour of verifying connectivity with the master node
* The old behaviour typically results in more network congestion, more load on the master node, and less reliable networks,
* but can work well when radio conditions are good and/or when there are only a small number of nodes on the network and/or in close proximity
* to the master node.
*/
#define RF24MESH_CONN_CHECK_PARENT 1
#define RF24MESH_CONN_CHECK_MASTER 0
#define RF24MESH_CONN_CHECK_TYPE RF24MESH_CONN_CHECK_PARENT
// To use old behavior:
// #define RF24MESH_CONN_CHECK_TYPE RF24MESH_CONN_CHECK_MASTER

/**************************/
/*** 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 a2b8135

Please sign in to comment.