So at start, the door is closed. Every time it sees 3.8VAC, assume the door is moving. First time it moves it is OPENING, so the program would do a requests.post to a specific URL (that is how I get the info). When it stops, do another requests.post to say the door is STOPPED. When it sees the 3.8VAC again, assume the door is CLOSING. Again, when it stops and the 3.8VAC is gone, it is STOPPED, do another requests.post to a URL. I would have three URLs prebuilt for it to post. One for "opening" direction, one for the "closing" direction, one for the "stopped" event. I already have one for the closed state
For the RIGHT door...
Start with rmovlogic = 1 # door is CLOSED
When I GET the 3.8VAC, do a requests.post to my URL and set rmovlogic = 2 # door is OPENING
When I LOSE the 3.8VAC, do a requests.post to my URL and set rmovlogic = 3 # door is STOPPED
When I GET the 3.8VAC, do a requests.post to my URL and set rmovlogic = 4 # door is CLOSING
* every time it reverses, go back and forth between rmovlogic = 2, 3 or 4, depending on direction as long as it is not CLOSED.
If the door direction changes several times before reaching CLOSED, I want to know what its last direction was. This is populated on my phone, determined by the last requests.post URL. Each URL has it own keyword that is interpreted by my phone (opening, stopped, closing, closed).
I will take care of the closed state with a limit switch on pin 40. If that has a ground, then the door is CLOSED. When it gets closed, the rmovlogic would be reset to 1. I already have a requests.post to a URL to pass on that state.
Here's a demo of what I have now, showing the OPEN/CLOSE state monitoring. I think it is recent... https://drive.google.com/file/d/1jKu4pB ... TVS81/view
And here's how I am monitoring open/closed state of two different doors in one program:
Code: Select all
import requests import RPi.GPIO as GPIO import time GPIO.setmode(GPIO.BOARD) GPIO.setwarnings(False) r = requests.post("http://bit.ly/xxxxxxx") # Door monitor service is active buttonRDPin = 15 # Not used buttonRUPin = 16 buttonLDPin = 38 # Not used buttonLUPin = 40 GPIO.setup(buttonRUPin, GPIO.IN, pull_up_down=GPIO.PUD_UP) GPIO.setup(buttonRDPin, GPIO.IN, pull_up_down=GPIO.PUD_UP) # Not used GPIO.setup(buttonLUPin, GPIO.IN, pull_up_down=GPIO.PUD_UP) GPIO.setup(buttonLDPin, GPIO.IN, pull_up_down=GPIO.PUD_UP) # Not used ledONPin = 32 GPIO.setup(ledONPin, GPIO.OUT) GPIO.output(ledONPin, GPIO.HIGH) # LED on breadboard indicating door monitor service is active llogic = 1 # Initialize door state of left door, assumed to be closed rlogic = 1 # Initialize door state of right door, assumed to be closed while True: buttonState = GPIO.input(buttonRUPin) if buttonState == False: if rlogic == 0: r = requests.post("http://bit.ly/xxxxxxx") # Right door is open rlogic = 1 else: if rlogic == 1: r = requests.post("http://bit.ly/xxxxxxx") # Right door is closed rlogic = 0 buttonState = GPIO.input(buttonLUPin) if buttonState == False: if llogic == 0: r = requests.post("http://bit.ly/xxxxxxx") # Left door is open llogic = 1 else: if llogic == 1: r = requests.post("http://bit.ly/xxxxxxxx") # Left door is closed llogic = 0 time.sleep(0.1)