Hi:
I’m making a small app to send messages from a remote location to a home server. An decided to go with python scripts in both ends. So created a subscription and a publish script. Publish script is working fine. I can even see the publish messages in the panel.
But the subscription script is just connecting to MQTT and nothing more. Once i was able to receive the messages from the publish script, but no more.
I have 2 different users with a TX and RX client-id and they should"crosstalk" to each other (TX-user1 to RX-user2) But so far can’t seem to find the reason why it is not happening any more. They are communicating to a common topic: test/dummy
#!/usr/bin/python
# coding: utf8
import keyring
import paho.mqtt.client as mqttc
broker_url = "node02.myqtthub.com"
broker_port = 1883
clean_session = True
topic = "test/dummy"
client_id = "mqtt-user2-rx"
username = 'mqtt-user2'
password = keyring.get_password("system", username)
def on_connect(client, userdata, flags, rc):
if rc == 0:
print("Connected to MQTT Broker!")
else:
print("Failed to connect, return code %d\n", rc)
def on_subscribe(client, userdata, mid, granted_qos):
print("Subscribed: "+str(mid)+" "+str(granted_qos))
def on_message(client, userdata, msg):
print(msg.topic+" "+str(msg.qos)+" "+str(msg.payload))
def on_log(client, userdata, level, string):
print(string)
client = mqttc.Client(client_id, clean_session)
client.username_pw_set(username, password)
client.on_message = on_message
client.on_connect = on_connect
client.on_subscribe = on_subscribe
client.on_log = on_log
client.connect(broker_url, broker_port, 15)
client.subscribe(topic, qos=1)
client.loop_forever()
Could you guys help me here? Have being struggling with this code for a week now.
Regards,
acaminiti