title: Publish and Subscribe with Paho Mqtt Client
body: <p>After installing paho mqtt client on my raspberry pi and connecting my android application and arduino with my broker. I want after receiving message from the application or the arduino client republish this message to this clients for example if i recieve "ON" after i recieve "OFF", the next publish it will be "ON" "OFF" "ON" "OFF"... or i need to be just "ON" or "OFF" </p>
  
  <pre><code>import paho.mqtt.client as mqtt
  message = 'ON'
  def on_connect(mosq, obj, rc):
      print("rc: " + str(rc))
  
  def on_message(mosq, obj, msg):
      global message
      print(msg.topic + " " + str(msg.qos) + " " + str(msg.payload))
      message = msg.payload
  
  def on_publish(mosq, obj, mid):
      print("mid: " + str(mid))
  
  def on_subscribe(mosq, obj, mid, granted_qos):
      print("Subscribed: " + str(mid) + " " + str(granted_qos))
  
  def on_log(mosq, obj, level, string):
      print(string)
  
  mqttc = mqtt.Client()
  # Assign event callbacks
  mqttc.on_message = on_message
  mqttc.on_connect = on_connect
  mqttc.on_publish = on_publish
  mqttc.on_subscribe = on_subscribe
  # Connect
  mqttc.connect("localhost", 1883,60)
  
  # Start subscribe, with QoS level 0
  mqttc.subscribe("f", 0)
  
  # Publish a message
  #mqttc.publish("hello/world", "my message")
  
  # Continue the network loop, exit when an error occurs
  rc = 0
  while rc == 0:
     rc = mqttc.loop()
     mqttc.publish("f",message)
  print("rc: " + str(rc))
  </code></pre>