«

»

Feb 27

Smart Doorbell

Sebuah kutipan program berbasis Pushover (berbayar), yang bisa disiasati dengan memanfaatkan solusi berbasis protokol MQTT yang free. Selamat mencoba … 🙂

from time import sleep
import os
import httplib, urllib
import RPi.GPIO as GPIO
 
GPIO.setmode(GPIO.BCM)
GPIO.setup(4, GPIO.IN)
 
def PushOver(title,message,url):
   app_key = "AppKeyHere"
   user_key = "UserKeyHere"
   #Connect with the Pushover API server
   conn = httplib.HTTPSConnection("api.pushover.net:443")
 
   #Send a POST request in urlencoded json
   conn.request("POST", "/1/messages.json",
   urllib.urlencode({
   "token": app_key,
   "user": user_key,
   "title": title,
   "message": message,
   "url": url,
   }), { "Content-type": "application/x-www-form-urlencoded" })
 
   #Any error messages or other responses?
   conn.getresponse()
 
#App-specific variables
 
PushOver('Doorbell','Started','')
print 'Doorbell Server Started\r'
 
while True:
 
   if (GPIO.input(4) == False):
      print 'Button Pushed!\r'
      os.system('mpg321 /home/pi/doorbell-1.mp3')
      PushOver('Doorbell','Someone is at the door!','')
   sleep(0.2);