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. Mozilla WebThings Gateway
  4. MQTT Support

MQTT Support

Scheduled Pinned Locked Moved Mozilla WebThings Gateway
14 Posts 4 Posters 1.2k 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.
  • R Offline
    R Offline
    Ryanmt
    wrote on last edited by
    #1

    Is MQTT support working? I was just installing webthings as an experiment but noticed when selecting MQTT you don't get prompted for the additional settings you would expect?

    It should be asking for the mqtt server address, credentials and topic prefix?

    mfalkviddM 1 Reply Last reply
    0
    • R Ryanmt

      Is MQTT support working? I was just installing webthings as an experiment but noticed when selecting MQTT you don't get prompted for the additional settings you would expect?

      It should be asking for the mqtt server address, credentials and topic prefix?

      mfalkviddM Offline
      mfalkviddM Offline
      mfalkvidd
      Mod
      wrote on last edited by
      #2

      from https://forum.mysensors.org/post/98906

      Now supports not just serial, but also ethernet and MQTT. If anyone can test MQTT I would be very grateful.

      So maybe ping @alowhum

      1 Reply Last reply
      0
      • alowhumA Offline
        alowhumA Offline
        alowhum
        Plugin Developer
        wrote on last edited by
        #3

        @Ryanmt I've never personally tested it. I've simply implemented the PyMysensors library.

        Looking at it in more details, it seems more needs to be done for MQTT support.
        https://github.com/theolind/pymysensors/blob/master/mqtt.py

        1 Reply Last reply
        0
        • alowhumA Offline
          alowhumA Offline
          alowhum
          Plugin Developer
          wrote on last edited by
          #4

          I've tried to add the required code. But as I'm not an MQTT user, I'm not sure I've implemented it properly.

          You mentioned:
          It should be asking for the mqtt server address, credentials and topic prefix?

          • The IP address can be filled in at the same spot where you fill it in for the ethernet gateway.
          • Are credentials required?
          • Topic prefix seems to be hardcoded to the mysensors ones? Right now I have:
                          MQTTC = MQTT(ip_address, 1883, 60)
                          MQTTC.start()
                          
                          #self.GATEWAY = mysensors.AsyncMQTTGateway(ip_address, event_callback=self.mysensors_message, 
                          #    persistence=True, persistence_file=self.persistence_file_path, 
                          #    protocol_version='2.2')
                          
                          self.GATEWAY = mysensors.AsyncMQTTGateway(MQTTC.publish, MQTTC.subscribe, in_prefix='mygateway1-out',
                              out_prefix='mygateway1-in', retain=True, event_callback=event,
                              persistence=True, persistence_file=self.persistence_file_path, 
                              protocol_version='2.2')
          
          mfalkviddM 1 Reply Last reply
          0
          • alowhumA alowhum

            I've tried to add the required code. But as I'm not an MQTT user, I'm not sure I've implemented it properly.

            You mentioned:
            It should be asking for the mqtt server address, credentials and topic prefix?

            • The IP address can be filled in at the same spot where you fill it in for the ethernet gateway.
            • Are credentials required?
            • Topic prefix seems to be hardcoded to the mysensors ones? Right now I have:
                            MQTTC = MQTT(ip_address, 1883, 60)
                            MQTTC.start()
                            
                            #self.GATEWAY = mysensors.AsyncMQTTGateway(ip_address, event_callback=self.mysensors_message, 
                            #    persistence=True, persistence_file=self.persistence_file_path, 
                            #    protocol_version='2.2')
                            
                            self.GATEWAY = mysensors.AsyncMQTTGateway(MQTTC.publish, MQTTC.subscribe, in_prefix='mygateway1-out',
                                out_prefix='mygateway1-in', retain=True, event_callback=event,
                                persistence=True, persistence_file=self.persistence_file_path, 
                                protocol_version='2.2')
            
            mfalkviddM Offline
            mfalkviddM Offline
            mfalkvidd
            Mod
            wrote on last edited by mfalkvidd
            #5

            @alowhum on a MySensors mqtt gateway, username, password and topic prefix can be configured by defines. Since they are configurable on a MySensors gateway, I think it would make sense to also support configuration of these parameters in Webthings gateway.

            1 Reply Last reply
            0
            • alowhumA Offline
              alowhumA Offline
              alowhum
              Plugin Developer
              wrote on last edited by alowhum
              #6

              I've added support for username and password (in theory). It should be available in the next version.

              1 Reply Last reply
              1
              • alowhumA Offline
                alowhumA Offline
                alowhum
                Plugin Developer
                wrote on last edited by
                #7

                I've been trying to test it. I got to the point where in theory it's connected to Mosquitto. But I don't have any MySensors MQTT devices, so nothing is happening after that.

                Could someone help me craft a test message? Something like:

                mosquitto_pub -h localhost -t mygateway1-out -m "4;255;3;0;6;0"

                mfalkviddM 1 Reply Last reply
                0
                • alowhumA alowhum

                  I've been trying to test it. I got to the point where in theory it's connected to Mosquitto. But I don't have any MySensors MQTT devices, so nothing is happening after that.

                  Could someone help me craft a test message? Something like:

                  mosquitto_pub -h localhost -t mygateway1-out -m "4;255;3;0;6;0"

                  mfalkviddM Offline
                  mfalkviddM Offline
                  mfalkvidd
                  Mod
                  wrote on last edited by
                  #8

                  @alowhum I don't use mqtt either, but https://www.mysensors.org/build/mqtt_gateway#setup-and-test-gateway has instructions for how to send a test message. Can you use that?

                  1 Reply Last reply
                  1
                  • bjacobseB Offline
                    bjacobseB Offline
                    bjacobse
                    wrote on last edited by
                    #9

                    I don't use Webthings, but MQTT shall work similar, on my RPI I have Domoticz and Mosquitto broker running, check in a prompt:
                    Is the broker running? ps -ef |grep mosq
                    you can also check the logfile: sudo tail /var/log/mosquitto/mosquitto.log

                    Then if above is ok, then your test message shall appear in the logfile, then Mosquitto is working. Then next check Mosquitto WebThings connection. I would assume a logfile must be present in WebThings that shows if a sensor is providing something

                    bjacobseB 1 Reply Last reply
                    0
                    • bjacobseB bjacobse

                      I don't use Webthings, but MQTT shall work similar, on my RPI I have Domoticz and Mosquitto broker running, check in a prompt:
                      Is the broker running? ps -ef |grep mosq
                      you can also check the logfile: sudo tail /var/log/mosquitto/mosquitto.log

                      Then if above is ok, then your test message shall appear in the logfile, then Mosquitto is working. Then next check Mosquitto WebThings connection. I would assume a logfile must be present in WebThings that shows if a sensor is providing something

                      bjacobseB Offline
                      bjacobseB Offline
                      bjacobse
                      wrote on last edited by
                      #10

                      @bjacobse
                      did you setup Node-RED?
                      Maybe this can help you: https://diyprojects.io/mqtt-mosquitto-communicating-connected-objects-iot/#.XTBAKiZJFCU

                      1 Reply Last reply
                      0
                      • R Offline
                        R Offline
                        Ryanmt
                        wrote on last edited by
                        #11

                        I don't have webthings setup anymore but am happy to spin it up in a docker container and test for you. Just let me know what the steps are to install the test version and i'll give it a go.

                        1 Reply Last reply
                        0
                        • alowhumA Offline
                          alowhumA Offline
                          alowhum
                          Plugin Developer
                          wrote on last edited by
                          #12

                          @Ryanmt thanks, that would be great.

                          I've tried to do some testing. Things look promising.

                          The Paho MQTT client seems to connect to a lot of topics:

                          Started MQTT client
                          subscribing to topicmygateway1-out/+/+/0/+/+
                          subscribing to topicmygateway1-out/+/+/3/+/+
                          subscribing to topicmygateway1-out/7/1/1/+/+
                          subscribing to topicmygateway1-out/7/1/2/+/+
                          subscribing to topicmygateway1-out/7/10/1/+/+
                          subscribing to topicmygateway1-out/7/10/2/+/+
                          subscribing to topicmygateway1-out/7/11/1/+/+
                          subscribing to topicmygateway1-out/7/11/2/+/+
                          

                          etc.

                          Then, this:
                          mosquitto_pub -t 'mygateway1-out/7/1/2/0/47' -m '0,test'
                          gives:
                          Not a valid message: not a valid value for dictionary value @ data['payload']

                          So there is a communication path. I'm just not recreating the correct message.

                          1 Reply Last reply
                          0
                          • alowhumA Offline
                            alowhumA Offline
                            alowhum
                            Plugin Developer
                            wrote on last edited by
                            #13

                            Does this look correct?
                            in_prefix='mygateway1-out', out_prefix='mygateway1-in'

                            Shouldn't that be reversed?

                            1 Reply Last reply
                            0
                            • alowhumA Offline
                              alowhumA Offline
                              alowhum
                              Plugin Developer
                              wrote on last edited by
                              #14

                              I saw the same pattern in the original example code at PyMySensors, so I'm assuming it's ok.

                              I've uploaded version 0.1.2 of the MySensors add-on, Mozilla should accept it in a work day or two.

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


                              18

                              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