0

I'm using this python script to implement a Paho(MQTT) subscriber but i am unable get any responce messages.i am able to subscribe mqtt brokerin command prompt by using mosquitto_sub -t "" -d -h -p 8883 --psk foo --psk-identity bar --insecure --tls-version tlsv1

import paho.mqtt.client as mqtt

def on_connect(client, userdata, flags, rc):
    print("Connected with result code "+str(rc))

    # Subscribing in on_connect() means that if we lose the connection and
    # reconnect then subscriptions will be renewed.
    client.subscribe("*********")

def on_message(client, userdata, msg):
    print(msg.topic+" "+str(msg.payload))

client = mqtt.Client()
client.on_connect = on_connect
client.on_message = on_message

client.connect("*********", 8883, 60)

client.loop_forever()

When I run above python script then it does not respond any error or message but keep going with loop , I also run it line by line and when I run client.connect("*********", 8883, 60) then it shows only 0 . please note here without psk and psk-identity we cannot connect to broker.

Thanks

hardillb
  • 54,545
  • 11
  • 67
  • 105
Owais Ajaz
  • 244
  • 5
  • 20
  • 1
    I'm not sure that the Python Paho client supports PSK TLS connections – hardillb Sep 11 '18 at 19:39
  • Thanks, what are the options with PSK TLS support? – Owais Ajaz Sep 11 '18 at 21:57
  • Have you actually configure the broker with PSK TLS? Why can't you use normal TLS certs and Username/password or client certificates to identify the clients? – hardillb Sep 11 '18 at 22:13
  • Mqtt broker is configured in other coutry and we need to connect with its topic , they provided us mqtt fqdn , psk , psk-identity , topic – Owais Ajaz Sep 12 '18 at 09:44
  • @OwaisAjaz You can use tls_set() function for configuring tls related options for more info on function check : https://pypi.org/project/paho-mqtt/ – Ashish Sep 12 '18 at 10:03
  • @OwaisAjaz This answer has an example of how to do it with the Java Paho client https://stackoverflow.com/a/49431225/504554 – hardillb Sep 12 '18 at 10:06
  • @Ashish that doesn't let you set up TLS_PSK only set the certs – hardillb Sep 12 '18 at 10:07
  • What if we ask our project client to give us tls certs , username and password as mentioned by @hardillb ?? – Owais Ajaz Sep 12 '18 at 10:14
  • 1
    Then you follow the doc on how to connect with TLS and username and certs – hardillb Sep 12 '18 at 10:17

1 Answers1

0

Please check with your topic carefully, sometimes missing of / or # cause this problem.

or

Try This

def on_message(client, userdata, msg):
   print("Message Recieved from broker: " + msg.payload.decode())
eyllanesc
  • 235,170
  • 19
  • 170
  • 241
NAGA RAJ S
  • 452
  • 4
  • 12