def stop_camera(): lcd.setText("") lcd.setRGB(0, 0, 0) print("\nNo motion") led.off() print("Camera off") camera.stop_preview()
def init(): #Temperature use Analog pin 1 temperature.init() #LED use Digital pin 13 led.init() #Light is on I2C, doesn't use a specific pin light.init() #Sound uses A0 Grove Port sound.init() #LCD is on I2C, doesn't use a specific pin lcd.init() lcd.setRGB(0,255,0) #Air Quality is on Analog Pin 1 air_quality.init() #Led bar is on pin D8, uses pin 8 and 9 led_bar.init()
def quit_light(): lcd.setRGB(128,0,128) #purple time.sleep(2)
def init_light(): lcd.setRGB(128,0,0) #set the light to red initially
def fade(level,color,sleep_time): if color=="red": for l in level: lcd.setRGB(level[l],0,0) time.sleep(sleep_time) #long enough to notice color change elif color=="green": for l in level: lcd.setRGB(0,level[l],0) time.sleep(sleep_time) #long enough to notice color change elif color=="blue": for l in level: lcd.setRGB(0,0,level[l]) time.sleep(sleep_time) #long enough to notice color change elif color=="yellow": for l in level: lcd.setRGB(level[l],level[l],0) time.sleep(sleep_time) #long enough to notice color change elif color=="bluegreen": for l in level: lcd.setRGB(0,level[l],level[l]) time.sleep(sleep_time) #long enough to notice color change elif color=="purple": for l in level: lcd.setRGB(level[l],0,level[l]) time.sleep(sleep_time) #long enough to notice color change elif color=="white": for l in level: lcd.setRGB(level[l],level[l],level[l]) time.sleep(sleep_time) #long enough to notice color change
def detect_face(photo): client = boto3.client('rekognition') bucket = 'fyp-caller-images' response = client.detect_faces( Image={'S3Object': { 'Bucket': bucket, 'Name': photo }}, Attributes=['ALL']) if (len(response['FaceDetails']) == 1): led.on() lcd.setText("Motion") lcd.setRGB(0, 128, 64) # compare face_matches = compare_faces(client, photo, bucket) print("Face matches: " + str(face_matches)) # Run AWS Rekognition facial recognition algorithm # Compares source file with target file in the bucket if (face_matches == 1): result = nameMatch target = photo name_result, jpg = result.split('.') name_target, jpg = target.split('.') print(name_target + " is matching with " + name_result) t = time.localtime() current_time = time.strftime("%H:%M", t) # Writing to text file f = open("caller_name.txt", "w+") f.write(name_result) f.close() l = open("last_caller.txt", "w+") l.write(name_result + " was the last person at your door at " + today_date + " " + current_time) l.close() k = open("status.txt", "w+") known = "true" k.write(known) k.close() # Write to Caller log file and upload to s3 with open("caller_log.txt", "a") as text_file: text_file.write("\n" + today_date + " " + current_time + " - " + name_result) upload_file('/home/pi/final-year-project/caller_log.txt', "caller-details", "caller_log.txt", False) # Upload to S3 bucket 'caller-names' upload_file('/home/pi/final-year-project/caller_name.txt', "caller-details", "caller_name.txt", False) upload_file('/home/pi/final-year-project/last_caller.txt', "caller-details", "last_caller.txt", False) upload_file('/home/pi/final-year-project/status.txt', "caller-details", "status.txt", False) lcd.setText(name_result + " is at the door!") lcd.setRGB(0, 255, 0) else: face_count = face_details(client, photo) print("Faces detected: " + str(face_count)) else: print("No face") return False return True
def face_details(client, target_file): print("No matches") response_detail = client.detect_faces(Image={ 'S3Object': { 'Bucket': 'fyp-caller-images', 'Name': target_file } }, Attributes=['ALL']) print('Detected faces for ' + target_file) for faceDetail in response_detail['FaceDetails']: print('The detected face is between ' + str(faceDetail['AgeRange']['Low']) + ' and ' + str(faceDetail['AgeRange']['High']) + ' years old.') #print('Here are some other attributes: ') #print(json.dumps(faceDetail, indent=4, sort_keys=True)) spectacles = faceDetail['Eyeglasses']['Value'] if spectacles: eyeglasses = " They were wearing eyeglasses." else: eyeglasses = " They were not wearing eyeglasses." sunnies = faceDetail['Sunglasses']['Value'] if sunnies: sunglasses = " They were wearing sunglasses." else: sunglasses = " They weren't wearing sunglasses." smileEv = faceDetail['Smile']['Value'] if smileEv: smile = " They were smiling." else: smile = " They weren't smiling." if (faceDetail['Gender']['Value'] == "male" or faceDetail['Gender']['Value'] == "Male"): beardEv = faceDetail['Beard']['Value'] if beardEv: beard = " They had a beard." else: beard = " They didn't have a beard." mustEv = faceDetail['Mustache']['Value'] if mustEv: mustache = " They had a mustache." else: mustache = " They didn't have a mustache." details = ("A " + faceDetail['Gender']['Value'] + ", aged between " + str(faceDetail['AgeRange']['Low']) + " & " + str(faceDetail['AgeRange']['High']) + " is at your door!" + eyeglasses + sunglasses + mustache + beard + smile) elif (faceDetail['Gender']['Value'] == "female" or faceDetail['Gender']['Value'] == "Female"): details = ("A " + faceDetail['Gender']['Value'] + ", aged between " + str(faceDetail['AgeRange']['Low']) + " & " + str(faceDetail['AgeRange']['High']) + " is at your door!" + eyeglasses + sunglasses + smile) t = time.localtime() current_time = time.strftime("%H:%M", t) details_time = ("A " + faceDetail['Gender']['Value'] + ", aged between " + str(faceDetail['AgeRange']['Low']) + " & " + str(faceDetail['AgeRange']['High']) + " was at your door at " + today_date + " " + current_time) s = open("status.txt", "w+") known = "false" s.write(known) s.close() l = open("last_caller.txt", "w+") l.write(details_time) l.close() u = open("caller_unknown.txt", "w+") u.write(details) u.close() # Write to Caller log file and upload to s3 with open("caller_log.txt", "a") as text_file: text_file.write("\n" + today_date + " " + current_time + " - Stranger (" + faceDetail['Gender']['Value'] + ")") upload_file('/home/pi/final-year-project/caller_log.txt', "caller-details", "caller_log.txt", False) # Upload to S3 bucket 'caller-names' upload_file('/home/pi/final-year-project/status.txt', "caller-details", "status.txt", False) upload_file('/home/pi/final-year-project/last_caller.txt', "caller-details", "last_caller.txt", False) upload_file('/home/pi/final-year-project/caller_unknown.txt', "caller-details", "caller_unknown.txt", False) print(details) lcd.setRGB(255, 0, 0) lcd.setText(current_time + ": A " + faceDetail['Gender']['Value'] + " is at the door!") time.sleep(2) lcd.setText(current_time + ":Aged between " + str(faceDetail['AgeRange']['Low']) + " & " + str(faceDetail['AgeRange']['High'])) return len(response_detail['FaceDetails'])
import lcd import requests import json while True: # pull values from the server to check for updates val = requests.get('http://andrew.local:1337/pull/?id=1') rslt = json.loads(val.text) color = rslt["response"]["sensors"]["lighting"]["value"] print color if color == "red": # if simone's light is red and no characters on screen lcd.setRGB(255, 0, 0) lcd.setText("") elif color == "blue": # if simone's light is blue and no characters on screen lcd.setRGB(0, 0, 255) lcd.setText("") elif color == "purple": # if simone's light is purple and no characters on screen lcd.setRGB(255, 0, 255) lcd.setText("")
from Comm import Comm import time import grovepi import lcd # Connect the Grove Button to digital port D2 button = 2 # Connect the Grove Buzzer to digital port D8 buzzer = 8 grovepi.pinMode(button,"INPUT") grovepi.pinMode(buzzer,"OUTPUT") lcd.setRGB(128,0,0) #red worker1_ip = "192.168.0.105" worker2_ip = "192.168.0.100" worker1 = Comm(worker1_ip) worker2 = Comm(worker2_ip) time.sleep(2) #Step 1. Wait for user to press button button_flag = True while button_flag: try: value = grovepi.digitalRead(button) # 0 not pressed, 1 pressed if value == 1:
def get_ip_address(ifname): s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) return socket.inet_ntoa(fcntl.ioctl(s.fileno(), 0x8915, struct.pack("256s", ifname[:15]))[20:24]) # SIOCGIFADDR print get_ip_address("lo") print get_ip_address("eth0") ip = get_ip_address("eth0") + ":5000" greenLed = 2 grovepi.pinMode(greenLed, "OUTPUT") grovepi.digitalWrite(greenLed, 1) lcd.setRGB(128, 0, 0) # red myMote = mote.Mote("Flasher", "Simple Flasher", ip) # myMote.addCapability( mote.Capability( "Button 1", 2, 1 ) ) # myMote.addCapability( mote.Capability( "Button 2", 3, 1 ) ) myMote.addCapability(mote.Capability("Green LED", 2, 2)) url = "http://andrew.local:1337/add_listener" header = {"content-type": "application/json"} foo = requests.post(url, params=myMote.toDict(), headers=header) rslt = json.loads(foo.text) id = rslt["response"]["id"] myMote.id = id for ob in myMote.capabilities:
#Ports for lights red = 3 blue = 4 grovepi.pinMode(redSens,"INPUT") grovepi.pinMode(blueSens,"INPUT") grovepi.pinMode(red,"OUTPUT") grovepi.pinMode(blue,"OUTPUT") gameLength = 10 #Keeps track of what the user has to remember/play back selectionLog = range(0,gameLength) readyToPlay = False lcd.setText("Play Simon!"); lcd.setRGB(128,128,128) def get_ip_address(ifname): s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) return socket.inet_ntoa(fcntl.ioctl( s.fileno(), 0x8915, # SIOCGIFADDR struct.pack('256s', ifname[:15]) )[20:24]) ip = get_ip_address('eth0') + ":5000" myMote = mote.Mote("Simon", "Dani' Simon", ip) #Adds listener