Skip to content

Commit 1cd84bf

Browse files
committed
Merge pull request arduino#75 from mapnull/dev-hotfix-begin_requestNodeId
check valid parentNodeId before requestNodeId
2 parents 1979cb6 + 2d8fddc commit 1cd84bf

File tree

1 file changed

+7
-10
lines changed

1 file changed

+7
-10
lines changed

libraries/MySensors/MySensor.cpp

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -87,22 +87,19 @@ void MySensor::begin(void (*_msgCallback)(const MyMessage &), uint8_t _nodeId, b
8787
findParentNode();
8888
}
8989

90-
if ( (_nodeId != AUTO) && (nc.nodeId != _nodeId) ) {
91-
// Set static id
92-
nc.nodeId = _nodeId;
93-
// Save static id in eeprom
94-
eeprom_update_byte((uint8_t*)EEPROM_NODE_ID_ADDRESS, _nodeId);
95-
}
96-
97-
// Try to fetch node-id from gateway
98-
if (nc.nodeId == AUTO) {
90+
if (_nodeId != AUTO) {
91+
// Set static id
92+
nc.nodeId = _nodeId;
93+
// Save static id in eeprom
94+
eeprom_update_byte((uint8_t*)EEPROM_NODE_ID_ADDRESS, _nodeId);
95+
} else if (isValidParent(nc.parentNodeId)) {
96+
// Try to fetch node-id from gateway
9997
requestNodeId();
10098
}
10199

102100
setupNode();
103101

104102
debug(PSTR("%s started, id=%d, parent=%d, distance=%d\n"), isGateway?"gateway":(repeaterMode?"repeater":"sensor"), nc.nodeId, nc.parentNodeId, nc.distance);
105-
106103
}
107104

108105
void MySensor::setupRepeaterMode(){

0 commit comments

Comments
 (0)