Skip to content

Commit 7ca48f0

Browse files
TMRh202bndy5github-actions[bot]
committed
mesh.checkConnection via parent not master (#250)
* mesh.checkConnection via parent not master - 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 * Fix last commit - _nodeID not nodeID * review changes * trigger compile size reports for PRs Specifically for PRs that only change the lib src code and not examples. * doc review use doxygen references * [docs] clarify return value of checkConnection() * format RF24Mesh.h Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> * review supported CMake options also defaults RF24_DRIVER to SPIDEV (per nRF24/RF24#971) * add reference to new config macro in checkConnection() doc. --------- Co-authored-by: Brendan <2bndy5@gmail.com> Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
1 parent b419857 commit 7ca48f0

File tree

7 files changed

+81
-38
lines changed

7 files changed

+81
-38
lines changed

.github/workflows/build_arduino.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ on:
66
paths:
77
- ".github/workflows/build_arduino.yml"
88
- "examples/**"
9+
- "RF24Mesh.*"
10+
- "RF24Mesh_config.h"
911

1012
push:
1113
branches: [master, v1.x]

CMakeLists.txt

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -143,10 +143,9 @@ if(DEFINED MESH_WRITE_TIMEOUT)
143143
message(STATUS "MESH_WRITE_TIMEOUT set to ${MESH_WRITE_TIMEOUT}")
144144
target_compile_definitions(${LibTargetName} PUBLIC MESH_WRITE_TIMEOUT=${MESH_WRITE_TIMEOUT})
145145
endif()
146-
# conditionally disable interruot support (a pigpio specific feature)
147-
if("${LibPIGPIO}" STREQUAL "LibPIGPIO-NOTFOUND" OR DEFINED RF24_NO_INTERRUPT)
148-
message(STATUS "Disabling IRQ pin support")
149-
target_compile_definitions(${LibTargetName} PUBLIC RF24_NO_INTERRUPT)
146+
if(DEFINED RF24MESH_CONN_CHECK_TYPE)
147+
message(STATUS "RF24MESH_CONN_CHECK_TYPE set to ${RF24MESH_CONN_CHECK_TYPE}")
148+
target_compile_definitions(${LibTargetName} PUBLIC RF24MESH_CONN_CHECK_TYPE=${RF24MESH_CONN_CHECK_TYPE})
150149
endif()
151150

152151

RF24Mesh.cpp

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -146,8 +146,25 @@ void RF24Mesh::setChild(bool allow)
146146

147147
bool RF24Mesh::checkConnection()
148148
{
149-
// getAddress() doesn't use auto-ack; do a double-check to manually retry 1 more time
150-
for (uint8_t i = 0; i < MESH_CONNECTION_CHECK_ATTEMPTS; i++) {
149+
150+
if (!_nodeID) return false;
151+
if (mesh_address == MESH_DEFAULT_ADDRESS) return false;
152+
153+
// Connection check via parent node
154+
#if RF24MESH_CONN_CHECK_TYPE == RF24MESH_CONN_CHECK_PARENT
155+
RF24NetworkHeader header;
156+
header.to_node = network.parent();
157+
header.type = NETWORK_PING;
158+
for (uint8_t i = 0; i < MESH_CONNECTION_CHECK_ATTEMPTS; ++i) {
159+
if (network.write(header, 0, 0)) {
160+
return true;
161+
}
162+
}
163+
return false;
164+
165+
#else // Connection check via master node
166+
// getAddress() doesn't use auto-ack; check connectivity multiple times
167+
for (uint8_t i = 0; i < MESH_CONNECTION_CHECK_ATTEMPTS; ++i) {
151168

152169
int16_t result = getAddress(_nodeID);
153170
switch (result) {
@@ -162,6 +179,7 @@ bool RF24Mesh::checkConnection()
162179
}
163180
}
164181
return false;
182+
#endif
165183
}
166184

167185
/*****************************************************/

RF24Mesh.h

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,16 @@ class RF24Mesh
163163
/**
164164
* Tests connectivity of this node to the mesh.
165165
* @note If this function fails, address renewal should typically be done.
166-
* @return 1 if connected, 0 if mesh not responding
166+
*
167+
* The current behavior will only ping this node's parent to validate connection to mesh.
168+
* Previously, this function would validate connection by looking up this node's assigned address with
169+
* the master node's `RF24Mesh::addrList`.
170+
* The old behavior can be mandated by changing @ref RF24MESH_CONN_CHECK_TYPE in RF24Mesh_config.h,
171+
* although a large mesh network might suffer a performance cost using the old behavior.
172+
*
173+
* @return
174+
* - True if connected.
175+
* - False if not connected, mesh is not responding, or this node is the master node.
167176
*/
168177
bool checkConnection();
169178

RF24Mesh_config.h

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,25 @@
6464
#define MESH_CONNECTION_CHECK_ATTEMPTS 3
6565
#endif
6666

67+
#define RF24MESH_CONN_CHECK_PARENT 1
68+
#define RF24MESH_CONN_CHECK_MASTER 0
69+
/**
70+
* @brief How to verify a connection
71+
*
72+
* On child nodes, determine how they verify/check their connection periodically, or when writes start to fail via the `RF24Mesh::checkConnection();`
73+
* function.
74+
* Set RF24MESH_CONN_CHECK_TYPE to @ref RF24MESH_CONN_CHECK_PARENT for the new behaviour of verifying connectivity only with their parent node.
75+
* Set RF24MESH_CONN_CHECK_TYPE to @ref RF24MESH_CONN_CHECK_MASTER for the old behaviour of verifying connectivity with the master node.
76+
* The old behaviour typically results in more network congestion, more load on the master node, and less reliable networks,
77+
* 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
78+
* to the master node.
79+
*/
80+
#ifndef RF24MESH_CONN_CHECK_TYPE
81+
#define RF24MESH_CONN_CHECK_TYPE RF24MESH_CONN_CHECK_PARENT
82+
// To use old behavior:
83+
// #define RF24MESH_CONN_CHECK_TYPE RF24MESH_CONN_CHECK_MASTER
84+
#endif
85+
6786
/**************************/
6887
/*** Debug ***/
6988
//#define RF24MESH_DEBUG_MINIMAL /** Uncomment for the Master Node to print out address assignments as they are assigned */

cmake/AutoConfig_RF24_DRIVER.cmake

Lines changed: 22 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -26,31 +26,33 @@ else()
2626
endif()
2727

2828

29-
if(${RF24_DRIVER} STREQUAL "UNKNOWN") # invokes automatic configuration
30-
if("${SOC}" STREQUAL "BCM2708" OR "${SOC}" STREQUAL "BCM2709" OR "${SOC}" STREQUAL "BCM2835")
31-
set(RF24_DRIVER RPi CACHE STRING "using folder /utility/RPi" FORCE)
32-
elseif(NOT "${LibPIGPIO}" STREQUAL "LibPIGPIO-NOTFOUND")
33-
message(STATUS "Found pigpio library: ${LibPIGPIO}")
34-
set(RF24_DRIVER pigpio CACHE STRING "using folder /utility/pigpio" FORCE)
35-
elseif(NOT "${LibWiringPi}" STREQUAL "LibWiringPi-NOTFOUND")
36-
message(STATUS "Found wiringPi library: ${LibWiringPi}")
37-
set(RF24_DRIVER wiringPi CACHE STRING "using folder /utility/wiringPi" FORCE)
38-
elseif(NOT "${LibLittleWire}" STREQUAL "LibLittleWire-NOTFOUND")
39-
message(STATUS "Found LittleWire library: ${LibLittleWire}")
40-
set(RF24_DRIVER LittleWire CACHE STRING "using folder /utility/LittleWire" FORCE)
41-
elseif(NOT "${LibMRAA}" STREQUAL "LibMRAA-NOTFOUND")
42-
message(STATUS "Found MRAA library: ${LibMRAA}")
43-
set(RF24_DRIVER MRAA CACHE STRING "using folder /utility/MRAA" FORCE)
44-
elseif(SPIDEV_EXISTS) # should be a non-empty string if SPI is enabled
45-
message(STATUS "detected that SPIDEV is enabled: ${SPIDEV_EXISTS}")
46-
set(RF24_DRIVER SPIDEV CACHE STRING "using folder /utility/SPIDEV" FORCE)
47-
endif()
48-
endif()
29+
# if(${RF24_DRIVER} STREQUAL "UNKNOWN") # invokes automatic configuration
30+
# if("${SOC}" STREQUAL "BCM2708" OR "${SOC}" STREQUAL "BCM2709" OR "${SOC}" STREQUAL "BCM2835")
31+
# set(RF24_DRIVER RPi CACHE STRING "using folder /utility/RPi" FORCE)
32+
# elseif(NOT "${LibPIGPIO}" STREQUAL "LibPIGPIO-NOTFOUND")
33+
# message(STATUS "Found pigpio library: ${LibPIGPIO}")
34+
# set(RF24_DRIVER pigpio CACHE STRING "using folder /utility/pigpio" FORCE)
35+
# elseif(NOT "${LibWiringPi}" STREQUAL "LibWiringPi-NOTFOUND")
36+
# message(STATUS "Found wiringPi library: ${LibWiringPi}")
37+
# set(RF24_DRIVER wiringPi CACHE STRING "using folder /utility/wiringPi" FORCE)
38+
# elseif(NOT "${LibLittleWire}" STREQUAL "LibLittleWire-NOTFOUND")
39+
# message(STATUS "Found LittleWire library: ${LibLittleWire}")
40+
# set(RF24_DRIVER LittleWire CACHE STRING "using folder /utility/LittleWire" FORCE)
41+
# elseif(NOT "${LibMRAA}" STREQUAL "LibMRAA-NOTFOUND")
42+
# message(STATUS "Found MRAA library: ${LibMRAA}")
43+
# set(RF24_DRIVER MRAA CACHE STRING "using folder /utility/MRAA" FORCE)
44+
# elseif(SPIDEV_EXISTS) # should be a non-empty string if SPI is enabled
45+
# message(STATUS "detected that SPIDEV is enabled: ${SPIDEV_EXISTS}")
46+
# set(RF24_DRIVER SPIDEV CACHE STRING "using folder /utility/SPIDEV" FORCE)
47+
# endif()
48+
# endif()
4949

5050
# override the auto-detect if RF24_DRIVER is defined in an env var
5151
if(DEFINED ENV{RF24_DRIVER})
5252
message(STATUS "RF24_DRIVER (set from env var) = $ENV{RF24_DRIVER}")
5353
set(RF24_DRIVER $ENV{RF24_DRIVER} CACHE STRING "" FORCE)
54+
elseif(${RF24_DRIVER} STREQUAL "UNKNOWN")
55+
set(RF24_DRIVER SPIDEV CACHE STRING "using folder RF24/utility/SPIDEV" FORCE)
5456
endif()
5557

5658
message(STATUS "Using driver: ${RF24_DRIVER}")

examples_RPi/CMakeLists.txt

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -47,26 +47,20 @@ elseif("${RF24_DRIVER}" STREQUAL "wiringPi")
4747
else()
4848
message(FATAL "Lib ${RF24_DRIVER} not found.")
4949
endif()
50-
elseif(NOT "${LibPIGPIO}" STREQUAL "LibPIGPIO-NOTFOUND" AND NOT DEFINED RF24_NO_INTERUPT)
51-
if(NOT "${RF24_DRIVER}" STREQUAL "pigpio")
52-
message(STATUS "linking to ${LibPIGPIO} for interrupt support")
53-
else()
50+
elseif("${RF24_DRIVER}" STREQUAL "pigpio")
51+
if(NOT "${LibPIGPIO}" STREQUAL "LibPIGPIO-NOTFOUND")
5452
message(STATUS "linking to ${LibPIGPIO}")
53+
list(APPEND linked_libs ${LibPIGPIO})
54+
else()
55+
message(FATAL "Lib ${RF24_DRIVER} not found.")
5556
endif()
56-
list(APPEND linked_libs ${LibPIGPIO})
57-
else()
58-
message(STATUS "Disabling IRQ pin support")
5957
endif()
6058

6159
foreach(example ${EXAMPLES_LIST})
6260
# make a target
6361
add_executable(${example} ${example}.cpp)
6462
# link the RF24 lib to the target.
6563
target_link_libraries(${example} PUBLIC ${linked_libs})
66-
# conditionally disable interruot support (a pigpio specific feature)
67-
if("${LibPIGPIO}" STREQUAL "LibPIGPIO-NOTFOUND" OR DEFINED RF24_NO_INTERRUPT)
68-
target_compile_definitions(${example} PUBLIC RF24_NO_INTERRUPT)
69-
endif()
7064
endforeach()
7165

7266
include(../cmake/enableNcursesExample.cmake)

0 commit comments

Comments
 (0)