title: MQTT Subscriber to ThingsBoard broker in python
body: <p><strong>Situation:</strong>
  I have a python virtual sensor (a python program) that submits data via MQTT protocol to my device in ThingsBoard.
  I can visualize data on the dashboard, so I'm sure that the data are received.</p>
  <p><strong>Problem:</strong>
  When I try to connect a python subscriber to the thingsboard broker (demo.thingsboard.io) using paho I obtain that the connection code is 0, so the connection is OK, <strong>however</strong> I see that the dashboard stops visualising the data from the virtual sensor but the subscriber does not receive anything.</p>
  <p>The virtual sensor is publishing at <em>v1/devices/me/telemetry</em> and the subscriber is subscribed at the same topic <em>v1/devices/me/telemetry</em>.</p>
  <p>How to show the data published by the virtual sensor on my subscriber client?</p>
  <p><strong>VIRTUAL SENSOR CODE:</strong></p>
  <pre><code>import paho.mqtt.client as paho                     #mqtt library
  import os
  import json
  import time
  from datetime import datetime
  
  ACCESS_TOKEN=&quot;vgFztmvT6bps7JCeOEZq&quot;                 #Token of your device
  broker=&quot;demo.thingsboard.io&quot;                        #host name
  port=1883                       #data listening port
  
  def on_publish(client,userdata,result):             #create function for callback
      print(&quot;data published to thingsboard \n&quot;)
      pass
  client1= paho.Client(&quot;control1&quot;)                    #create client object
  client1.on_publish = on_publish                     #assign function to callback
  client1.username_pw_set(ACCESS_TOKEN)               #access token from thingsboard device
  client1.connect(broker,port,keepalive=60)           #establish connection
  
  while True:
    
     payload=&quot;{&quot;
     payload+=&quot;\&quot;Humidity\&quot;:60,&quot;; 
     payload+=&quot;\&quot;Temperature\&quot;:25&quot;; 
     payload+=&quot;}&quot;
     ret= client1.publish(&quot;v1/devices/me/telemetry&quot;,payload) #topic-v1/devices/me/telemetry
     print(&quot;Please check LATEST TELEMETRY field of your device&quot;)
     print(payload);
     time.sleep(5)
  </code></pre>
  <p><strong>CLIENT SUBSCRIBER CODE:</strong></p>
  <pre><code>import paho.mqtt.client as mqtt
  import time
  
  token = &quot;vgFztmvT6bps7JCeOEZq&quot;
  broker=&quot;demo.thingsboard.io&quot;                        # host name
  port=1883
  topic = &quot;v1/devices/me/telemetry&quot;
  
  # The callback for when the client receives a CONNACK response from the server.
  def on_connect(client, userdata, flags, rc) :
      if (rc==0) :
          print(&quot;connected OK Returned code = &quot;, rc)
      else :
          print(&quot;Bad connection Returned code = &quot;, rc)
      
  def on_message(client, userdata, msg) :
      print (msg.topic + &quot; &quot; + str(msg.payload))    
  
  
  client = mqtt.Client()
  client.on_connect = on_connect
  client.on_message = on_message
  
  client.username_pw_set(token)
  client.connect(broker , port, 60)
  client.subscribe(topic)
  
  client.loop_forever()
  </code></pre>