我对python非常陌生,只想解决下面的问题。
我在试着建立一个工厂浇水自动化系统。作为一个基础,使用龙卷风套接字服务器,它听取客户投票和交付数据的可视化。
为了自动浇水,我创建了一个ContinuousCallback (每30分钟一次),在其中我想检查湿度并控制水泵(GPIO )。
的任务:,如果回调启动,并测量低湿度,它应该开始泵通过切换GPIO引脚在一定的时间。(时间在SQLITE DB中定义)
问题:如何做?输入回调并启动泵操作(我有4个泵),并在定义的时间后结束?(计时器?,计时器中断?)而不影响套接字服务器IOloop?
。
。
谢谢你和最美好的祝愿
塞巴斯蒂安
发布于 2020-06-02 07:40:40
我猜
def on_button_or_whatever():
setGPIO_HIGH()
timer = threading.Timer(target=setGPIO_LOW,5.0)
timer.start() 发布于 2020-06-02 08:03:49
多亏了乔兰我做到了。
这是我的密码。
GPIO_PUMP_1 = 17
GPIO_PUMP_2 = 27
GPIO_PUMP_3 = 22
GPIO_PUMP_4 = 10
#function which switches the relais off (low-active)
def setGPIO_HIGH(pin):
GPIO.setmode(GPIO.BCM)
GPIO.setup(pin, GPIO.OUT)
GPIO.output(pin, GPIO.LOW)
return True
#function which switches the relais on (low-active)
def setGPIO_LOW(pin):
GPIO.setmode(GPIO.BCM)
GPIO.setup(pin, GPIO.OUT)
GPIO.output(pin, GPIO.HIGH)
return True
#main function for controlling the watering logic
def doStuff():
setGPIO_HIGH(GPIO_PUMP_1)
setGPIO_HIGH(GPIO_PUMP_2)
setGPIO_HIGH(GPIO_PUMP_3)
setGPIO_HIGH(GPIO_PUMP_4)
timer1 = threading.Timer(5.0, setGPIO_LOW, [GPIO_PUMP_1])
timer1.start()
timer2 = threading.Timer(6.0, setGPIO_LOW, [GPIO_PUMP_2])
timer2.start()
timer3 = threading.Timer(7.0, setGPIO_LOW, [GPIO_PUMP_3])
timer3.start()
timer4 = threading.Timer(8.0, setGPIO_LOW, [GPIO_PUMP_4])
timer4.start()
WebSocketHandler.broadcast("all done")
return Truehttps://stackoverflow.com/questions/62146536
复制相似问题