Skip to content

Instantly share code, notes, and snippets.

@mapkyca
Created June 13, 2013 15:48
Show Gist options
  • Save mapkyca/5774799 to your computer and use it in GitHub Desktop.
Save mapkyca/5774799 to your computer and use it in GitHub Desktop.
A home security system. Logs when windows are opened or closed to the syslog, and gives you an indicator panel so you can see at a glance whether a you've left something open before walking out of the house!
import piface.pfio
import time
import sys
import syslog
class SecurityIndicator:
""" A switch and LED link: Displays light when switch is closed """
def __init__(self, pin_pair, label):
self.pin_pair = pin_pair
self.label = label
self.laststatus = ""
self.poll()
def poll(self):
if piface.pfio.digital_read(self.pin_pair) == 1:
if self.laststatus != 'closed':
piface.pfio.digital_write(self.pin_pair, 1)
self.log(self.label + ' is CLOSED')
self.laststatus = 'closed'
else:
if self.laststatus != 'open':
piface.pfio.digital_write(self.pin_pair, 0)
self.log(self.label + ' is OPEN')
self.laststatus = 'open'
def log(self, message):
# Echo message
print(message + ' at ' + time.strftime("%a, %d %b %Y %H:%M:%S +0000", time.gmtime()))
# And for good measure, log entry to auth log
syslog.syslog(syslog.LOG_AUTH | syslog.LOG_INFO, message)
def main(argv):
piface.pfio.init()
# Initialise our indicator switches
indicators = ['Front Door', 'Study window', 'Study door', 'Bedroom Window', 'Back door', 'Living room window', 'Kitchen window', 'Bathroom window']
indicator_obj = [];
cnt = 0
for switch in indicators:
indicator_obj.append(SecurityIndicator(cnt, switch))
cnt = cnt + 1
# Loop and check indicators
while True:
for indicator in indicator_obj:
indicator.poll()
time.sleep(0.05)
if __name__ == "__main__":
sys.exit(main(sys.argv))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment