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. General Discussion
  3. set Metric on gw?

set Metric on gw?

Scheduled Pinned Locked Moved General Discussion
7 Posts 3 Posters 3.4k 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.
  • G Offline
    G Offline
    gigaguy
    wrote on last edited by
    #1

    Sorry, I am brand new to MySensors. I see in all the examples there is a gw.getConfig().isMetric

    I know this is a new feature. Trying to figure out how to set this, before I update all my nodes with the metric part just commented out.

    Can I push this setting out from openhab (via SerialGateway)?
    TIA.

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

      The node sends an I_CONFIG request at startup. Create a rule that replies to this (with the same internal I_CONFIG). Payload should be M(etric) or I for imperial.

      http://www.mysensors.org/download/serial_api_14

      1 Reply Last reply
      0
      • G Offline
        G Offline
        gigaguy
        wrote on last edited by gigaguy
        #3

        Guess I should have posted this code initially. I already have that rule in place, and still no luck. (I couldnt get "gw.requestTime(receiveTime)" to work either)

        This is in the setup portion in arduino sketch

          metric = gw.getConfig().isMetric;
        

        Only posted relevant portions of the code. The rule itself works (for V_TEMP, etc), just none of the "internal commands I_*" do.

        var int I_CONFIG = 6
        
        //receiving msg from mysensors gateway
        rule "Arduino sends to Openhab"
            when
                Item Arduino received update
            then
                var String lineBuffer =  Arduino.state.toString.split("\n")
                for (String line : lineBuffer) {
                    var String[] message = line.split(";")
                    var Integer nodeId = new Integer(message.get(0))
                    var Integer childId = new Integer(message.get(1))
                    var Integer msgType = new Integer(message.get(2))
                    var Integer ack = new Integer(message.get(3))
                    var Integer subType = new Integer(message.get(4))
                    var String msg = message.get(5)
        
                   // Internal Command
                    if(msgType == 3){
                        if(subType == I_CONFIG){
                                var String unit
                                unit = "I"
                                //unit = "M"
                                sendCommand(Arduino, nodeId + ";255;3;0;6;" + unit + "\n")
                                println("Updated Sensor Units to " + unit +)
                            }
                        }
                    }
        end
        
        

        This is what openhab is getting when the arduino is reset.

        101;255;3;0;11;Humidity
        0;0;3;0;9;read: 101-101-0 s=255,c=3,t=12,pt=0,l=3:1.0
        101;255;3;0;12;1.0
        0;0;3;0;9;read: 101-101-0 s=0,c=0,t=7,pt=0,l=5:1.4.1
        101;0;0;0;7;1.4.1
        0;0;3;0;9;read: 101-101-0 s=1,c=0,t=6,pt=0,l=5:1.4.1
        101;1;0;0;6;1.4.1
        0;0;3;0;9;read: 101-101-0 s=2,c=0,t=4,pt=0,l=5:1.4.1
        101;2;0;0;4;1.4.1
        0;0;3;0;9;read: 101-101-0 s=3,c=2,t=3,pt=0,l=0:
        101;3;2;0;3;
        0;0;3;0;9;read: 101-101-0 s=1,c=1,t=0,pt=7,l=5:26.0
        101;1;1;0;0;26.0
        0;0;3;0;9;read: 101-101-0 s=0,c=1,t=1,pt=7,l=5:34.0
        101;0;1;0;1;34.0
        

        Shouldnt there be something like

        101;255;3;0;6;?
        
        1 Reply Last reply
        0
        • T Offline
          T Offline
          Tango2
          wrote on last edited by
          #4

          I was able to see the request come into the gw on mine, however I'm not sure how the reply should be structured given the sensor node is 101.

          1 Reply Last reply
          0
          • G Offline
            G Offline
            gigaguy
            wrote on last edited by
            #5

            Ok, it just started working !!!! I created a separate rul for it. So either it doesnt like being mixed in with the other stuff or it doesnt like the == I_CONFIG

            This rule below is working

            rule "Arduino config"
                when
                    Item Arduino received update
                then
                    var String lineBuffer =  Arduino.state.toString.split("\n")
                    for (String line : lineBuffer) {
                        var String[] message = line.split(";")
                        var Integer nodeId = new Integer(message.get(0))
                        var Integer childId = new Integer(message.get(1))
                        var Integer msgType = new Integer(message.get(2))
                        var Integer ack = new Integer(message.get(3))
                        var Integer subType = new Integer(message.get(4))
                        var String msg = message.get(5)
                        // Internal Command
                        if(msgType == 3){
                            if(subType == 6){
                                    var String unit
                                    unit = "I"
                                    //unit = "M"
                                    sendCommand(Arduino, nodeId + ";255;3;0;6;" + unit + "\n")
                                    println("Updated Sensor Units to " + unit +)
                                }
                            }
                       }
            
                end
            
            1 Reply Last reply
            0
            • T Offline
              T Offline
              Tango2
              wrote on last edited by
              #6

              Glad you got yours working. I tried changing the code on mine to see if it would respond, but it didn't. I may have hard coded the sensors to imperial though. I believe mine is catching the I_CONFIG variable, because I would get an output on the console when the sensor started up where I had a println command. Hopefully it was just my syntax that was wrong.

              On another note, can you trigger a "sendCommand" with xxx;255;3;0;6;<I or M> at any time, or can it only be in response to the request from the sensor node?

              G 1 Reply Last reply
              0
              • T Tango2

                Glad you got yours working. I tried changing the code on mine to see if it would respond, but it didn't. I may have hard coded the sensors to imperial though. I believe mine is catching the I_CONFIG variable, because I would get an output on the console when the sensor started up where I had a println command. Hopefully it was just my syntax that was wrong.

                On another note, can you trigger a "sendCommand" with xxx;255;3;0;6;<I or M> at any time, or can it only be in response to the request from the sensor node?

                G Offline
                G Offline
                gigaguy
                wrote on last edited by
                #7

                @Tango2 I had been doing this a different way until I noticed the GW should be able to do it. BTW, It is only working on one node, not sure why :(.

                Anyway, my alternate solution allows be to send "settings: to the nodes. For example, change the loop time or measurement unit.

                This is not the complete code, just the relevant parts (hopefully).

                void setup()  
                { 
                gw.begin(incomingMessage, nodeID);
                }
                void loop()
                {
                    gw.process();  
                }
                void incomingMessage(const MyMessage &message) {
                  if (message.type == 97) {
                    Serial.print("Recvd Time");
                    Serial.println(time);
                    timeReceived=true;  
                  }
                  if (message.type == 98) {
                    int reqsleep = atoi( message.data );
                    SLEEP_TIME = reqsleep*1000;
                    Serial.print( "Changing sleep to: " );
                    Serial.println( String(reqsleep) );
                  }
                  if (message.type == 99) {
                    int requnit = atoi( message.data );
                    Serial.print( "Changing units to: " );
                
                    if(requnit == M){
                      metric = true;
                      Serial.println( "metric" );
                    } else {
                      metric = false;
                      Serial.println( "imprerial" );
                    }          
                  }
                }
                
                

                Using this code, I can send things from openhab, or any serial command I suppose.

                My openhab rules
                Send Units:

                sendCommand(Arduino, "101;99;1;0;99;M\n")
                

                Send Time:

                var Number time1
                time1 = now().getMillis() / 1000
                sendCommand(Arduino, "101;97;1;0;97;" + time1 + "\n")
                
                
                1 Reply Last reply
                0
                Reply
                • Reply as topic
                Log in to reply
                • Oldest to Newest
                • Newest to Oldest
                • Most Votes


                30

                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