Jednym z istotnych elementów bezpieczeństwa domu inteligentnego jest system alarmowy. Możemy go uzbrajać oraz dezaktywować przy pomocy np. klawiatura numeryczna membranowa 16 klawiszy. Pozostałe elementy systemy ochrony mogą stanowić :
- https://malinowo.secu.com.pl/raspberry-pi-sterowanie-syrena-alarmowa-s2-6-14v-105db-6-tonow/
- https://malinowo.secu.com.pl/raspberry-pi-hc-sr501-skrypt-w-pythonie-do-wysylania-powiadomien-emailem/
- https://malinowo.secu.com.pl/raspberry-pi-kontaktron-czujnik-otwarcia-okien-i-drzwi-uklad-mcp23017/
Potrzebne elementy:
Podłączenie:
- piny 1,2,3,4 wierszy (ROWS) klawiatury odpowiednio do pinów 19,21,23,29 maliny
- piny 5,6,7,8 kolumn (COLUMNS) klawiatury poprzez rezystor 1k Ohm do pinów 31,33,35,37 maliny
Skrypt python Keyboard4x4_pass.py sprawdzający podawane hasło:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 |
#!/usr/bin/python import RPi.GPIO as GPIO import time,os """Keyboard4x4_pass.py: Test password entered by the user """ __author__ = "zbiros" __copyright__ = "Copyright 2015, Malinowo.net.pl" __credits__ = ["maros","Chris Crumpacker - original author"] __license__ = "GPL" __version__ = "1.0.1" __maintainer__ = "zbiros" __email__ = "zbiros@malinowo.secu.com.pl" __status__ = "Development" class keypad(): KEYPAD = [ [1,2,3,'A'], [4,5,6,'B'], [7,8,9,'C'], ['*',0,'#','D'] ] ROW = [19,21,23,29] COLUMN = [31,33,35,37] def __init__(self): GPIO.setmode(GPIO.BOARD) def cls(self): os.system(['clear','cls'][os.name == 'nt']) def getKey(self): # Set all columns as output low for j in range(len(self.COLUMN)): GPIO.setup(self.COLUMN[j], GPIO.OUT) GPIO.output(self.COLUMN[j], GPIO.LOW) # Set all rows as input for i in range(len(self.ROW)): GPIO.setup(self.ROW[i], GPIO.IN, pull_up_down=GPIO.PUD_UP) # Scan rows for pushed key/button # A valid key press should set "rowVal" between 0 and 3. rowVal = -1 for i in range(len(self.ROW)): tmpRead = GPIO.input(self.ROW[i]) if tmpRead == 0: rowVal = i # if rowVal is not 0 thru 3 then no button was pressed and we can exit if rowVal <0 or rowVal >3: self.exit() return # Convert columns to input for j in range(len(self.COLUMN)): GPIO.setup(self.COLUMN[j], GPIO.IN, pull_up_down=GPIO.PUD_DOWN) # Switch the i-th row found from scan to output GPIO.setup(self.ROW[rowVal], GPIO.OUT) GPIO.output(self.ROW[rowVal], GPIO.HIGH) # Scan columns for still-pushed key/button # A valid key press should set "colVal" between 0 and 2. colVal = -1 for j in range(len(self.COLUMN)): tmpRead = GPIO.input(self.COLUMN[j]) if tmpRead == 1: colVal=j # if colVal is not 0 thru 2 then no button was pressed and we can exit if colVal <0 or colVal >3: self.exit() return # Return the value of the key pressed self.exit() return self.KEYPAD[rowVal][colVal] def exit(self): # Reinitialize all rows and columns as input at exit for i in range(len(self.ROW)): GPIO.setup(self.ROW[i], GPIO.IN, pull_up_down=GPIO.PUD_UP) for j in range(len(self.COLUMN)): GPIO.setup(self.COLUMN[j], GPIO.IN, pull_up_down=GPIO.PUD_UP) if __name__ == '__main__': kp = keypad() digit = None password_test = "" password = "*159#" try: print "PROSZE WPISAC HASLO:" while(True): digit = kp.getKey() if digit is not None: password_test += str(digit) if digit == '#': if password_test == password: print "HASLO POPRAWNE:" + password_test password_test = "" else: print "HASLO BLEDNE" password_test= "" #print digit time.sleep(0.5) # kp.cls() except KeyboardInterrupt: GPIO.cleanup() |
Wynik działania skryptu:
Warto zobaczyć:
http://crumpspot.blogspot.com/2013/05/using-3×4-matrix-keypad-with-raspberry.html
http://hackyourmind.org/articles/raspberry-pi-with-a-keypad-matrix
Klawiatura do nabycia w:
http://botland.com.pl/klawiatury/1680-klawiatura-membranowa-numeryczna-16-klawiszy.html