Fix another problem related to config from controller (reading wrong position at startup!). Bugfix. Only strip carriage return on serial data from controller (at gateway)
This commit is contained in:
@@ -169,8 +169,10 @@ void MyGateway::parseAndSend(char *commandBuffer) {
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
value = str;
|
value = str;
|
||||||
// Remove newline character
|
// Remove ending carriage return character (if it exists)
|
||||||
value[strlen(value)-1] = 0;
|
uint8_t lastCharacter = strlen(value)-1;
|
||||||
|
if (value[lastCharacter] == '\r')
|
||||||
|
value[lastCharacter] = 0;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -87,7 +87,13 @@ char* MyMessage::getString(char *buffer) const {
|
|||||||
}
|
}
|
||||||
|
|
||||||
uint8_t MyMessage::getByte() const {
|
uint8_t MyMessage::getByte() const {
|
||||||
return data[0];
|
if (miGetPayloadType() == P_BYTE) {
|
||||||
|
return data[0];
|
||||||
|
} else if (miGetPayloadType() == P_STRING) {
|
||||||
|
return atoi(data);
|
||||||
|
} else {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool MyMessage::getBool() const {
|
bool MyMessage::getBool() const {
|
||||||
|
|||||||
@@ -46,7 +46,7 @@ void MySensor::begin(void (*_msgCallback)(const MyMessage &), uint8_t _nodeId, b
|
|||||||
// Read settings from EEPROM
|
// Read settings from EEPROM
|
||||||
eeprom_read_block((void*)&nc, (void*)EEPROM_NODE_ID_ADDRESS, sizeof(NodeConfig));
|
eeprom_read_block((void*)&nc, (void*)EEPROM_NODE_ID_ADDRESS, sizeof(NodeConfig));
|
||||||
// Read latest received controller configuration from EEPROM
|
// Read latest received controller configuration from EEPROM
|
||||||
eeprom_read_block((void*)&cc, (void*)EEPROM_LOCAL_CONFIG_ADDRESS, sizeof(ControllerConfig));
|
eeprom_read_block((void*)&cc, (void*)EEPROM_CONTROLLER_CONFIG_ADDRESS, sizeof(ControllerConfig));
|
||||||
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;
|
||||||
@@ -328,11 +328,12 @@ boolean MySensor::process() {
|
|||||||
bool isMetric;
|
bool isMetric;
|
||||||
|
|
||||||
if (type == I_REBOOT) {
|
if (type == I_REBOOT) {
|
||||||
|
// Requires MySensors or other bootloader with watchdogs enabled
|
||||||
wdt_enable(WDTO_15MS);
|
wdt_enable(WDTO_15MS);
|
||||||
for (;;);
|
for (;;);
|
||||||
} else if (type == I_ID_RESPONSE) {
|
} else if (type == I_ID_RESPONSE) {
|
||||||
if (nc.nodeId == AUTO) {
|
if (nc.nodeId == AUTO) {
|
||||||
nc.nodeId = msg.getInt();
|
nc.nodeId = msg.getByte();
|
||||||
// Write id to EEPROM
|
// Write id to EEPROM
|
||||||
if (nc.nodeId == AUTO) {
|
if (nc.nodeId == AUTO) {
|
||||||
// sensor net gateway will return max id if all sensor id are taken
|
// sensor net gateway will return max id if all sensor id are taken
|
||||||
@@ -347,14 +348,13 @@ boolean MySensor::process() {
|
|||||||
} else if (type == I_CONFIG) {
|
} else if (type == I_CONFIG) {
|
||||||
// Pick up configuration from controller (currently only metric/imperial)
|
// Pick up configuration from controller (currently only metric/imperial)
|
||||||
// and store it in eeprom if changed
|
// and store it in eeprom if changed
|
||||||
isMetric = msg.getByte() == 'M' ;
|
isMetric = msg.getString()[0] == 'M' ;
|
||||||
if (cc.isMetric != isMetric) {
|
if (cc.isMetric != isMetric) {
|
||||||
cc.isMetric = isMetric;
|
cc.isMetric = isMetric;
|
||||||
eeprom_write_byte((uint8_t*)EEPROM_CONTROLLER_CONFIG_ADDRESS, isMetric);
|
eeprom_write_byte((uint8_t*)EEPROM_CONTROLLER_CONFIG_ADDRESS, isMetric);
|
||||||
//eeprom_write_block((const void*)&cc, (uint8_t*)EEPROM_CONTROLLER_CONFIG_ADDRESS, sizeof(ControllerConfig));
|
|
||||||
}
|
}
|
||||||
} else if (type == I_CHILDREN) {
|
} else if (type == I_CHILDREN) {
|
||||||
if (repeaterMode && msg.getByte() == 'C') {
|
if (repeaterMode && msg.getString()[0] == 'C') {
|
||||||
// Clears child relay data for this node
|
// Clears child relay data for this node
|
||||||
debug(PSTR("rd=clear\n"));
|
debug(PSTR("rd=clear\n"));
|
||||||
for (uint8_t i=0;i< sizeof(childNodeTable); i++) {
|
for (uint8_t i=0;i< sizeof(childNodeTable); i++) {
|
||||||
|
|||||||
Reference in New Issue
Block a user