<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[Sensor::readMessage()]]></title><description><![CDATA[<p dir="auto">When I ported sensor.cpp to C# i notice:</p>
<p dir="auto">boolean Sensor::readMessage() {<br />
uint8_t len = RF24::getDynamicPayloadSize();<br />
RF24::read(&amp;msg, len);</p>
<pre><code>if (!(msg.header.messageType==M_INTERNAL &amp;&amp; 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));
	RF24::write(&amp;radioId, sizeof(uint8_t));
	RF24::closeReadingPipe(WRITE_PIPE); // Stop listening to write-pipe after transmit
	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';
debug(PSTR("Rx: fr=%d,to=%d,la=%d,ci=%d,mt=%d,t=%d,cr=%d(%s): %s\n"),
		msg.header.from,msg.header.to, msg.header.last, msg.header.childId, msg.header.messageType, msg.header.type, msg.header.crc, valid==0?"ok":valid==1?"ec":"ev", msg.data);
return ok;
</code></pre>
<p dir="auto">}</p>
<p dir="auto">Is this correct? Isn't better to first validante message and then send confirmation if it is ok. Like this:</p>
<p dir="auto">boolean Sensor::readMessage() {<br />
uint8_t len = RF24::getDynamicPayloadSize();<br />
RF24::read(&amp;msg, len);</p>
<p dir="auto">uint8_t valid = validate(len-sizeof(header_s));<br />
boolean ok = valid == VALIDATE_OK;**<br />
**<br />
if (ok &amp;&amp; !(msg.header.messageType==M_INTERNAL &amp;&amp; msg.header.type == I_PING_ACK)) {<br />
delay(ACK_SEND_DELAY); // Small delay here to let other side switch to reading mode<br />
RF24::stopListening();<br />
RF24::openWritingPipe(TO_ADDR(msg.header.last));<br />
RF24::write(&amp;radioId, sizeof(uint8_t));<br />
RF24::closeReadingPipe(WRITE_PIPE); // Stop listening to write-pipe after transmit<br />
RF24::startListening();<br />
debug(PSTR("Sent ack msg to %d\n"), msg.header.last);<br />
}</p>
<pre><code>// Make sure string gets terminated ok for full sized messages.
msg.data[len - sizeof(header_s) ] = '\0';
debug(PSTR("Rx: fr=%d,to=%d,la=%d,ci=%d,mt=%d,t=%d,cr=%d(%s): %s\n"),
		msg.header.from,msg.header.to, msg.header.last, msg.header.childId, msg.header.messageType, msg.header.type, msg.header.crc, valid==0?"ok":valid==1?"ec":"ev", msg.data);
return ok;
</code></pre>
<p dir="auto">}</p>
]]></description><link>https://forum.mysensors.org/topic/37/sensor-readmessage</link><generator>RSS for Node</generator><lastBuildDate>Tue, 21 Jul 2026 19:28:58 GMT</lastBuildDate><atom:link href="https://forum.mysensors.org/topic/37.rss" rel="self" type="application/rss+xml"/><pubDate>Tue, 15 Apr 2014 07:32:23 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Sensor::readMessage() on Tue, 15 Apr 2014 09:27:07 GMT]]></title><description><![CDATA[<p dir="auto">Also in RelayActuator.ino</p>
<p dir="auto">void setRelayStatus(message_s message) {<br />
if (message.header.messageType=M_SET_VARIABLE &amp;&amp;<br />
message.header.type==V_LIGHT) {</p>
<p dir="auto">is better:</p>
<p dir="auto">void setRelayStatus(message_s message) {<br />
if ((message.header.messageType==M_SET_VARIABLE || message.header.messageType==M_ACK_VARIABLE ) &amp;&amp;<br />
message.header.type==V_LIGHT) {</p>
<p dir="auto">Be careful message.header.messageType=M_SET_VARIABLE and message.header.messageType==M_SET_VARIABLE is not the same.</p>
]]></description><link>https://forum.mysensors.org/post/173</link><guid isPermaLink="true">https://forum.mysensors.org/post/173</guid><dc:creator><![CDATA[EasyIoT]]></dc:creator><pubDate>Tue, 15 Apr 2014 09:27:07 GMT</pubDate></item><item><title><![CDATA[Reply to Sensor::readMessage() on Tue, 15 Apr 2014 08:33:09 GMT]]></title><description><![CDATA[<p dir="auto">Yes, you're right!</p>
<p dir="auto">I will change this.</p>
]]></description><link>https://forum.mysensors.org/post/172</link><guid isPermaLink="true">https://forum.mysensors.org/post/172</guid><dc:creator><![CDATA[hek]]></dc:creator><pubDate>Tue, 15 Apr 2014 08:33:09 GMT</pubDate></item></channel></rss>