Skip to content
  • MySensors
  • OpenHardware.io
  • Categories
  • Recent
  • Tags
  • Popular
Skins
  • Light
  • Brite
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Brand Logo
  1. Home
  2. Bug Reports
  3. getConfig().isMetric not updated correctly

getConfig().isMetric not updated correctly

Scheduled Pinned Locked Moved Bug Reports
7 Posts 4 Posters 4.5k Views 2 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • Marvin RogerM Offline
    Marvin RogerM Offline
    Marvin Roger
    wrote on last edited by
    #1

    Hey,

    I just started to create a MySensors controller, and I face a problem relating the metric/imperial config, using this sketch:

    #include <SPI.h>
    #include <EEPROM.h>
    #include <MySensor.h>
    #include <DallasTemperature.h>
    #include <OneWire.h>
    
    #define TEMPERATURE_ID 1
    
    #define ONE_WIRE_BUS 4
    #define TEMPERATURE_INTERVAL 120
    
    OneWire oneWire(ONE_WIRE_BUS);
    DallasTemperature temperatureSensors(&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 >= TEMPERATURE_INTERVAL * 1000UL) {
        temperatureSensors.requestTemperaturesByIndex(0); 
        float temperature = static_cast<float>(static_cast<int>((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& receivedMessage) {
    }
    

    Once the controller receives the I_CONFIG message, it replies with a M to indicate we want a value in Celcius. I am an hundred percent sure the reply is received by the sensor.
    The first value is sent after two minutes, so the sensor has received and processed the I_CONFIG before sending out its first value.

    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 isMetric is not updated, even after having received the config from the controller, until the first send. This happens after each reboot of the sensor.
    Maybe I am missing something?

    Thanks for your answers.

    1 Reply Last reply
    0
    • ch3b7C Offline
      ch3b7C Offline
      ch3b7
      wrote on last edited by
      #2

      i think you need add ||| metric = gw.getConfig().isMetric; ||| in void setup and declare ||| boolean metric = true; |||

      1 Reply Last reply
      0
      • Marvin RogerM Offline
        Marvin RogerM Offline
        Marvin Roger
        wrote on last edited by
        #3

        No, it would be a workaround, not a real solution.
        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... which is ignored in the official temp sketch since 17 June, I didn't see.

        So there is no problem finally!

        SparkmanS 1 Reply Last reply
        0
        • Marvin RogerM Marvin Roger

          No, it would be a workaround, not a real solution.
          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... which is ignored in the official temp sketch since 17 June, I didn't see.

          So there is no problem finally!

          SparkmanS Offline
          SparkmanS Offline
          Sparkman
          Hero Member
          wrote on last edited by Sparkman
          #4

          @Marvin-Roger 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.

          Cheers
          Al

          1 Reply Last reply
          0
          • hekH Offline
            hekH Offline
            hek
            Admin
            wrote on last edited by
            #5

            Calling getConfig() only returns a cached copy of the config requested by node at startup (or from eeprom if the request failed).

            Requested here:
            https://github.com/mysensors/Arduino/blob/master/libraries/MySensors/MySensor.cpp#L279

            And reply is handled here:
            https://github.com/mysensors/Arduino/blob/master/libraries/MySensors/MySensor.cpp#L697

            So the node is always handling incoming CONFIG updates (when awake).
            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.

            Currently there aren't any API function exposed to re-request this during runtime. I can't imagine many switches between Metric/Imperial frequently.

            SparkmanS 1 Reply Last reply
            0
            • hekH hek

              Calling getConfig() only returns a cached copy of the config requested by node at startup (or from eeprom if the request failed).

              Requested here:
              https://github.com/mysensors/Arduino/blob/master/libraries/MySensors/MySensor.cpp#L279

              And reply is handled here:
              https://github.com/mysensors/Arduino/blob/master/libraries/MySensors/MySensor.cpp#L697

              So the node is always handling incoming CONFIG updates (when awake).
              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.

              Currently there aren't any API function exposed to re-request this during runtime. I can't imagine many switches between Metric/Imperial frequently.

              SparkmanS Offline
              SparkmanS Offline
              Sparkman
              Hero Member
              wrote on last edited by
              #6

              @hek Thanks for clarifying!

              Cheers
              Al

              1 Reply Last reply
              0
              • Marvin RogerM Offline
                Marvin RogerM Offline
                Marvin Roger
                wrote on last edited by
                #7

                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.

                1 Reply Last reply
                0
                Reply
                • Reply as topic
                Log in to reply
                • Oldest to Newest
                • Newest to Oldest
                • Most Votes


                19

                Online

                11.7k

                Users

                11.2k

                Topics

                113.1k

                Posts


                Copyright 2025 TBD   |   Forum Guidelines   |   Privacy Policy   |   Terms of Service
                • Login

                • Don't have an account? Register

                • Login or register to search.
                • First post
                  Last post
                0
                • MySensors
                • OpenHardware.io
                • Categories
                • Recent
                • Tags
                • Popular