diff --git a/libraries/MySensors/MyGateway.cpp b/libraries/MySensors/MyGateway.cpp index 7e70c87..2785ec9 100644 --- a/libraries/MySensors/MyGateway.cpp +++ b/libraries/MySensors/MyGateway.cpp @@ -169,8 +169,10 @@ void MyGateway::parseAndSend(char *commandBuffer) { } } else { value = str; - // Remove newline character - value[strlen(value)-1] = 0; + // Remove ending carriage return character (if it exists) + uint8_t lastCharacter = strlen(value)-1; + if (value[lastCharacter] == '\r') + value[lastCharacter] = 0; } break; } diff --git a/libraries/MySensors/MyMessage.cpp b/libraries/MySensors/MyMessage.cpp index a5f8a20..286b111 100755 --- a/libraries/MySensors/MyMessage.cpp +++ b/libraries/MySensors/MyMessage.cpp @@ -87,7 +87,13 @@ char* MyMessage::getString(char *buffer) 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 { diff --git a/libraries/MySensors/MySensor.cpp b/libraries/MySensors/MySensor.cpp index 0f2399b..a619171 100755 --- a/libraries/MySensors/MySensor.cpp +++ b/libraries/MySensors/MySensor.cpp @@ -46,7 +46,7 @@ void MySensor::begin(void (*_msgCallback)(const MyMessage &), uint8_t _nodeId, b // Read settings from EEPROM eeprom_read_block((void*)&nc, (void*)EEPROM_NODE_ID_ADDRESS, sizeof(NodeConfig)); // 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) { // Eeprom empty, set default to metric cc.isMetric = 0x01; @@ -328,11 +328,12 @@ boolean MySensor::process() { bool isMetric; if (type == I_REBOOT) { + // Requires MySensors or other bootloader with watchdogs enabled wdt_enable(WDTO_15MS); for (;;); } else if (type == I_ID_RESPONSE) { if (nc.nodeId == AUTO) { - nc.nodeId = msg.getInt(); + nc.nodeId = msg.getByte(); // Write id to EEPROM if (nc.nodeId == AUTO) { // 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) { // Pick up configuration from controller (currently only metric/imperial) // and store it in eeprom if changed - isMetric = msg.getByte() == 'M' ; + isMetric = msg.getString()[0] == 'M' ; if (cc.isMetric != isMetric) { cc.isMetric = 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) { - if (repeaterMode && msg.getByte() == 'C') { + if (repeaterMode && msg.getString()[0] == 'C') { // Clears child relay data for this node debug(PSTR("rd=clear\n")); for (uint8_t i=0;i< sizeof(childNodeTable); i++) {