MQTT Support
-
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')@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.
-
I've added support for username and password (in theory). It should be available in the next version.
-
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" -
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" -
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.logThen 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 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.logThen 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
-
@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.
-
Does this look correct?
in_prefix='mygateway1-out', out_prefix='mygateway1-in'Shouldn't that be reversed?
-
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.