MQTT Support



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


  • Mod

    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


  • Plugin Developer

    @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


  • Plugin Developer

    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')
    

  • Mod

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


  • Plugin Developer

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


  • Plugin Developer

    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"


  • Mod

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



  • 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





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


  • Plugin Developer

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


  • Plugin Developer

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

    Shouldn't that be reversed?


  • Plugin Developer

    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.


Log in to reply
 

Suggested Topics

  • 6
  • 4
  • 6
  • 3
  • 55
  • 5

0
Online

11.4k
Users

11.1k
Topics

112.7k
Posts