From 43d74e2083faf0260d1763e2497b3e74e27593b3 Mon Sep 17 00:00:00 2001 From: Henrik Ekblad Date: Tue, 15 Apr 2014 19:38:39 +0200 Subject: [PATCH] Bug fixed for http://forum.mysensors.org/topic/37/sensor-readmessage --- libraries/MySensors/Sensor.cpp | 7 ++++--- .../MySensors/examples/RelayActuator/RelayActuator.ino | 2 +- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/libraries/MySensors/Sensor.cpp b/libraries/MySensors/Sensor.cpp index 2824e39..fca9dfa 100644 --- a/libraries/MySensors/Sensor.cpp +++ b/libraries/MySensors/Sensor.cpp @@ -454,7 +454,10 @@ boolean Sensor::readMessage() { uint8_t len = RF24::getDynamicPayloadSize(); RF24::read(&msg, len); - if (!(msg.header.messageType==M_INTERNAL && msg.header.type == I_PING_ACK)) { + uint8_t valid = validate(len-sizeof(header_s)); + boolean ok = valid == VALIDATE_OK; + + if (ok && !(msg.header.messageType==M_INTERNAL && msg.header.type == I_PING_ACK)) { delay(ACK_SEND_DELAY); // Small delay here to let other side switch to reading mode RF24::stopListening(); RF24::openWritingPipe(TO_ADDR(msg.header.last)); @@ -463,8 +466,6 @@ boolean Sensor::readMessage() { RF24::startListening(); debug(PSTR("Sent ack msg to %d\n"), msg.header.last); } - uint8_t valid = validate(len-sizeof(header_s)); - boolean ok = valid == VALIDATE_OK; // Make sure string gets terminated ok for full sized messages. msg.data[len - sizeof(header_s) ] = '\0'; diff --git a/libraries/MySensors/examples/RelayActuator/RelayActuator.ino b/libraries/MySensors/examples/RelayActuator/RelayActuator.ino index 98fcb4f..8b995b6 100644 --- a/libraries/MySensors/examples/RelayActuator/RelayActuator.ino +++ b/libraries/MySensors/examples/RelayActuator/RelayActuator.ino @@ -50,7 +50,7 @@ void loop() } void setRelayStatus(message_s message) { - if (message.header.messageType=M_SET_VARIABLE && + if (message.header.messageType==M_SET_VARIABLE && message.header.type==V_LIGHT) { int incomingRelayStatus = atoi(message.data); // Change relay state