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

mesh.checkConnection via parent not master #250

Merged
merged 9 commits into from
Jun 30, 2024
Merged
Show file tree
Hide file tree
Changes from 6 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
2 changes: 2 additions & 0 deletions .github/workflows/build_arduino.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ on:
paths:
- ".github/workflows/build_arduino.yml"
- "examples/**"
- "RF24Mesh.*"
- "RF24Mesh_config.h"

push:
branches: [master, v1.x]
Expand Down
22 changes: 20 additions & 2 deletions RF24Mesh.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -154,8 +154,25 @@ 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
for (uint8_t i = 0; i < MESH_CONNECTION_CHECK_ATTEMPTS; i++) {

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);
switch (result) {
Expand All @@ -170,6 +187,7 @@ bool ESBMesh<network_t, radio_t>::checkConnection()
}
}
return false;
#endif
}

/*****************************************************/
Expand Down
4 changes: 3 additions & 1 deletion RF24Mesh.h
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,9 @@ class ESBMesh
/**
* Tests connectivity of this node to the mesh.
* @note If this function fails, address renewal should typically be done.
* @return 1 if connected, 0 if mesh not responding
* @return
2bndy5 marked this conversation as resolved.
Show resolved Hide resolved
* - True if connected.
* - False if not connected, mesh is not responding, or this node is the master node.
*/
bool checkConnection();

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

#define RF24MESH_CONN_CHECK_PARENT 1
#define RF24MESH_CONN_CHECK_MASTER 0
/**
* @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 `RF24Mesh::checkConnection();`
* function.
* Set RF24MESH_CONN_CHECK_TYPE to @ref RF24MESH_CONN_CHECK_PARENT for the new behaviour of verifying connectivity only with their parent node.
* Set RF24MESH_CONN_CHECK_TYPE to @ref 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 it 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.
*/
#ifndef RF24MESH_CONN_CHECK_TYPE
#define RF24MESH_CONN_CHECK_TYPE RF24MESH_CONN_CHECK_PARENT
// To use old behavior:
// #define RF24MESH_CONN_CHECK_TYPE RF24MESH_CONN_CHECK_MASTER
#endif

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