Client not connecting [message #1764334] |
Sun, 28 May 2017 11:42 |
Wim Nijntjes 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)
|
|
|
|
Powered by
FUDForum. Page generated in 0.03553 seconds