Merge pull request #62 from mapnull/hotfix-autoFindParent_response
Accept a new parent only when autoFindParent is 1
This commit is contained in:
@@ -37,6 +37,7 @@ void MyGateway::begin(rf24_pa_dbm_e paLevel, uint8_t channel, rf24_datarate_e da
|
|||||||
Serial.begin(BAUD_RATE);
|
Serial.begin(BAUD_RATE);
|
||||||
repeaterMode = true;
|
repeaterMode = true;
|
||||||
isGateway = true;
|
isGateway = true;
|
||||||
|
autoFindParent = false;
|
||||||
setupRepeaterMode();
|
setupRepeaterMode();
|
||||||
|
|
||||||
if (inDataCallback != NULL) {
|
if (inDataCallback != NULL) {
|
||||||
|
|||||||
@@ -303,17 +303,19 @@ boolean MySensor::process() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (command == C_INTERNAL) {
|
if (command == C_INTERNAL) {
|
||||||
if (type == I_FIND_PARENT_RESPONSE && !isGateway) {
|
if (type == I_FIND_PARENT_RESPONSE) {
|
||||||
// We've received a reply to a FIND_PARENT message. Check if the distance is
|
if (autoFindParent) {
|
||||||
// shorter than we already have.
|
// We've received a reply to a FIND_PARENT message. Check if the distance is
|
||||||
uint8_t distance = msg.getByte();
|
// shorter than we already have.
|
||||||
if (distance<nc.distance-1) {
|
uint8_t distance = msg.getByte();
|
||||||
// Found a neighbor closer to GW than previously found
|
if (distance<nc.distance-1) {
|
||||||
nc.distance = distance + 1;
|
// Found a neighbor closer to GW than previously found
|
||||||
nc.parentNodeId = msg.sender;
|
nc.distance = distance + 1;
|
||||||
eeprom_write_byte((uint8_t*)EEPROM_PARENT_NODE_ID_ADDRESS, nc.parentNodeId);
|
nc.parentNodeId = msg.sender;
|
||||||
eeprom_write_byte((uint8_t*)EEPROM_DISTANCE_ADDRESS, nc.distance);
|
eeprom_write_byte((uint8_t*)EEPROM_PARENT_NODE_ID_ADDRESS, nc.parentNodeId);
|
||||||
debug(PSTR("new parent=%d, d=%d\n"), nc.parentNodeId, nc.distance);
|
eeprom_write_byte((uint8_t*)EEPROM_DISTANCE_ADDRESS, nc.distance);
|
||||||
|
debug(PSTR("new parent=%d, d=%d\n"), nc.parentNodeId, nc.distance);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
} else if (sender == GATEWAY_ADDRESS) {
|
} else if (sender == GATEWAY_ADDRESS) {
|
||||||
|
|||||||
Reference in New Issue
Block a user