Sending I_CONFIG to set unit of measure on sensor nodes



  • I tried asking this on the OpenHAB forums, but I haven't received any feedback. I'm having problems properly sending the I_CONFIG value to my sensors.

    Below is my "Arduino sends to Openhab" rule that I've added the I_CONFIG variable to:

    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)
    if(msgType == 1 ){
    if (subType == V_TEMP){ 
    postUpdate(sensorToItemsMap.get( nodeId + ";" + childId + ";"), msg)
    println ("Temp item: " + sensorToItemsMap.get( nodeId + ";" + childId + ";") + " temp: " + msg )
    }
    if (subType == V_HUM){
    postUpdate(sensorToItemsMap.get( nodeId + ";" + childId + ";"), msg)
    println ("Hum item: " + sensorToItemsMap.get( nodeId + ";" + childId + ";") + " hum: " + msg )
    }
    }
    if(msgType == 3){
    if(subType == I_BATTERY_LEVEL){
    postUpdate(sensorToItemsMap.get( nodeId + ";" + childId + ";"), msg)
    println ("Battery level received: " + msg)
    }
    if(subType == I_CONFIG){
    println("Request config units") 
    sendCommand(Arduino, nodeId + ";" + childId + ";" + msgType + ";" + ack + ";" + subType + ";" + core_Units.state + "\n")
    println("Sent measurement units:" + core_Units.state )
    }
    if(subType == I_SKETCH_NAME){
    println("Sketch name: " + msg )
    sketchName=msg
    }
    if(subType == I_SKETCH_VERSION){
    println("Sketch version: " + msg )
    postUpdate(sensorToItemsMap.get( nodeId + ";" + childId + ";"), sketchName+" " +msg )
    sketchName=""
    }
    }
    }
    
    end
    

    In it's current state, the sensor node gets repeated responses from the controller/gateway with the units (I or M), based on the value of the item Core_Units.state. I'm trying to figure out why this doesn't just sendCommand one time to the sensor node. The response received by the sensor node seems correct, I just get hundreds of them. Below is the output from my sensor node after requesting the I_CONFIG value from the controller:

    read: 0-0-105 s=255,c=3,t=6,pt=0,l=1,sg=0:I
    

    This appears correct to me. Any thoughts?


  • Admin

    Yes, it should be picked up here:

    https://github.com/mysensors/Arduino/blob/master/libraries/MySensors/MySensor.cpp#L711-L716

    You could add some debug print in the node to verify that this is the case perhaps.

    The node should normally only ask once when the node starts up:
    https://github.com/mysensors/Arduino/blob/master/libraries/MySensors/MySensor.cpp#L282



  • It seems as if the problem I'm seeing is more with the controller/gateway than with the node. The gateway is sending out the I_CONFIG units repeatedly (like hundreds of times). The node is only requesting the units once.

    That is why I'm not sure if it is a gateway problem or a controller (rules) problem. I can comment out the following section:

    if(subType == I_CONFIG){
    println("Request config units") 
    sendCommand(Arduino, nodeId + ";" + childId + ";" + msgType + ";" + ack + ";" + subType + ";" + core_Units.state + "\n")
    println("Sent measurement units:" + core_Units.state )
    }
    

    and the sensor node is no longer flooded with responses after it asks for config units. I'm just not sure why this is "flooding" the sensor node with responses.


  • Hero Member

    I suppose the rules are triggered, whenever there is a message coming from the gateway or from a sendCommand () call. So this will result in an infinite loop.



  • Eventually, the repeated requests seem to calm down and it works as expected. What I'm trying to figure out is why the repeated messages occur.

    If I'm reading the code correctly, the only time the 'if(subType == I_CONFIG)' should be invoked is when the request for config units is made from the sensor node. I've confirmed that the sensor node only requests the I_CONFIG units once, and the gateway only receives it once. I can't seem to make sense out of why the gateway replies so many times...


  • Hero Member

    If you only comment out the line with "sendCommand()" how often does is the rule triggered? My guess: only once.
    You need to distinguish if you're getting a request from the node or sending an answer.


Log in to reply
 

Suggested Topics

  • 22
  • 4
  • 2
  • 3
  • 7
  • 132

73
Online

11.4k
Users

11.1k
Topics

112.7k
Posts