Page 13 of 17

Re: MQTT Client

Posted: Fri Oct 20, 2017 8:08 pm
by wawa79
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!

Re: MQTT Client

Posted: Fri Oct 20, 2017 11:39 pm
by Snowbird
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.

Re: MQTT Client

Posted: Sun Oct 22, 2017 5:07 pm
by wawa79
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!

Re: MQTT Client

Posted: Tue Oct 24, 2017 6:50 pm
by Septik
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.

Mqtt volume control

Posted: Tue Feb 13, 2018 8:24 pm
by livioavalle
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.

Re: MQTT Client

Posted: Fri Mar 30, 2018 9:18 pm
by wawa79
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!

Re: MQTT Client

Posted: Sat Mar 31, 2018 6:11 am
by Snowbird
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 ?

Re: MQTT Client

Posted: Sat Mar 31, 2018 4:16 pm
by wawa79
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

Re: MQTT Client

Posted: Sun Apr 01, 2018 1:18 am
by kgschlosser
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.

Re: MQTT Client

Posted: Sun Apr 01, 2018 1:24 am
by kgschlosser
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.

Re: MQTT Client

Posted: Sun Apr 01, 2018 7:58 am
by Snowbird
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 ! :)

Re: MQTT Client

Posted: Tue Apr 10, 2018 7:58 am
by alonmalka
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

Re: MQTT Client

Posted: Tue Apr 10, 2018 8:36 am
by Snowbird
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)

Re: MQTT Client

Posted: Tue Apr 10, 2018 8:58 am
by alonmalka
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?

Re: MQTT Client

Posted: Tue Apr 10, 2018 9:33 am
by Snowbird
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 ?