mqtt_sample_code

This is an old revision of the document!


MQTT Sample Code

   import RPi.GPIO as GPIO
   import time
   import paho.mqtt.client as mqtt

GPIO.setmode(GPIO.BOARD)

GPIO.setup(13,GPIO.IN)

mqttc=mqtt.Client() mqttc.connect(“iot.eclipse.org”,1883,60) mqttc.loop_start()

def reading1():

  a=GPIO.input(13)
  print(a)
  return a

while 1:

  t=reading1()
  (result,mid)=mqttc.publish("paho/temp_ab",t,2)
  time.sleep(1)

mqttc.loop_stop() mqttc.disconnect()

mqtt_sample_code.1475064584.txt.gz · Last modified: 2016/09/28 08:09 by tomgle