Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Paho » Client not connecting(Subscriber does not pickup a topic with retain flag set.)
Client not connecting [message #1764334] Sun, 28 May 2017 11:42 Go to next message
Wim Nijntjes is currently offline Wim NijntjesFriend
Messages: 5
Registered: May 2017
Junior Member
When I run this program it does not pickup the topic "topic_1" if the last line "client.loop_forever()" is not included.

# Run this after the Ptopic_1.py has ran.

---------------------------------------------------------

import time
import paho.mqtt.client as mqtt

client = mqtt.Client()
client.connect("192.168.2.232",1883,60) # IP address of Broker.

def on_connect(client, userdata, flags, rc):
print "Connected."
client.subscribe("topic_1")

def on_message(client, userdata, msg):
data = str(msg.payload.decode())
print data

client.on_connect = on_connect
client.on_message = on_message

client.loop_forever() # Without this line it does not make connection.
# Even if I made a time.sleep(10) here.
time.sleep(10)

--------------------------------------------------------------

I want to make it run without the lines 18..22

To create this topic I used the following:

---------------------------------------
# Publisher for topic "topic_1" including retain flag.
# Run this one time: sudo python Ptopic_1.py
# So it will create the topic "topic_1" with the retain flag set.

import paho.mqtt.client as mqtt
client = mqtt.Client()
client.connect("192.168.2.232",1883,60) # IP address of Broker.

data = "12345" # Test data.

client.publish("topic_1",data,qos=0,retain=True)
client.disconnect()

------------------------------------------

Regards, Wim

  • Attachment: Ptopic_1.py
    (Size: 0.37KB, Downloaded 186 times)
  • Attachment: Stopic-1.py
    (Size: 0.62KB, Downloaded 172 times)
Re: Client not connecting [message #1764341 is a reply to message #1764334] Sun, 28 May 2017 15:02 Go to previous message
Wim Nijntjes is currently offline Wim NijntjesFriend
Messages: 5
Registered: May 2017
Junior Member
Solved by adding : client.disconnect(). Just after the "print data" statement.
Previous Topic:Help with publishing
Next Topic:Send query params when mqttClient connect
Goto Forum:
  


Current Time: Thu Apr 25 19:20:10 GMT 2024

Powered by FUDForum. Page generated in 0.03553 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top