@@ -51,7 +51,7 @@ void MySensor::begin(void (*_msgCallback)(const MyMessage &), uint8_t _nodeId, b
5151 }
5252 setupRadio ();
5353
54- // Read settings from EEPROM
54+ // Read settings from eeprom
5555 eeprom_read_block ((void *)&nc, (void *)EEPROM_NODE_ID_ADDRESS, sizeof (NodeConfig));
5656 // Read latest received controller configuration from EEPROM
5757 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
6868 autoFindParent = _parentNodeId == AUTO;
6969 if (!autoFindParent) {
7070 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 ;
7276 } else if (!isValidParent (nc.parentNodeId )) {
7377 // Auto find parent, but parent in eeprom is invalid. Force parent search on first transmit.
7478 nc.distance = DISTANCE_INVALID;
@@ -377,6 +381,11 @@ boolean MySensor::process() {
377381 for (uint8_t i=0 ;i< sizeof (childNodeTable); i++) {
378382 removeChildRoute (i);
379383 }
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 ();
380389 sendRoute (build (msg, nc.nodeId , GATEWAY_ADDRESS, NODE_SENSOR_ID, C_INTERNAL, I_CHILDREN,false ).set (" " ));
381390 }
382391 }
0 commit comments