<?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[getConfig().isMetric not updated correctly]]></title><description><![CDATA[<p dir="auto">Hey,</p>
<p dir="auto">I just started to create a MySensors controller, and I face a problem relating the metric/imperial config, using this sketch:</p>
<pre><code class="lang-c++">#include &lt;SPI.h&gt;
#include &lt;EEPROM.h&gt;
#include &lt;MySensor.h&gt;
#include &lt;DallasTemperature.h&gt;
#include &lt;OneWire.h&gt;

#define TEMPERATURE_ID 1

#define ONE_WIRE_BUS 4
#define TEMPERATURE_INTERVAL 120

OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature temperatureSensors(&amp;oneWire);
MySensor gw;
MyMessage msgTemperature(TEMPERATURE_ID, V_TEMP);

unsigned long time_temperature_sent;

void setup() {
  temperatureSensors.begin();
  gw.begin(handleMessage);
  gw.sendSketchInfo("Temperature", "0.1");
  gw.present(TEMPERATURE_ID, S_TEMP, "Room temperature");
}

void loop() {
  gw.process();
  if (millis() - time_temperature_sent &gt;= TEMPERATURE_INTERVAL * 1000UL) {
    temperatureSensors.requestTemperaturesByIndex(0); 
    float temperature = static_cast&lt;float&gt;(static_cast&lt;int&gt;((gw.getConfig().isMetric?temperatureSensors.getTempCByIndex(0):temperatureSensors.getTempFByIndex(0)) * 10.)) / 10.;
    gw.send(msgTemperature.set(temperature, 1));
    time_temperature_sent = millis();
  }
}

void handleMessage(const MyMessage&amp; receivedMessage) {
}
</code></pre>
<p dir="auto">Once the controller receives the <code>I_CONFIG</code> message, it replies with a <code>M</code> to indicate we want a value in Celcius. I am an hundred percent sure the reply is received by the sensor.<br />
The first value is sent after two minutes, so the sensor has received and processed the <code>I_CONFIG</code> before sending out its first value.</p>
<p dir="auto">But the fact is the first value sent is in Fahrenheit, and then all subsequent values sent are in Celcius. It's like if the <code>isMetric</code> is not updated, even after having received the config from the controller, until the first send. This happens after each reboot of the sensor.<br />
Maybe I am missing something?</p>
<p dir="auto">Thanks for your answers.</p>
]]></description><link>https://forum.mysensors.org/topic/1848/getconfig-ismetric-not-updated-correctly</link><generator>RSS for Node</generator><lastBuildDate>Sun, 07 Jun 2026 17:31:32 GMT</lastBuildDate><atom:link href="https://forum.mysensors.org/topic/1848.rss" rel="self" type="application/rss+xml"/><pubDate>Sat, 22 Aug 2015 22:28:25 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to getConfig().isMetric not updated correctly on Mon, 24 Aug 2015 14:13:08 GMT]]></title><description><![CDATA[<p dir="auto">Great, and as I see it waits two seconds waiting for the configuration reply. So when you enter in the loop, you're quite sure everything is set! Thanks.</p>
]]></description><link>https://forum.mysensors.org/post/19631</link><guid isPermaLink="true">https://forum.mysensors.org/post/19631</guid><dc:creator><![CDATA[Marvin Roger]]></dc:creator><pubDate>Mon, 24 Aug 2015 14:13:08 GMT</pubDate></item><item><title><![CDATA[Reply to getConfig().isMetric not updated correctly on Sun, 23 Aug 2015 20:50:49 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/hek" aria-label="Profile: hek">@<bdi>hek</bdi></a> Thanks for clarifying!</p>
<p dir="auto">Cheers<br />
Al</p>
]]></description><link>https://forum.mysensors.org/post/19605</link><guid isPermaLink="true">https://forum.mysensors.org/post/19605</guid><dc:creator><![CDATA[Sparkman]]></dc:creator><pubDate>Sun, 23 Aug 2015 20:50:49 GMT</pubDate></item><item><title><![CDATA[Reply to getConfig().isMetric not updated correctly on Sun, 23 Aug 2015 19:55:44 GMT]]></title><description><![CDATA[<p dir="auto">Calling getConfig() only returns a cached copy of the config requested by node at startup (or from eeprom if the request failed).</p>
<p dir="auto">Requested here:<br />
<a href="https://github.com/mysensors/Arduino/blob/master/libraries/MySensors/MySensor.cpp#L279" rel="nofollow ugc">https://github.com/mysensors/Arduino/blob/master/libraries/MySensors/MySensor.cpp#L279</a></p>
<p dir="auto">And reply is handled here:<br />
<a href="https://github.com/mysensors/Arduino/blob/master/libraries/MySensors/MySensor.cpp#L697" rel="nofollow ugc">https://github.com/mysensors/Arduino/blob/master/libraries/MySensors/MySensor.cpp#L697</a></p>
<p dir="auto">So the node is always handling incoming CONFIG updates (when awake).<br />
So either the controller must send out a new config to the nodes when updated or the node must be restarted to send a new request.</p>
<p dir="auto">Currently there aren't any API function exposed to re-request this during runtime. I can't imagine many switches between Metric/Imperial frequently.</p>
]]></description><link>https://forum.mysensors.org/post/19601</link><guid isPermaLink="true">https://forum.mysensors.org/post/19601</guid><dc:creator><![CDATA[hek]]></dc:creator><pubDate>Sun, 23 Aug 2015 19:55:44 GMT</pubDate></item><item><title><![CDATA[Reply to getConfig().isMetric not updated correctly on Sun, 23 Aug 2015 16:23:29 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/marvin-roger" aria-label="Profile: Marvin-Roger">@<bdi>Marvin-Roger</bdi></a> One suggestion, I would move the gw.getConfig() request into the setup function, rather than in the loop.  Unless you are frequently changing whether you want results in F or C, requesting it once and storing it in a variable should suffice.</p>
<p dir="auto">Cheers<br />
Al</p>
]]></description><link>https://forum.mysensors.org/post/19584</link><guid isPermaLink="true">https://forum.mysensors.org/post/19584</guid><dc:creator><![CDATA[Sparkman]]></dc:creator><pubDate>Sun, 23 Aug 2015 16:23:29 GMT</pubDate></item><item><title><![CDATA[Reply to getConfig().isMetric not updated correctly on Sun, 23 Aug 2015 12:16:15 GMT]]></title><description><![CDATA[<p dir="auto">No, it would be a workaround, not a real solution.<br />
I know what happens... It's 30°C where I am, which is about 85°F. Well, the first value I received was 85.0, a value that I thought was the Fahrenheit one, but it is not. It appears that +85.0°C is the power-on reset value of the temperature register... <a href="https://github.com/mysensors/Arduino/commit/938ade88232b12e364368e6004e2cf4d31008154" rel="nofollow ugc">which is ignored in the <em>official</em> temp sketch since 17 June, I didn't see</a>.</p>
<p dir="auto">So there is no problem finally!</p>
]]></description><link>https://forum.mysensors.org/post/19571</link><guid isPermaLink="true">https://forum.mysensors.org/post/19571</guid><dc:creator><![CDATA[Marvin Roger]]></dc:creator><pubDate>Sun, 23 Aug 2015 12:16:15 GMT</pubDate></item><item><title><![CDATA[Reply to getConfig().isMetric not updated correctly on Sun, 23 Aug 2015 02:00:45 GMT]]></title><description><![CDATA[<p dir="auto">i think you need add ||| metric = gw.getConfig().isMetric; ||| in void setup and declare ||| boolean metric = true; |||</p>
]]></description><link>https://forum.mysensors.org/post/19562</link><guid isPermaLink="true">https://forum.mysensors.org/post/19562</guid><dc:creator><![CDATA[ch3b7]]></dc:creator><pubDate>Sun, 23 Aug 2015 02:00:45 GMT</pubDate></item></channel></rss>