Jun-12-2021, 11:15 AM
(This post was last modified: Jun-12-2021, 01:16 PM by duckredbeard.)
I have a Raspberry Pi that monitors my keg fridge's temperature, pressure, and weight of the three kegs. It sends that information to an Android tablet that displays this data. I also have a PIR motion sensor that initiates a message to the tablet to "wake up" and show the home screen, the tablet also makes a short beep sound. Ideally, I would have this send this wakeup message no more than once per 2 minutes, the tablet's screen timeout is set to two minutes. This should keep the screen on as long as there is motion seen.
The problem I am having with this code is that if it sees constant motion, it does not send the message. It does, however, send the message after I stop moving and then move again. I have done some tests and manually sent the wake message during the movement and the tablet correctly responds.
Behold the code:
Again, my end goal is to have the script do the requests.post as long as there is motion detected, but not every time it sees motion. I can change the tablet's screen timeout to 1, 2, 5, or 10 minutes, but I prefer 2 or 5.
The problem I am having with this code is that if it sees constant motion, it does not send the message. It does, however, send the message after I stop moving and then move again. I have done some tests and manually sent the wake message during the movement and the tablet correctly responds.
Behold the code:
from gpiozero import Button, MotionSensor, LED, PWMLED import requests from signal import pause from time import sleep import time start = time.time() enablepir = 1 from datetime import datetime now = datetime.now() current_time = now.strftime("%H:%M:%S") print("Service started at", current_time) kegpir = MotionSensor(10) def kegmotion(): global start if enablepir == 1: now = time.time() if now > start: r = requests.post("https://autoremotejoaomgcd.appspot.com/sendmessage?key=SuperSecretDeviceIDHiddenForPrivacy&message=wakee") # Message to tablet that motion has been detected near the fridge print("motion detected") start = time.time() start = start + 20 #seconds to wait before enabling motion scan again, set just under tablet timeout to keep tablet waking def kegmotionstop(): placeholder = 1 kegpir.when_motion = kegmotion kegpir.when_no_motion = kegmotionstop pause()The "def kegmotionstop()" is only there because I extracted this from another code I have, where in that code stopping motion triggers something. It is probably not needed in this script.
Again, my end goal is to have the script do the requests.post as long as there is motion detected, but not every time it sees motion. I can change the tablet's screen timeout to 1, 2, 5, or 10 minutes, but I prefer 2 or 5.