Skip to content

Commit 9fecc53

Browse files
committed
Merge pull request arduino#62 from mapnull/hotfix-autoFindParent_response
Accept a new parent only when autoFindParent is 1
2 parents 80bd4df + d92918c commit 9fecc53

File tree

2 files changed

+14
-11
lines changed

2 files changed

+14
-11
lines changed

libraries/MySensors/MyGateway.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ void MyGateway::begin(rf24_pa_dbm_e paLevel, uint8_t channel, rf24_datarate_e da
3737
Serial.begin(BAUD_RATE);
3838
repeaterMode = true;
3939
isGateway = true;
40+
autoFindParent = false;
4041
setupRepeaterMode();
4142

4243
if (inDataCallback != NULL) {

libraries/MySensors/MySensor.cpp

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -303,17 +303,19 @@ boolean MySensor::process() {
303303
}
304304

305305
if (command == C_INTERNAL) {
306-
if (type == I_FIND_PARENT_RESPONSE && !isGateway) {
307-
// We've received a reply to a FIND_PARENT message. Check if the distance is
308-
// shorter than we already have.
309-
uint8_t distance = msg.getByte();
310-
if (distance<nc.distance-1) {
311-
// Found a neighbor closer to GW than previously found
312-
nc.distance = distance + 1;
313-
nc.parentNodeId = msg.sender;
314-
eeprom_write_byte((uint8_t*)EEPROM_PARENT_NODE_ID_ADDRESS, nc.parentNodeId);
315-
eeprom_write_byte((uint8_t*)EEPROM_DISTANCE_ADDRESS, nc.distance);
316-
debug(PSTR("new parent=%d, d=%d\n"), nc.parentNodeId, nc.distance);
306+
if (type == I_FIND_PARENT_RESPONSE) {
307+
if (autoFindParent) {
308+
// We've received a reply to a FIND_PARENT message. Check if the distance is
309+
// shorter than we already have.
310+
uint8_t distance = msg.getByte();
311+
if (distance<nc.distance-1) {
312+
// Found a neighbor closer to GW than previously found
313+
nc.distance = distance + 1;
314+
nc.parentNodeId = msg.sender;
315+
eeprom_write_byte((uint8_t*)EEPROM_PARENT_NODE_ID_ADDRESS, nc.parentNodeId);
316+
eeprom_write_byte((uint8_t*)EEPROM_DISTANCE_ADDRESS, nc.distance);
317+
debug(PSTR("new parent=%d, d=%d\n"), nc.parentNodeId, nc.distance);
318+
}
317319
}
318320
return false;
319321
} else if (sender == GATEWAY_ADDRESS) {

0 commit comments

Comments
 (0)