check valid parentNodeId before requestNodeId

This commit is contained in:
Marcelo Aquino
2015-02-22 10:41:29 -03:00
parent e8bb9623e0
commit 2d8fddcb05
+7 -10
View File
@@ -87,22 +87,19 @@ void MySensor::begin(void (*_msgCallback)(const MyMessage &), uint8_t _nodeId, b
findParentNode();
}
if ( (_nodeId != AUTO) && (nc.nodeId != _nodeId) ) {
// Set static id
nc.nodeId = _nodeId;
// Save static id in eeprom
eeprom_update_byte((uint8_t*)EEPROM_NODE_ID_ADDRESS, _nodeId);
}
// Try to fetch node-id from gateway
if (nc.nodeId == AUTO) {
if (_nodeId != AUTO) {
// Set static id
nc.nodeId = _nodeId;
// Save static id in eeprom
eeprom_update_byte((uint8_t*)EEPROM_NODE_ID_ADDRESS, _nodeId);
} else if (isValidParent(nc.parentNodeId)) {
// Try to fetch node-id from gateway
requestNodeId();
}
setupNode();
debug(PSTR("%s started, id=%d, parent=%d, distance=%d\n"), isGateway?"gateway":(repeaterMode?"repeater":"sensor"), nc.nodeId, nc.parentNodeId, nc.distance);
}
void MySensor::setupRepeaterMode(){