Skip to content

Commit d92918c

Browse files
author
Marcelo Aquino
committed
Accept a new parent only when autoFindParent is 1
In a gateway, I_FIND_PARENT_RESPONSE messages was returning as true by process(). With this commit it will return as false, is this the right expected behavior?
1 parent 7b99a2e commit d92918c

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
@@ -300,17 +300,19 @@ boolean MySensor::process() {
300300
}
301301

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

0 commit comments

Comments
 (0)