Skip to content

Commit 9192da3

Browse files
committed
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)
1 parent bf341ab commit 9192da3

File tree

3 files changed

+16
-8
lines changed

3 files changed

+16
-8
lines changed

libraries/MySensors/MyGateway.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -169,8 +169,10 @@ void MyGateway::parseAndSend(char *commandBuffer) {
169169
}
170170
} else {
171171
value = str;
172-
// Remove newline character
173-
value[strlen(value)-1] = 0;
172+
// Remove ending carriage return character (if it exists)
173+
uint8_t lastCharacter = strlen(value)-1;
174+
if (value[lastCharacter] == '\r')
175+
value[lastCharacter] = 0;
174176
}
175177
break;
176178
}

libraries/MySensors/MyMessage.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,13 @@ char* MyMessage::getString(char *buffer) const {
8787
}
8888

8989
uint8_t MyMessage::getByte() const {
90-
return data[0];
90+
if (miGetPayloadType() == P_BYTE) {
91+
return data[0];
92+
} else if (miGetPayloadType() == P_STRING) {
93+
return atoi(data);
94+
} else {
95+
return 0;
96+
}
9197
}
9298

9399
bool MyMessage::getBool() const {

libraries/MySensors/MySensor.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ void MySensor::begin(void (*_msgCallback)(const MyMessage &), uint8_t _nodeId, b
4646
// Read settings from EEPROM
4747
eeprom_read_block((void*)&nc, (void*)EEPROM_NODE_ID_ADDRESS, sizeof(NodeConfig));
4848
// Read latest received controller configuration from EEPROM
49-
eeprom_read_block((void*)&cc, (void*)EEPROM_LOCAL_CONFIG_ADDRESS, sizeof(ControllerConfig));
49+
eeprom_read_block((void*)&cc, (void*)EEPROM_CONTROLLER_CONFIG_ADDRESS, sizeof(ControllerConfig));
5050
if (cc.isMetric == 0xff) {
5151
// Eeprom empty, set default to metric
5252
cc.isMetric = 0x01;
@@ -328,11 +328,12 @@ boolean MySensor::process() {
328328
bool isMetric;
329329

330330
if (type == I_REBOOT) {
331+
// Requires MySensors or other bootloader with watchdogs enabled
331332
wdt_enable(WDTO_15MS);
332333
for (;;);
333334
} else if (type == I_ID_RESPONSE) {
334335
if (nc.nodeId == AUTO) {
335-
nc.nodeId = msg.getInt();
336+
nc.nodeId = msg.getByte();
336337
// Write id to EEPROM
337338
if (nc.nodeId == AUTO) {
338339
// sensor net gateway will return max id if all sensor id are taken
@@ -347,14 +348,13 @@ boolean MySensor::process() {
347348
} else if (type == I_CONFIG) {
348349
// Pick up configuration from controller (currently only metric/imperial)
349350
// and store it in eeprom if changed
350-
isMetric = msg.getByte() == 'M' ;
351+
isMetric = msg.getString()[0] == 'M' ;
351352
if (cc.isMetric != isMetric) {
352353
cc.isMetric = isMetric;
353354
eeprom_write_byte((uint8_t*)EEPROM_CONTROLLER_CONFIG_ADDRESS, isMetric);
354-
//eeprom_write_block((const void*)&cc, (uint8_t*)EEPROM_CONTROLLER_CONFIG_ADDRESS, sizeof(ControllerConfig));
355355
}
356356
} else if (type == I_CHILDREN) {
357-
if (repeaterMode && msg.getByte() == 'C') {
357+
if (repeaterMode && msg.getString()[0] == 'C') {
358358
// Clears child relay data for this node
359359
debug(PSTR("rd=clear\n"));
360360
for (uint8_t i=0;i< sizeof(childNodeTable); i++) {

0 commit comments

Comments
 (0)