User Tools

Site Tools


mqtt_sample_code

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Next revision
Previous revision
mqtt_sample_code [2016/09/28 08:09] – created tomglemqtt_sample_code [2016/09/28 08:12] (current) tomgle
Line 5: Line 5:
      import paho.mqtt.client as mqtt      import paho.mqtt.client as mqtt
  
-GPIO.setmode(GPIO.BOARD)+     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
  
-GPIO.setup(13,GPIO.IN)+     while 1: 
 +       result,mid)=mqttc.publish("paho/temp_ab",t,2) 
 +       time.sleep(1)
  
-mqttc=mqtt.Client() +     mqttc.loop_stop() 
-mqttc.connect("iot.eclipse.org",1883,60) +     mqttc.disconnect()
-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