title: Run paho mqtt client loop_forever
body: <p>I am trying to run the following code on loop continuously. But the following code only runs once and takes only one message entry. </p>
  
  <p>What i a trying to do inside the on_message function is run a cron task using python apscheduler. </p>
  
  <pre><code>def on_message(mqttc, obj, msg):
          global val
          val = str(msg.payload)
          print val
          dow = val[0:3]
          print dow
          hr = val[4:6]
          print hr
          min = val[7:9]
          print min
          status = val[10:11]
          print status
          def plugON():
                  publish.single("plug/status","0", hostname="localhost")
          def plugOFF():
                  publish.single("plug/status","1", hostname="localhost")
          def cronon():
                  print "cron on"
          def cronoff():
                  print "cron off"
          if status == '0':
                  sched.add_job(plugON, trigger='cron', year='*', month='*', day='*', week='*', day_of_week=dow, hour=hr, minute=min, id='plugon')
                  sched.add_job(cronon, trigger='cron', year='*', month='*', day='*', week='*', day_of_week=dow, hour=hr, minute=min)
  
          if status == '1':
                  sched.add_job(plugOFF, trigger='cron', year='*', month='*', day='*', week='*', day_of_week=dow, hour=hr, minute=min, id='plugoff')
                  sched.add_job(cronoff, trigger='cron', year='*', month='*', day='*', week='*', day_of_week=dow, hour=hr, minute=min)
  
          sched.start()
  </code></pre>
  
  <p>The mqtt connect script:</p>
  
  <pre><code>mqttc = mqtt.Client()
  mqttc.on_message = on_message
  mqttc.on_connect = on_connect
  mqttc.on_publish = on_publish
  mqttc.on_subscribe = on_subscribe
  mqttc.connect("localhost", 1883, 60)
  mqttc.subscribe("plug/#", 0)
  
  #mqtt loop
  mqttc.loop_forever()
  </code></pre>
  
  <p>during the execution, it connects to localhost, takes a single entry. On sending something like <strong>thu:05:47:0</strong>, waits till the 5:47 to run plugON/plugOFF. At 5:47 it runs the function and disconnects with the localhost. </p>
  
  <p>How can i get my code to take another entry and continue loop?</p>