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. Use of mqtt gateway from other sensors

Use of mqtt gateway from other sensors

Scheduled Pinned Locked Moved OpenHAB
6 Posts 3 Posters 3.1k 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.
  • staehlerS Offline
    staehlerS Offline
    staehler
    wrote on last edited by staehler
    #1

    Hi,
    is it possible to use the mqtt broker (on mqtt-gateway) to post messages from sensor different to mysensors? I have some sensors on my homeserver and want to post this messages to the broker as well, which should be processed by openhab.
    With
    mosquitto_pub -h ...
    I had no success :-(

    First: when I connect via mosquitto_sub to the mysensors broker, the connection to openhab terminates and doesn't reconnect. This message appears immediately in the openhab.log:

    > 2015-09-16 16:06:19.584 [ERROR] [o.i.t.m.i.MqttBrokerConnection] - MQTT connection to broker was lost
    > org.eclipse.paho.client.mqttv3.MqttException: Unerwarteter Fehler
    >         at org.eclipse.paho.client.mqttv3.internal.CommsReceiver.run(CommsReceiver.java:115) ~[na:na]
    >         at java.lang.Thread.run(Thread.java:745) [na:1.7.0_79]
    > 2015-09-16 16:06:19.585 [ERROR] [o.i.t.m.i.MqttBrokerConnection] - MQTT connection to 'mysensor' was lost: Unerwarteter Fehler : ReasonCode 6 : Cause : Unknown
    > 2015-09-16 16:06:19.585 [INFO ] [o.i.t.m.i.MqttBrokerConnection] - Starting connection helper to periodically try restore connection to broker 'mysensor'
    > 2015-09-16 16:06:29.586 [INFO ] [o.i.t.m.i.MqttBrokerConnection] - Starting MQTT broker connection 'mysensor'
    

    This must be a bug, as a mosquitto server doesn't show this behaviour. openhab doesn't loose its connection to the mosquitto server, even when I subscribe with mosquitto_sub.

    Second: when I start a mosquitto_pub, openhab looses its connection to mysensors mqtt broker as well. Same error as above.

    Third: When I publish a message to the broker ignoring the error on openhab

    /usr/bin/mosquitto_pub -h 192.168.2.10 -p 1883 -t MyMQTT/19/1/V_TEMP -m 23
    

    I see this in the mosquitto_sub terminal

    Client mosqsub/28854-server received CONNACK
    Client mosqsub/28854-server sending SUBSCRIBE (Mid: 2, Topic: MyMQTT/#, QoS: 0)
    Client mosqsub/28854-server received SUBACK
    Subscribed (mid: 2): 0
    

    A regular message from a sensor looks like:

    Client mosqsub/27168-server received PUBLISH (d0, q0, r0, m0, 'MyMQTT/22/0/V_HUM', ... (4 bytes))
    MyMQTT/22/0/V_HUM 50.9
    

    What am I doing wrong?

    To First und Second I fear. there is a bug.
    To Third I have no idea, why I can not post a mqtt message.

    Would be very nice, if someone could have a look at it or give me a hint.

    Michael

    1 Reply Last reply
    0
    • TD22057T Offline
      TD22057T Offline
      TD22057
      Hardware Contributor
      wrote on last edited by
      #2

      The issue is probably that that the MQTT broker gateway is an extremely limited implementation because of space/cpu issues on the Arduino. I'd recommend that you run a regular mosquitto instance as your primary message broker and connect everything through that. So the MySensors gateway is a client of the mosquitto broker and openhab and everything else is connected through mosquitto. If you want to use the MQTT broker gateway, then look up "mosquitto bridge" which will let you connect the mosquitto broker to the MySensors broker. if you want to use the MQTT client gateway (which I would recommend), then you can point it at the mosquitto broker like any normal client.

      1 Reply Last reply
      0
      • staehlerS Offline
        staehlerS Offline
        staehler
        wrote on last edited by
        #3

        Thanks a lot for your advice. I'm quite newbe. What does it mean, to go your recommended way: "use the MQTT client gateway (which I would recommend), then you can point it at the mosquitto broker like any normal client"
        Is there a switch or forward server IP I have to give the mysensors mqtt-gateway code. How can I convert the mysensors mqtt server to mqtt client, which forwards to mosquitto broker?

        1 Reply Last reply
        0
        • TD22057T Offline
          TD22057T Offline
          TD22057
          Hardware Contributor
          wrote on last edited by
          #4

          Sorry - there are 2 gateway implementations that use MQTT. The first one is MQTTGateway and implements a very limited broker interface. Only a limited number of clients can connect and they can't limit what they subscribe to. It's only designed to interface with controllers using MQTT and isn't a general purpose broker.

          The second one is on the development branch (go to MySensors github, click the branch menu, and select Development) and is named MQTTClientGateway. It's a gateway that is an MQTT client so it publishes to and subscribes from a regular MQTT broker like mosquitto.

          The first one is useful for people who want to use a controller that uses MQTT but aren't using MQTT for anything else. The second one is better for everything else (in my opinion). In the MQTTClientGateway, you give the IP and port number of your MQTT broker and it publishes sensor values and subscribes to actuator commands. So I would recommend that you download the development branch and use that one instead.

          1 Reply Last reply
          0
          • staehlerS Offline
            staehlerS Offline
            staehler
            wrote on last edited by staehler
            #5

            Great, I'm going to follow your advice. Hopefully with no further questions ;-)
            Thanks a lot for your help!

            I assume, you mean this
            https://github.com/mysensors/Arduino/tree/development/libraries/PubSubClient/examples/mqtt_publish_in_callback
            as I coulnd't find anything else, which would match better your explanation, right?

            AWIA 1 Reply Last reply
            0
            • staehlerS staehler

              Great, I'm going to follow your advice. Hopefully with no further questions ;-)
              Thanks a lot for your help!

              I assume, you mean this
              https://github.com/mysensors/Arduino/tree/development/libraries/PubSubClient/examples/mqtt_publish_in_callback
              as I coulnd't find anything else, which would match better your explanation, right?

              AWIA Offline
              AWIA Offline
              AWI
              Hero Member
              wrote on last edited by
              #6

              @staehler try this ;-)

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


              35

              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