set Metric on gw?



  • 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.


  • Admin

    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



  • 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;?
    


  • 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.



  • 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
    


  • 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?



  • @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")
    
    

Log in to reply
 

Suggested Topics

58
Online

11.4k
Users

11.1k
Topics

112.7k
Posts