Close

Button + Telegram

A project log for Smart Intercom

Real-Time system that allow to pass only authorized/invited people, using Face-Recognition or NFC cards.

evgheniiEvghenii 08/01/2017 at 07:040 Comments
#!/usr/bin/python
import RPi.GPIO as GPIO
from subprocess import call
from datetime import datetime
import time
import os
shutdownPin = 29
shutdownMinSeconds = 5
debounceSeconds = 0.01
GPIO.setmode(GPIO.BOARD)
GPIO.setup(shutdownPin, GPIO.IN, pull_up_down=GPIO.PUD_UP)
buttonPressedTime = None
def buttonStateChanged(pin):
    global buttonPressedTime
    if not (GPIO.input(pin)):
        if buttonPressedTime is None:
            buttonPressedTime = datetime.now()
    else:
        if buttonPressedTime is not None:
            elapsed = (datetime.now() - buttonPressedTime).total_seconds()
            buttonPressedTime = None
            if elapsed >= shutdownMinSeconds:
                call(['shutdown', '-r', 'now'], shell=True)
            elif elapsed >= debounceSeconds:
		os.system("sh /home/pi/tgphoto.sh FaceRec /var/www/html/last.jpg > log.out 2> /dev/null")
                os.system("sshpass -p password ssh root@10.14.0.89 -p1337 notify-send -i /usr/share/icons/gnome/32x32/actions/ring2.png Smart-Intercom Guest_at_the_door")        
GPIO.add_event_detect(shutdownPin, GPIO.BOTH, callback=buttonStateChanged)
while True:
    time.sleep(5)

Added pushbutton to Smart Intercom.

It sends you last photo to telegram bot and sends notification to Ubuntu Desktop PC.

Discussions