首页 > 解决方案 > 通过具有 Dataplicity 的移动设备远程控制 Rpi 按钮按下,涉及继电器

问题描述

我已经尝试了几天通过手机上的 Dataplicity 访问我的 RPi 按钮。我知道这是一个带有开/关的自定义操作,但我无法获得带有开/关的界面来控制我的按钮按下。该示例用于开/关红灯和绿灯。我基本上有一组灯通过继电器连接到引脚 17。引脚 18 控制按钮,引脚 17 工作继电器。只需按一下按钮,圣诞灯就会在我指定的分配时间内打开。有什么建议么?示例代码的链接是: https ://docs.dataplicity.com/docs/custom-actions-gpio

只是不确定如何将两者合并。这是我的第一个主要项目,我没有编程背景。按键代码如下:

from gpiozero import Button
from gpiozero import OutputDevice
from time import sleep

relay1 = OutputDevice(17)
button = Button(18)
x = 0

relay1.off()

while x < 1:
    print("Lights off...")
    button.wait_for_press()
    print("The button was pressed!")
    relay1.on()
    print("Lights on...")
    print("Waiting...")
    sleep(60)
    relay1.off()

我尝试将红色部分从 Dataplicity 中的代码中删除,但我不确定如何让它包含中继部分

现在,在我手机上的自定义操作下,它显示 Control LEDs 绿色 LED,然后显示一个永不加载的旋转轮

任何建议表示赞赏=(

标签: buttonmobileraspberry-pi3relayremote-control

解决方案


可能是在按钮按下结束时您没有为自定义操作返回“OK”状态吗?

与您链接的文档中的示例类似:

# Custom Action executed succesfully
echo "[[[ReturnOK]]]"

此致,

数据性


推荐阅读