Skip to content

Commit a22f712

Browse files
author
Marcelo Aquino
committed
respond to a I_FIND_PARENT after findParentNode()
When a repeater receives a I_FIND_PARENT, it first update the nc.distance if is invalid and then respond the request
1 parent fcb9243 commit a22f712

File tree

1 file changed

+11
-8
lines changed

1 file changed

+11
-8
lines changed

libraries/MySensors/MySensor.cpp

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -781,14 +781,17 @@ boolean MySensor::process() {
781781
// If this node have an id, relay the message
782782

783783
if (command == C_INTERNAL && type == I_FIND_PARENT) {
784-
if (nc.distance == DISTANCE_INVALID) {
785-
findParentNode();
786-
} else if (sender != nc.parentNodeId) {
787-
// Relaying nodes should always answer ping messages
788-
// Wait a random delay of 0-2 seconds to minimize collision
789-
// between ping ack messages from other relaying nodes
790-
wait(hw_millis() & 0x3ff);
791-
sendWrite(sender, build(msg, nc.nodeId, sender, NODE_SENSOR_ID, C_INTERNAL, I_FIND_PARENT_RESPONSE, false).set(nc.distance));
784+
if (sender != nc.parentNodeId) {
785+
if (nc.distance == DISTANCE_INVALID)
786+
findParentNode();
787+
788+
if (nc.distance != DISTANCE_INVALID) {
789+
// Relaying nodes should always answer ping messages
790+
// Wait a random delay of 0-2 seconds to minimize collision
791+
// between ping ack messages from other relaying nodes
792+
wait(hw_millis() & 0x3ff);
793+
sendWrite(sender, build(msg, nc.nodeId, sender, NODE_SENSOR_ID, C_INTERNAL, I_FIND_PARENT_RESPONSE, false).set(nc.distance));
794+
}
792795
}
793796
} else if (to == nc.nodeId) {
794797
// We should try to relay this message to another node

0 commit comments

Comments
 (0)