def stop_camera(): lcd.setText("") lcd.setRGB(0, 0, 0) print("\nNo motion") led.off() print("Camera off") camera.stop_preview()
import grovepi import urllib2 import json import time import requests import lcd #ports for buttons that will be updating values in the database button1 = 2 button2 = 3 piID = 1 lcd.setText("Hi, I'm pi number" + str(piID)) while (true): #if the value isnt already one, set it to one when the corresponding button's pressed if (json.loads(urllib2.urlopen("http://andrew.local:1337/pull/?id=").read())["response"]["sensors"]["button1"]["value"] == 0): requests.post("http://andrew.local:1337/push/?id=" + piID + "&name=button1&value=" + \ grovepi.digitalRead(button1)) if (json.loads(urllib2.urlopen("http://andrew.local:1337/pull/?id=").read())["response"]["sensors"]["button2"]["value"] == 0): requests.post("http://andrew.local:1337/push/?id=" + piID + "&name=button2&value=" + \ grovepi.digitalRead(button2)) time.sleep(.1)
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("")
blueSens = 5 #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)
#Led bar is on pin D8, uses pin 8 and 9 led_bar.init() if __name__=="__main__": init() config = ConfigParser.ConfigParser() config.add_section('Values') while True: led.loop() #will add a 0.4sec delay db = sound.loop() # time.sleep 0.5s degree = temperature.loop() lux = light.loop() quality = air_quality.getString() qualityValue = air_quality.getValue() lcd.setText("%.0f lux, %.01f C\n%d db, %s" % (lux, degree, db, quality)) level = 0 if qualityValue > 300: level = level + 1 if lux < 200: level = level + 2 elif lux < 100: level = level + 1 if degree > 30 or degree < 18: level = level + 2 elif degree > 26 or degree < 22: level = level + 1 if db > 100: