@@ -51,7 +51,7 @@ void MySensor::begin(void (*_msgCallback)(const MyMessage &), uint8_t _nodeId, b
51
51
}
52
52
setupRadio ();
53
53
54
- // Read settings from EEPROM
54
+ // Read settings from eeprom
55
55
eeprom_read_block ((void *)&nc, (void *)EEPROM_NODE_ID_ADDRESS, sizeof (NodeConfig));
56
56
// Read latest received controller configuration from EEPROM
57
57
eeprom_read_block ((void *)&cc, (void *)EEPROM_CONTROLLER_CONFIG_ADDRESS, sizeof (ControllerConfig));
@@ -68,7 +68,11 @@ void MySensor::begin(void (*_msgCallback)(const MyMessage &), uint8_t _nodeId, b
68
68
autoFindParent = _parentNodeId == AUTO;
69
69
if (!autoFindParent) {
70
70
nc.parentNodeId = _parentNodeId;
71
- nc.distance = 0 ;
71
+ // Save static parent id in eeprom (used by bootloader)
72
+ eeprom_write_byte ((uint8_t *)EEPROM_PARENT_NODE_ID_ADDRESS, _parentNodeId);
73
+ // We don't actually know the distance to gw here. Let's pretend it is 1.
74
+ // If the current node is also repeater, be aware of this.
75
+ nc.distance = 1 ;
72
76
} else if (!isValidParent (nc.parentNodeId )) {
73
77
// Auto find parent, but parent in eeprom is invalid. Force parent search on first transmit.
74
78
nc.distance = DISTANCE_INVALID;
@@ -377,6 +381,11 @@ boolean MySensor::process() {
377
381
for (uint8_t i=0 ;i< sizeof (childNodeTable); i++) {
378
382
removeChildRoute (i);
379
383
}
384
+ // Clear parent node id & distance to gw
385
+ eeprom_write_byte ((uint8_t *)EEPROM_PARENT_NODE_ID_ADDRESS, 0xFF );
386
+ eeprom_write_byte ((uint8_t *)EEPROM_DISTANCE_ADDRESS, 0xFF );
387
+ // Find parent node
388
+ findParentNode ();
380
389
sendRoute (build (msg, nc.nodeId , GATEWAY_ADDRESS, NODE_SENSOR_ID, C_INTERNAL, I_CHILDREN,false ).set (" " ));
381
390
}
382
391
}
0 commit comments