Re: MQTT Client
Posted: Tue Mar 08, 2016 5:37 pm
Sorry for the previous post. It is all working fine. I used the wrong IP.
If you get some error message that Paho is missing or something related, try to copy the paho subfolder to /lib26/site-packages folder and restart EG
EDIT: Actually, I think you need to do this, copy or move the paho subfolder with all content as mentioned
Code: Select all
print 'START SENDING'
for i in range(5):
eg.plugins.MQTTthreads.publishMQTT(u'MQTT test',
u'localhost',
1883,
u'/openHAB/in/ECL_mN2_Chambre_chevetp/state',
str(i),
0,
False)
print 'COMPLETED'
No, it is not, it looks like the client is being kicked out every twenty secondsIs this normal behaviour?
You cannot send the events that fast I think, try to insert a short time.sleep(0.1) in you script (modification below is for the paho version and my configuration but you get the idea)not to trigger eg events when sent repeateadly
Code: Select all
import time
print 'START SENDING'
for i in range(5):
eg.plugins.MQTTthreads.publishMQTT(u'MQTT test',
u'192.168.10.248',
1883,
u'/zwave',
str(i),
0,
False,
'691760406161'
)
time.sleep(0.1)
print 'COMPLETED'
08:35:52 MQTT./zwave u"4"
08:35:53 MQTT./zwave u"Device_6_Instance_3_temperature, 21.3700016"
08:35:53 START SENDING
08:35:54 COMPLETED
08:35:54 MQTT./zwave u"0"
08:35:54 MQTT./zwave u"1"
08:35:54 MQTT./zwave u"2"
08:35:54 MQTT./zwave u"3"
08:35:54 MQTT./zwave u"Device_6_Instance_4_temperature, 22.43"
08:35:54 MQTT./zwave u"4"
08:35:55 START SENDING
08:35:56 COMPLETED
08:35:56 MQTT./zwave u"0"
08:35:56 MQTT./zwave u"1"
08:35:56 MQTT./zwave u"2"
08:35:56 MQTT./zwave u"3"
08:35:56 MQTT./zwave u"4"
08:35:56 RFXtrx.Type: RTHN318 id: 7425 ' temperature: +13.2 deg C signal: 6 battery: 9'
08:35:57 START SENDING
08:35:58 COMPLETED
08:35:58 MQTT./zwave u"0"
08:35:58 MQTT./zwave u"1"
08:35:58 MQTT./zwave u"2"
08:35:58 MQTT./zwave u"3"
08:35:58 MQTT./zwave u"4"
08:35:59 START SENDING
08:36:00 COMPLETED
08:36:00 MQTT./zwave u"0"
08:36:00 MQTT./zwave u"1"
08:36:00 MQTT./zwave u"2"
08:36:00 MQTT./zwave u"3"
08:36:00 MQTT./zwave u"4"
08:36:01 SunTracker.Weather Condition: 'Fair'
08:36:06 RFXtrx.Type: THGN122/123, THGN132, THGR122/228/238/268 id: 1796 ' temperature: +10.0 deg C humidity: 50 %RH status: normal signal: 6 battery: 9'
08:36:06 MQTT.out u"['event', 'Oregon_Message', 'Direction', 'In', 'Oregon.Channel', '4', 'Oregon.Id', '112', 'Oregon.LowBattery', '0', 'Oregon.Moisture', '50', 'Oregon.SensorId', '7456', 'Oregon.Temp', '100', 'Value', '']"
Hello Walter,krambriw wrote:You cannot send the events that fast I think, try to insert a short time.sleep(0.1) in you script (modification below is for the paho version and my configuration but you get the idea)not to trigger eg events when sent repeateadly
You are right: openHab uses 2 topics for MQTT communication. One openhab/in/# for inbound traffic and one openhab/out/# for outbound traffic.krambriw wrote:Do you have to publish and subscribe to the same topic? Maybe that is conflicting in your setup with openHAB? You could eventually try to have separate topics for sending & receiving.
Walter, the issue is independant from OpenHAB. Just see the xml test I sent earlier. If you click repeatedly on the [TEST] button for that script, you do not see all the corresponding Eg events display in the log : some are missed. On my side, this happens on all the PC on which I run that script.krambriw wrote:On the other hand, as you saw, I could without problem publish to the same topic as I subscribed to. I do not use openHAB so I cannot reproduce the errors and I have never heard other users having the same problem..
I understand the general threading layout which sounds to be the robust construction for this plugin but there should be some side effect we miss that is causing the behaviour of "lost messages"krambriw wrote: Regarding the code under the hood:
- there is a separate thread handling subscriptions (receiving of events) so it should not be possible to interfere
- when publishing /(sending a message) a new client connection is opened and then closed
I don't think so: it behaves the same when the MQTT server is running on the same computer as the MQTT clients so there is no connection drop effect in that case. Or should there be any OS or network adapter mechanism that drops connection?krambriw wrote: I think the problem is related to that your connection only lasts 20 seconds, this is not a normal behavior. The normal is that the connection is kept steady until it is closed on purpose.
Code: Select all
06:19:47 START SENDING
06:19:48 COMPLETED
06:19:48 MQTT.openhab/out u"0"
06:19:48 MQTT.openhab/out u"1"
06:19:48 MQTT.openhab/out u"2"
06:19:48 MQTT.openhab/out u"3"
06:19:48 MQTT.openhab/out u"4"
06:19:51 START SENDING
06:19:52 COMPLETED
06:19:52 MQTT.openhab/out u"0"
06:19:52 MQTT.openhab/out u"1"
06:19:52 MQTT.openhab/out u"2"
06:19:52 MQTT.openhab/out u"3"
06:19:52 MQTT.openhab/out u"4"
06:19:54 START SENDING
06:19:55 COMPLETED
06:19:55 MQTT.openhab/out u"0"
06:19:55 MQTT.openhab/out u"1"
06:19:55 MQTT.openhab/out u"2"
06:19:55 MQTT.openhab/out u"3"
06:19:55 MQTT.openhab/out u"4"
06:19:58 START SENDING
06:19:59 COMPLETED
06:19:59 RFXtrx.Type: RTHN318 id: 7425 ' temperature: +6.4 deg C signal: 6 battery: 9'
06:19:59 MQTT.openhab/out u"0"
06:19:59 MQTT.openhab/out u"1"
06:19:59 MQTT.openhab/out u"2"
06:19:59 MQTT.openhab/out u"3"
06:19:59 MQTT.openhab/out u"4"
I am running Mosquitto broker on the same computer as the one running Eg. It is a Win10 OSkrambriw wrote:Hello,
1) Where do you run the MQTT broker and what OS is used in that environment?
I tested with test.mosquitto.org and got same results: Eg generating events ramdomly when received back from the broker.krambriw wrote:2) Could you try to connect and test to another broker, try the public available and see if you experience the same problem when running your test script from EG?
test.mosquitto.org. Below is from my test using that broker, I do not miss any event.
Since the simple test script you provided works for me but not for you, I for the moment believe there must something in your environment that is causing this problemHow can I add some clever 'print' command in your plugin to see if Mqtt messages are actually received and if it is only a matter of event generation in Eg?
Code: Select all
def on_message(client, userdata, msg):
print client, userdata, msg.payload
Below the result of the test with the logging you suggested.krambriw wrote: To add a print statement you could try (search for line 222) and add the print statement as below:
Code: Select all
def on_message(client, userdata, msg): print client, userdata, msg.payload
Code: Select all
19:57:02 MQTT./openHAB/in/AV_mRDC_Salon_media_album/state u"02"
19:57:02 <paho.mqtt.client.Client object at 0x0500D7B0> None 02
19:57:03 <paho.mqtt.client.Client object at 0x0500D7B0> None 03
19:57:04 MQTT./openHAB/in/AV_mRDC_Salon_media_album/state u"03"
19:57:04 <paho.mqtt.client.Client object at 0x0500D7B0> None 04
19:57:04 MQTT./openHAB/in/AV_mRDC_Salon_media_album/state u"04"
19:57:04 <paho.mqtt.client.Client object at 0x0500D7B0> None 04
19:57:04 <paho.mqtt.client.Client object at 0x0500D7B0> None 04
19:57:04 <paho.mqtt.client.Client object at 0x0500D7B0> None 04
19:57:05 <paho.mqtt.client.Client object at 0x0500D7B0> None 05
19:57:06 MQTT./openHAB/in/AV_mRDC_Salon_media_album/state u"05"