2020-09-08 17:56:24 +02:00
|
|
|
#!/usr/bin/env python
|
|
|
|
#coding: utf8
|
|
|
|
|
|
|
|
# file: watchdoor.py
|
|
|
|
# date: 06.09.2020
|
|
|
|
# mail: berhsi@web.de
|
|
|
|
# desc: deamon who deals with edge detection at pin 18
|
|
|
|
|
|
|
|
import logging
|
|
|
|
loglevel = logging.INFO
|
|
|
|
formatstring = '%(asctime)s: %(levelname)s: %(message)s'
|
|
|
|
logging.basicConfig(format=formatstring, level=loglevel)
|
2020-10-22 23:59:04 +02:00
|
|
|
import time
|
|
|
|
import RPi.GPIO as GPIO
|
|
|
|
try:
|
|
|
|
from setstatus import SetStatus
|
|
|
|
except Exception as e:
|
|
|
|
logging.error('Cant import module setstatus')
|
|
|
|
logging.error('Error: {}'.format(e))
|
|
|
|
|
2020-09-08 17:56:24 +02:00
|
|
|
|
|
|
|
GPIO.setmode(GPIO.BOARD) # kind of enumeration
|
|
|
|
GPIO.setup(18, GPIO.IN, pull_up_down = GPIO.PUD_DOWN) # pin 18 (GPIO 24)
|
|
|
|
channel = 18
|
|
|
|
|
|
|
|
def voltage_changed(channel):
|
|
|
|
'''
|
|
|
|
callback-function
|
|
|
|
'''
|
|
|
|
if GPIO.input(channel) == GPIO.HIGH:
|
|
|
|
# door closed -> pin hight
|
|
|
|
logging.info('Pin high triggered - Space closed')
|
2020-10-22 23:59:04 +02:00
|
|
|
s = SetStatus()
|
|
|
|
s.run(0)
|
2020-09-08 17:56:24 +02:00
|
|
|
else:
|
|
|
|
# door open -> pin low
|
|
|
|
logging.info('Pin low triggered - Space is open')
|
2020-10-22 23:59:04 +02:00
|
|
|
s = SetStatus()
|
|
|
|
s.run(1)
|
2020-09-08 17:56:24 +02:00
|
|
|
|
|
|
|
def main():
|
|
|
|
'''
|
|
|
|
'''
|
|
|
|
logging.info('watchdoor.py started')
|
|
|
|
GPIO.add_event_detect(channel,
|
|
|
|
GPIO.BOTH,
|
|
|
|
callback = voltage_changed,
|
|
|
|
bouncetime = 200)
|
|
|
|
while 1:
|
|
|
|
time.sleep(0.1)
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
main()
|