@@ -67,9 +67,11 @@ void MySensor::begin(void (*_msgCallback)(const MyMessage &), uint8_t _nodeId, b
67
67
68
68
autoFindParent = _parentNodeId == AUTO;
69
69
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
+ }
73
75
// We don't actually know the distance to gw here. Let's pretend it is 1.
74
76
// If the current node is also repeater, be aware of this.
75
77
nc.distance = 1 ;
@@ -293,21 +295,23 @@ boolean MySensor::process() {
293
295
}
294
296
295
297
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
+ }
311
315
}
312
316
}
313
317
return false ;
0 commit comments