def loop():
"""
The main loop in which we mow the lawn.
"""
print 'GPIO daemon started'
while True:
for PIN in PINS:
index = [y[0] for y in PINS].index(PIN[0])
pin = PINS[index][0]
oldstate = PINS[index][1]
newstate = GPIO.input(pin)
if newstate != oldstate:
mqttc.publish(MQTT_TOPIC_OUT % pin, payload=newstate, qos=MQTT_QOS, retain=MQTT_RETAIN)
PINS[index][1] = newstate
time.sleep(.8)
# Use the signal module to handle signals
评论列表
文章目录