Skip to content

Commit 50c8c44

Browse files
committed
Merge branch 'master' into development
Conflicts: libraries/MySensors/MyGateway.cpp libraries/MySensors/MySensor.cpp
2 parents 6f0ea1f + 9fecc53 commit 50c8c44

File tree

1 file changed

+22
-18
lines changed

1 file changed

+22
-18
lines changed

libraries/MySensors/MySensor.cpp

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -67,9 +67,11 @@ void MySensor::begin(void (*_msgCallback)(const MyMessage &), uint8_t _nodeId, b
6767

6868
autoFindParent = _parentNodeId == AUTO;
6969
if (!autoFindParent) {
70-
nc.parentNodeId = _parentNodeId;
71-
// Save static parent id in eeprom (used by bootloader)
72-
eeprom_write_byte((uint8_t*)EEPROM_PARENT_NODE_ID_ADDRESS, _parentNodeId);
70+
if (_parentNodeId != nc.parentNodeId) {
71+
nc.parentNodeId = _parentNodeId;
72+
// Save static parent id in eeprom (used by bootloader)
73+
eeprom_write_byte((uint8_t*)EEPROM_PARENT_NODE_ID_ADDRESS, _parentNodeId);
74+
}
7375
// We don't actually know the distance to gw here. Let's pretend it is 1.
7476
// If the current node is also repeater, be aware of this.
7577
nc.distance = 1;
@@ -293,21 +295,23 @@ boolean MySensor::process() {
293295
}
294296

295297
if (command == C_INTERNAL) {
296-
if (type == I_FIND_PARENT_RESPONSE && !isGateway) {
297-
// We've received a reply to a FIND_PARENT message. Check if the distance is
298-
// shorter than we already have.
299-
uint8_t distance = msg.getByte();
300-
if (isValidDistance(distance))
301-
{
302-
// Distance to gateway is one more for us w.r.t. parent
303-
distance++;
304-
if (isValidDistance(distance) && (distance < nc.distance)) {
305-
// Found a neighbor closer to GW than previously found
306-
nc.distance = distance;
307-
nc.parentNodeId = msg.sender;
308-
eeprom_write_byte((uint8_t*)EEPROM_PARENT_NODE_ID_ADDRESS, nc.parentNodeId);
309-
eeprom_write_byte((uint8_t*)EEPROM_DISTANCE_ADDRESS, nc.distance);
310-
debug(PSTR("new parent=%d, d=%d\n"), nc.parentNodeId, nc.distance);
298+
if (type == I_FIND_PARENT_RESPONSE) {
299+
if (autoFindParent) {
300+
// We've received a reply to a FIND_PARENT message. Check if the distance is
301+
// shorter than we already have.
302+
uint8_t distance = msg.getByte();
303+
if (isValidDistance(distance))
304+
{
305+
// Distance to gateway is one more for us w.r.t. parent
306+
distance++;
307+
if (isValidDistance(distance) && (distance < nc.distance)) {
308+
// Found a neighbor closer to GW than previously found
309+
nc.distance = distance;
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);
314+
}
311315
}
312316
}
313317
return false;

0 commit comments

Comments
 (0)