GartenwasserGPIO.py 文件源码

python
阅读 21 收藏 0 点赞 0 评论 0

项目:Gartenwasser 作者: bgewehr 项目源码 文件源码
def on_message(mosq, obj, msg):
    """
    Handle incoming messages
    """
    if msg.topic == MONITOR_REFRESH:
        refresh()
        return

    topicparts = msg.topic.split("/")
    pin = int(topicparts[len(topicparts) - 1])
    try:
        value = int(float(msg.payload))
    except ValueError:
        value = 0

    if pin not in GPIO_OUTPUT_PINS:
        GPIO.setup(pin, GPIO.OUT, initial=GPIO.HIGH)
        GPIO_OUTPUT_PINS.append(pin)
    if topicparts[2] == 'in':
        if value == 1:
            GPIO.output(pin, GPIO.LOW)
        else:
            GPIO.output(pin, GPIO.HIGH)

# End of MQTT callbacks
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号