Correct initialization for gateway
This commit is contained in:
@@ -88,56 +88,55 @@ void MySensor::begin(void (*_msgCallback)(const MyMessage &), uint8_t _nodeId, b
|
|||||||
msgCallback = _msgCallback;
|
msgCallback = _msgCallback;
|
||||||
failedTransmissions = 0;
|
failedTransmissions = 0;
|
||||||
|
|
||||||
// Only gateway should use node id 0
|
// Only gateway should use node id 0!
|
||||||
isGateway = _nodeId == 0;
|
isGateway = _nodeId == GATEWAY_ADDRESS;
|
||||||
|
|
||||||
// Setup radio
|
// Setup radio
|
||||||
radio.init();
|
radio.init();
|
||||||
|
|
||||||
// Read settings from eeprom
|
|
||||||
hw_readConfigBlock((void*)&nc, (void*)EEPROM_NODE_ID_ADDRESS, sizeof(NodeConfig));
|
|
||||||
// Read latest received controller configuration from EEPROM
|
|
||||||
hw_readConfigBlock((void*)&cc, (void*)EEPROM_CONTROLLER_CONFIG_ADDRESS, sizeof(ControllerConfig));
|
|
||||||
#ifdef MY_OTA_FIRMWARE_FEATURE
|
|
||||||
// Read firmware config from EEPROM, i.e. type, version, CRC, blocks
|
|
||||||
hw_readConfigBlock((void*)&fc, (void*)EEPROM_FIRMWARE_TYPE_ADDRESS, sizeof(NodeFirmwareConfig));
|
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
#ifdef MY_SIGNING_FEATURE
|
#ifdef MY_SIGNING_FEATURE
|
||||||
// Read out the signing requirements from EEPROM
|
// Read out the signing requirements from EEPROM
|
||||||
hw_readConfigBlock((void*)doSign, (void*)EEPROM_SIGNING_REQUIREMENT_TABLE_ADDRESS, sizeof(doSign));
|
hw_readConfigBlock((void*)doSign, (void*)EEPROM_SIGNING_REQUIREMENT_TABLE_ADDRESS, sizeof(doSign));
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (isGateway) {
|
if (isGateway) {
|
||||||
|
// Set configuration for gateway
|
||||||
|
nc.parentNodeId = 0;
|
||||||
nc.distance = 0;
|
nc.distance = 0;
|
||||||
}
|
nc.nodeId = 0;
|
||||||
|
} else {
|
||||||
|
// Read settings from eeprom
|
||||||
|
hw_readConfigBlock((void*)&nc, (void*)EEPROM_NODE_ID_ADDRESS, sizeof(NodeConfig));
|
||||||
|
// Read latest received controller configuration from EEPROM
|
||||||
|
hw_readConfigBlock((void*)&cc, (void*)EEPROM_CONTROLLER_CONFIG_ADDRESS, sizeof(ControllerConfig));
|
||||||
|
#ifdef MY_OTA_FIRMWARE_FEATURE
|
||||||
|
// Read firmware config from EEPROM, i.e. type, version, CRC, blocks
|
||||||
|
hw_readConfigBlock((void*)&fc, (void*)EEPROM_FIRMWARE_TYPE_ADDRESS, sizeof(NodeFirmwareConfig));
|
||||||
|
#endif
|
||||||
|
|
||||||
if (cc.isMetric == 0xff) {
|
if (cc.isMetric == 0xff) {
|
||||||
// Eeprom empty, set default to metric
|
// Eeprom empty, set default to metric
|
||||||
cc.isMetric = 0x01;
|
cc.isMetric = 0x01;
|
||||||
}
|
}
|
||||||
|
|
||||||
autoFindParent = _parentNodeId == AUTO;
|
autoFindParent = _parentNodeId == AUTO;
|
||||||
if (!autoFindParent) {
|
if (!autoFindParent) {
|
||||||
nc.parentNodeId = _parentNodeId;
|
nc.parentNodeId = _parentNodeId;
|
||||||
// Save static parent id in eeprom (used by bootloader)
|
// Save static parent id in eeprom (used by bootloader)
|
||||||
hw_writeConfig(EEPROM_PARENT_NODE_ID_ADDRESS, _parentNodeId);
|
hw_writeConfig(EEPROM_PARENT_NODE_ID_ADDRESS, _parentNodeId);
|
||||||
// We don't actually know the distance to gw here. Let's pretend it is 1.
|
// We don't actually know the distance to gw here. Let's pretend it is 1.
|
||||||
// If the current node is also repeater, be aware of this.
|
// If the current node is also repeater, be aware of this.
|
||||||
nc.distance = 1;
|
nc.distance = 1;
|
||||||
} else if (!isValidParent(nc.parentNodeId)) {
|
} else if (!isValidParent(nc.parentNodeId)) {
|
||||||
// Auto find parent, but parent in eeprom is invalid. Try find one.
|
// Auto find parent, but parent in eeprom is invalid. Try find one.
|
||||||
findParentNode();
|
findParentNode();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!isGateway) {
|
|
||||||
if (_nodeId != AUTO) {
|
if (_nodeId != AUTO) {
|
||||||
// Set static id
|
// Set static id
|
||||||
nc.nodeId = _nodeId;
|
nc.nodeId = _nodeId;
|
||||||
// Save static id in eeprom
|
// Save static id in eeprom
|
||||||
if (_nodeId > 0)
|
hw_writeConfig(EEPROM_NODE_ID_ADDRESS, _nodeId);
|
||||||
hw_writeConfig(EEPROM_NODE_ID_ADDRESS, _nodeId);
|
|
||||||
} else if (isValidParent(nc.parentNodeId)) {
|
} else if (isValidParent(nc.parentNodeId)) {
|
||||||
// Try to fetch node-id from gateway
|
// Try to fetch node-id from gateway
|
||||||
requestNodeId();
|
requestNodeId();
|
||||||
|
|||||||
Reference in New Issue
Block a user