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. Controllers
  3. OpenHAB
  4. openhab sendCommand problem with serialbinding (Solved)

openhab sendCommand problem with serialbinding (Solved)

Scheduled Pinned Locked Moved OpenHAB
4 Posts 3 Posters 4.6k Views 3 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.
  • S Offline
    S Offline
    shasha
    wrote on last edited by shasha
    #1

    Hello

    I did not find the solution for the loopback problem:

    when I use sendCommand with serialbinding the message is sent to the gateway.
    but at the same time this message is presented as an incoming message to openhab.

    so this message is processed again and creates a deathloop.

    I tried to move the sendCommand from the processing incoming message rule to a separate one
    but the problem is the same. With this new code I use cron so the message does not come immediately
    but the loop is still here.

    I could set up a workaround but I would like to know if there is a clean solution ?
    Is it the way the rule are working ? Is it due to serialbinding ? I tried to have a look at the serial binding code
    but did not find what could create the loopback.

    Help help thank you for your support !

    here is the code :

    //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 == C_INT ){
                     if(subType == I_TIME ){ 
                            println("Time request from node : " + nodeId)   
                            timeToNodeId = nodeId
                            sendTime = 1
                      }              
                }
            }
    end
    //
    //
    //
    rule "send time"
    when
                   Time cron "0 * * * * ?"
    then
                   if (sendTime == 1) {
                       var Integer time2 = now().getMillis()/1000 +7200
                       sendCommand(Arduino, timeToNodeId+";255;3;0;1;" + time2+"\n") 
                       sendTime = 0 
                   }       
    end
    
    1 Reply Last reply
    0
    • T Offline
      T Offline
      TimO
      Hero Member
      wrote on last edited by
      #2

      OpenHAB is using a message bus and every message send to that bus is received by every one/rule.
      Simply moving the code will not help.

      I think the best way is to differentiate between the request and answer(sendCommand).

      Currently the rule is triggered whenever a message with "subType == I_TIME" is received by openHAB.

      if(subType == I_TIME ){ 
                              println("Time request from node : " + nodeId)   
                              timeToNodeId = nodeId
                              sendTime = 1
                        } 
      

      So, in the code above you need to differ between request and answer. I don't know how the request looks like, so I'm only able to give a hint.

      In the answer the payload of the message is the content of "time", something like 1234567. I suppose the payload in the request differs for example in length, it's shorter I suppose.

      So you could go with:

      if(subType == I_TIME ){ 
                              if(msg.length < 1) {
                                 sendCommand(Arduino, timeToNodeId+";255;3;0;1;" + time2+"\n")
                              }
                        } 
      

      I hope this helps.

      1 Reply Last reply
      0
      • S Offline
        S Offline
        shasha
        wrote on last edited by
        #3

        Thank you for the info

        so all the sendCommand to Arduino I will initiate will be seen again when using a trigger like "Arduino received update".

        The workaround I was thinking is the one you suggested. That is to say to check the payload of the incoming message.

        So this problem is solved !

        Thank you !

        1 Reply Last reply
        0
        • Dave DanD Offline
          Dave DanD Offline
          Dave Dan
          wrote on last edited by
          #4

          @Shasha, have you tried this? https://github.com/openhab/openhab/wiki/Rules#concurrency-guard

          I'm currently trying the same (because I have the same issue) and wondering if you tried this before.

          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