MQTT Client

Questions and comments specific to a particular plugin should go here.
wawa79
Posts: 25
Joined: Fri Nov 02, 2012 11:01 pm

Re: MQTT Client

Post by wawa79 » Fri Oct 20, 2017 8:08 pm

Hello Walter,

In this topic I had endless connection/deconnection loop with your Paho-based plugin and my warkaround was... to stick to the old Mosquitto-based one.

I just found the issue with the Paho plugin when posting this post (this is why it has been edited): to create a 2nd subscription, I copy/paste the 1st one which results in the 2 subscription to have same MQTT-clientID. When changing the MQTT-clientID to different values, I no longer get the problem.

Below is a the Eg config that subscribes 2 topics on test.mosquitto.org broker and produces the looping behavior. I let you tell if this is normal behavior as per MQTT spec or if it a bug.

Code: Select all

<?xml version="1.0" encoding="UTF-8" ?>
<EventGhost Version="1722" Guid="{40F7E6BE-17C0-44C6-9B54-954ECA0AB06A}" Time="1508530026.72">
    <Autostart Name="Autostart" Expanded="True">
        <Plugin Identifier="MQTTthreads" Guid="{D5CCABA6-8E20-4B59-A7A7-9C197F91037F}" File="MQTT Client">
            gAIpLg==
        </Plugin>
    </Autostart>
    <Folder Name="&lt;unnamed folder&gt;" Expanded="True">
        <Macro Name="MQTT Client: Start a new MQTT subscription " Expanded="True">
            <Action Name="Subscribe topic1">
                MQTTthreads.MQTTclient(u'topic1', u'test.mosquitto.org', 1883, u'eg_topic1', False, '979305467018', False, False, u'username', u'password', False, u'', u'', u'', u'TLSv1.2')
            </Action>
            <Action Name="Subscribe topic2">
                MQTTthreads.MQTTclient(u'topic2', u'test.mosquitto.org', 1883, u'eg_topic2', False, '979305467018', False, False, u'username', u'password', False, u'', u'', u'', u'TLSv1.2')
            </Action>
        </Macro>
    </Folder>
</EventGhost>
Thank you in advance!

Snowbird
Experienced User
Posts: 286
Joined: Fri Jul 03, 2009 10:04 am

Re: MQTT Client

Post by Snowbird » Fri Oct 20, 2017 11:39 pm

Hi,

you just need to change the ID, you are using the same ID twice "979305467018", that's why it is looping, just change it to whatever you want, for example "123451234" it doesn't matter as long as you use it once and only once.

wawa79
Posts: 25
Joined: Fri Nov 02, 2012 11:01 pm

Re: MQTT Client

Post by wawa79 » Sun Oct 22, 2017 5:07 pm

Snowbird wrote:
Fri Oct 20, 2017 11:39 pm
Hi,

you just need to change the ID, you are using the same ID twice "979305467018", that's why it is looping, just change it to whatever you want, for example "123451234" it doesn't matter as long as you use it once and only once.
You probably replied before I edited my post. Thank you for the support!

Septik
Posts: 37
Joined: Sun Feb 15, 2015 1:29 pm

Re: MQTT Client

Post by Septik » Tue Oct 24, 2017 6:50 pm

krambriw wrote:
Thu Oct 19, 2017 5:29 pm
Hi there, yeah it is easy to forget minor details,

I think it will work for you but you have to give each subscription a unique name. Like in this example, they are simply named 1,2,3,4 and all are connected to an external broker

Hope this helps,
Kind regards, Walter
Hey again.

Finally found time to play around with this again. After reading other comments, it seems like I maybe was using the same ID twice (by using the same "action" to add each subscription). This time, however, I'm unable to subscribe at all, although the plugin seems to think it's subscribing a thousand times! :p

Image

Edit: Not sure what was wrong, but after reconfiguring Home Assistant to use CloudMQTT instead of the local broker, I'm not having these issues. Might have been an error in my configuration then rather than in your plugin.

livioavalle
Posts: 1
Joined: Tue Feb 13, 2018 8:19 pm

Mqtt volume control

Post by livioavalle » Tue Feb 13, 2018 8:24 pm

Hi, i need your help.
I've installed eventghost and mqtt plugin. i have a mqtt server that work.
I want to make a macro that read a number from a mqtt topic and then set the volume with this number.
example. i publish 50 on the mqtt topic, the macro read the 50 number and set volume to 50. but i donth know how to set up. Can anyone help me?
I use windows 10
Thank you.

wawa79
Posts: 25
Joined: Fri Nov 02, 2012 11:01 pm

Re: MQTT Client

Post by wawa79 » Fri Mar 30, 2018 9:18 pm

Hello,

I experienced a bug due to an unhandled error in MQTT plugin. This is caused by a corrupted message received and not the plugin itself.
But failure in handling this corrupted message crashed both instances of MQTT plugin threads that were running on 2 machines.
It would be nice if receiving corrupted data resulted in a restart of the thread after its termination to keep the plugin listening to all topics subscribed.

Code: Select all

22:48:41   Exception in thread OpenHAB topic:
22:48:41   Traceback (most recent call last):
22:48:41     File "threading.pyc", line 801, in __bootstrap_inner
22:48:41     File "C:\ProgramData\EventGhost\plugins\MQTT Client\__init__.py", line 521, in run
22:48:41       lrsp = mqttc.loop(10.0, 1)
22:48:41     File "C:\ProgramData\EventGhost\plugins\MQTT Client\paho\mqtt\client.py", line 1004, in loop
22:48:41       rc = self.loop_read(max_packets)
22:48:41     File "C:\ProgramData\EventGhost\plugins\MQTT Client\paho\mqtt\client.py", line 1282, in loop_read
22:48:41       rc = self._packet_read()
22:48:41     File "C:\ProgramData\EventGhost\plugins\MQTT Client\paho\mqtt\client.py", line 1847, in _packet_read
22:48:41       rc = self._packet_handle()
22:48:41     File "C:\ProgramData\EventGhost\plugins\MQTT Client\paho\mqtt\client.py", line 2294, in _packet_handle
22:48:41       return self._handle_publish()
22:48:41     File "C:\ProgramData\EventGhost\plugins\MQTT Client\paho\mqtt\client.py", line 2465, in _handle_publish
22:48:41       self._handle_on_message(message)
22:48:41     File "C:\ProgramData\EventGhost\plugins\MQTT Client\paho\mqtt\client.py", line 2612, in _handle_on_message
22:48:41       self.on_message(self, self._userdata, message)
22:48:41     File "C:\ProgramData\EventGhost\plugins\MQTT Client\__init__.py", line 382, in on_message
22:48:41       ProcessEvent(msg, False, 0.0, res_key, event)
22:48:41     File "C:\ProgramData\EventGhost\plugins\MQTT Client\__init__.py", line 272, in ProcessEvent
22:48:41       TriggerEvent(msg)
22:48:41     File "C:\ProgramData\EventGhost\plugins\MQTT Client\__init__.py", line 253, in TriggerEvent
22:48:41       pl = str(msg.payload).decode('utf-8')
22:48:41     File "encodings\utf_8.pyc", line 16, in decode
22:48:41   UnicodeDecodeError: 'utf8' codec can't decode byte 0xe9 in position 3: invalid continuation byte
Thank you in advance!

Snowbird
Experienced User
Posts: 286
Joined: Fri Jul 03, 2009 10:04 am

Re: MQTT Client

Post by Snowbird » Sat Mar 31, 2018 6:11 am

This plugin is one of the most stable around, I've been using it for almost a year daily and never experienced what you are describing. It must be a very rare situation, the error you got is about character encoding/decoding, UTF-8 is the most used and compatible character set. Can you reproduce this easily ? I mean how can I generate a corrupted message to get the same error as you ?

wawa79
Posts: 25
Joined: Fri Nov 02, 2012 11:01 pm

Re: MQTT Client

Post by wawa79 » Sat Mar 31, 2018 4:16 pm

Snowbird wrote:
Sat Mar 31, 2018 6:11 am
This plugin is one of the most stable around, I've been using it for almost a year daily and never experienced what you are describing. It must be a very rare situation, the error you got is about character encoding/decoding, UTF-8 is the most used and compatible character set. Can you reproduce this easily ? I mean how can I generate a corrupted message to get the same error as you ?
For sure, the plugin is very stable: I have been using it for years also in my home automation setup 7/7d 24/24h.

First time I see this and I cannot reproduce it. Probably adding an error handler on utf8 decoding would be enough to avoid the thread to stop. Something like:

Code: Select all

try:
	pl = None
	pl = str(msg.payload).decode('utf-8')
except:
	pass
finally:
	if pl <> None:
		#continue processing of MQTT message here

User avatar
kgschlosser
Site Admin
Posts: 3693
Joined: Fri Jun 05, 2015 5:43 am
Location: Rocky Mountains, Colorado USA

Re: MQTT Client

Post by kgschlosser » Sun Apr 01, 2018 1:18 am

I have updated the plugin with exception catching and a little better unicode decoding. I have done this for all places where any decoding was done.

The updated version is attached.
Attachments
MQTT Client_v1.2.2.egplugin
(70.13 KiB) Downloaded 30 times
If you like the work I have been doing then feel free to Image

User avatar
kgschlosser
Site Admin
Posts: 3693
Joined: Fri Jun 05, 2015 5:43 am
Location: Rocky Mountains, Colorado USA

Re: MQTT Client

Post by kgschlosser » Sun Apr 01, 2018 1:24 am

I believe that krambriw is no longer supporting this plugin. It has been over 30 days since he has logged in. I am not 100% sure on this as there has been questions that have been asked from even before his last login.

I know nothing of MQTT but I will make alterations on problems that contain an error.
If you like the work I have been doing then feel free to Image

Snowbird
Experienced User
Posts: 286
Joined: Fri Jul 03, 2009 10:04 am

Re: MQTT Client

Post by Snowbird » Sun Apr 01, 2018 7:58 am

you're right krambriw is not supporting this plugin anymore, a few months ago he said that he was going to do some other things (not EG related). But, he was still around off and on until a few weeks ago, and he kindly worked on his plugin and updated it a couple of times even though he said he wouldn't be here anymore. So don't be surprised if he pops in at some point, he could even update his plugin once more ! :)

alonmalka
Posts: 27
Joined: Wed Dec 04, 2013 10:07 am

Re: MQTT Client

Post by alonmalka » Tue Apr 10, 2018 7:58 am

Hi,

I started using this plugin in order to broadcast messages to Raspberry Pi. I use it to trigger actions in home assistant.
The thing is, it takes about 2.5 seconds from the moment I send the message via MQTT until the light turns on. When I sent the MQTT message through mqtt.fx which is just a program running under windows to send MQTT messages, The light turned on under a second.
I seems the EG client establishes a connection each time I send the message. Any idea how to fix it?

Thanks,
Alon

Snowbird
Experienced User
Posts: 286
Joined: Fri Jul 03, 2009 10:04 am

Re: MQTT Client

Post by Snowbird » Tue Apr 10, 2018 8:36 am

This is strange, it shouldn't take this long... I usually get a couple of hundred milliseconds. EG keeps the connection opened only if you are subscribed to a topic, if you just use EG to publish messages the connection is made to the mqtt broker just during the publishing time (very short time). So this is normal behavior and there's nothing to fix.

If you want to see if a specific port is open to check if a connection is established, run this command :
in windows : netstat -ano
in linux : netstat -laputen

and check for the MQTT port 1883 or 8883 (TLS)

alonmalka
Posts: 27
Joined: Wed Dec 04, 2013 10:07 am

Re: MQTT Client

Post by alonmalka » Tue Apr 10, 2018 8:58 am

So what you are saying is that I don't need to be subscribed and I can just publish a message and that anyway it shouldn't take so long like I described?

Snowbird
Experienced User
Posts: 286
Joined: Fri Jul 03, 2009 10:04 am

Re: MQTT Client

Post by Snowbird » Tue Apr 10, 2018 9:33 am

Well I'm not saying anything in particular, just trying to tell you that it's normal to connect/disconnect every time a message is published, I was just confirming what you were wondering about.

So if I understand well, if you publish this way :
EG mqtt plugin --> RPi --> HomeAssistant --> Light (it takes 2.5 seconds)

and if you do it that way :
Windows mqtt.fx program --> RPi --> HomeAssistant --> Light (it takes less than 1 second)

Did I get it right ?

Post Reply