From bf8f5b8164e6dcc09bfa15933e3eb8400960b81b Mon Sep 17 00:00:00 2001 From: Marcelo Aquino Date: Thu, 29 Jan 2015 17:19:19 -0200 Subject: [PATCH] fix a case where parent distance from repeater get stuck at 255 --- libraries/MySensors/MySensor.cpp | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/libraries/MySensors/MySensor.cpp b/libraries/MySensors/MySensor.cpp index cf2f08e..d0311aa 100755 --- a/libraries/MySensors/MySensor.cpp +++ b/libraries/MySensors/MySensor.cpp @@ -285,11 +285,15 @@ boolean MySensor::process() { uint8_t destination = msg.destination; if (repeaterMode && command == C_INTERNAL && type == I_FIND_PARENT) { - // Relaying nodes should always answer ping messages - // Wait a random delay of 0-2 seconds to minimize collision - // between ping ack messages from other relaying nodes - delay(millis() & 0x3ff); - sendWrite(sender, build(msg, nc.nodeId, sender, NODE_SENSOR_ID, C_INTERNAL, I_FIND_PARENT_RESPONSE, false).set(nc.distance), true); + if (nc.distance == 255) { + findParentNode(); + } else { + // Relaying nodes should always answer ping messages + // Wait a random delay of 0-2 seconds to minimize collision + // between ping ack messages from other relaying nodes + delay(millis() & 0x3ff); + sendWrite(sender, build(msg, nc.nodeId, sender, NODE_SENSOR_ID, C_INTERNAL, I_FIND_PARENT_RESPONSE, false).set(nc.distance), true); + } return false; } else if (destination == nc.nodeId) { // Check if sender requests an ack back.