<?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[Boolean switch, setting, requesting and storing in eeprom.]]></title><description><![CDATA[<p dir="auto">I'm opening this topic because I'm getting strange results in a sketch I'm modifying, and perhaps is it something that I misunderstand.</p>
<p dir="auto">I created a "virtual" binary sensor in my device, so I can put it in passive mode, so it is still available, sends it's sensors info but doesn't do any action. Doesn't switch on and off.</p>
<pre><code>bool passiveMode = false;
...
#define CHILD_ID_PASSIVEMODE  4
MyMessage msgPassiveMode(CHILD_ID_PASSIVEMODE, V_STATUS);
...
void sendStatus() {
...
  send(msgPassiveMode.set(passiveMode));
}

void setup() {
...
  passiveMode = loadState(0);
}

void presentation() {
...
  present(CHILD_ID_PASSIVEMODE, S_BINARY, "ModoPasivo");
}
...
void receive(const MyMessage &amp;message) {

  const uint16_t commandType = mGetCommand(message);
  if (commandType == 2) {
    if (message.type == V_STATUS &amp;&amp; message.sensor == CHILD_ID_PASSIVEMODE) {
      send(msgPassiveMode.set(passiveMode));
    }
  }
  else if (commandType == 1) {
    if (message.type == V_STATUS &amp;&amp; message.sensor == CHILD_ID_PASSIVEMODE) {
      if (message.bValue != passiveMode) {
        passiveMode = message.bValue;
        saveState(0, passiveMode);
      }
    }
}
</code></pre>
<p dir="auto">Well, that's all the code added. In the first run, without the memory slot been set, returned a value of "1" for passiveMode. Then, I set it to "0" and requested it again, and it replied again "1".</p>
<p dir="auto">I'm wondering what I I've misunderstood. Is not possible to store that value in the sketch as a boolean and rely on implicit conversions?<br />
The problem can be:<br />
The storage: Does saveState and readState understand true/false as 1/0?<br />
The Set/Req: I interpret that those functions should enforce the conversions as message has a bValue property available and send has overloads for it.</p>
<p dir="auto">I could change passiveMode to an uint8_t and never look back, but I need to understand what's the problem, here.</p>
]]></description><link>https://forum.mysensors.org/topic/10645/boolean-switch-setting-requesting-and-storing-in-eeprom</link><generator>RSS for Node</generator><lastBuildDate>Tue, 19 May 2026 00:46:45 GMT</lastBuildDate><atom:link href="https://forum.mysensors.org/topic/10645.rss" rel="self" type="application/rss+xml"/><pubDate>Sun, 15 Sep 2019 17:23:04 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Boolean switch, setting, requesting and storing in eeprom. on Sun, 15 Sep 2019 18:20:32 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/mfalkvidd" aria-label="Profile: mfalkvidd">@<bdi>mfalkvidd</bdi></a> If you look close, I'm only sending as a response to a request from the "controller".</p>
<p dir="auto">But I'm still wrong for insist getting the received value from the property bValue. Seems logical to me that it would contain the boolean value instead of a byte size or whatever.</p>
<p dir="auto">If I had used the method ".getBool()" I would had the boolean value. Although, if the controller sets a boolean, the node still gets wrong values, so you still have to transmit an integer 0/1. I don't like it, because it forces processing all the values as integers in node-red, for example.</p>
<p dir="auto">As usual, I'll leave this, my stupidity, behind in the hopes it serves to anyone else. :sweat_smile:</p>
]]></description><link>https://forum.mysensors.org/post/101327</link><guid isPermaLink="true">https://forum.mysensors.org/post/101327</guid><dc:creator><![CDATA[Sergio Rius]]></dc:creator><pubDate>Sun, 15 Sep 2019 18:20:32 GMT</pubDate></item><item><title><![CDATA[Reply to Boolean switch, setting, requesting and storing in eeprom. on Sun, 15 Sep 2019 18:19:39 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/sergio-rius" aria-label="Profile: sergio-rius">@<bdi>sergio-rius</bdi></a>  calling send from within receive will overwrite the incoming message. So when you're saving the value, you are probably saving the outgoing value, not the incoming value.</p>
]]></description><link>https://forum.mysensors.org/post/101325</link><guid isPermaLink="true">https://forum.mysensors.org/post/101325</guid><dc:creator><![CDATA[mfalkvidd]]></dc:creator><pubDate>Sun, 15 Sep 2019 18:19:39 GMT</pubDate></item><item><title><![CDATA[Reply to Boolean switch, setting, requesting and storing in eeprom. on Sun, 15 Sep 2019 17:59:31 GMT]]></title><description><![CDATA[<p dir="auto">I've built up a new dummy sensor so I can debug it in my desk. The results still are so confusing:</p>
<pre><code>Initialising...
loadState(0): 255  // The expected behavior for a non initialised slot.
passiveMode: 1    // Makes the variable true. All ok.
loadState(0): 255
passiveMode: 1
Received value: 48  // If I Set to 0 bValue is 48??
Storing...
passiveMode: 1
Received value: 102  // If I Set false...
Storing...
passiveMode: 1
loadState(0): 1
passiveMode: 1
Received value: 70   //If I Set False...
Storing...
passiveMode: 1
</code></pre>
<p dir="auto">That's so interesting. But not what I expected.</p>
]]></description><link>https://forum.mysensors.org/post/101324</link><guid isPermaLink="true">https://forum.mysensors.org/post/101324</guid><dc:creator><![CDATA[Sergio Rius]]></dc:creator><pubDate>Sun, 15 Sep 2019 17:59:31 GMT</pubDate></item></channel></rss>