def scanning(): if running: try: readIR() # time.sleep(0.5) except KeyboardInterrupt: GPIO.Cleanup() exit() root.after(1000, scanning)
s.ehlo() s.login(smtpUser,smtpPass) s.sendmail(fromAdd, toAdd, header + '\n\n' + body) s.quit() else: count1 =1 count2+=1 if count2 == 2: smtpUser = '******' smtpPass = '******' toAdd = '*****@*****.**' fromAdd = smtpUser subject = 'NO INTRUSION DETECTED IN THE FIELD' header = 'To: ' + toAdd + '\n' + 'From: ' + fromAdd + '\n' + 'subject: ' + subject body = 'NO INTRUSION DETECTED, CHECK OUT THE LATEST FEEDS AT http://192.168.43.107:8081' print header + '\n' + body s = smtplib.SMTP('smtp.gmail.com',587) s.ehlo() s.starttls() s.ehlo() s.login(smtpUser,smtpPass) s.sendmail(fromAdd, toAdd, header + '\n\n' + body) s.quit() GPIO.Cleanup()
def Measurement_Sweep(): GPIO.setmode(GPIO.BCM) GPIO.setwarnings(False) #delay time delay = 30 #Assign GPIO numbers. V_Limit = 22 HR_Limit = 27 HL_Limit = 17 H_Pulse = 6 GND_1 = 12 H_Dir = 13 GND_2 = 16 V_Pulse = 19 GND_3 = 20 V_Dir = 26 GND_4 = 21 #Set as outputs. GPIO.setup(H_Pulse, GPIO.OUT) GPIO.setup(H_Dir, GPIO.OUT, initial=GPIO.HIGH) GPIO.setup(V_Pulse, GPIO.OUT) GPIO.setup(V_Dir, GPIO.OUT) #Set as inputs pulled down. GPIO.setup(V_Limit, GPIO.IN, pull_up_down=GPIO.PUD_DOWN) GPIO.setup(HR_Limit, GPIO.IN, pull_up_down=GPIO.PUD_DOWN) GPIO.setup(HL_Limit, GPIO.IN, pull_up_down=GPIO.PUD_DOWN) #Set up grounds(From Test_Connectivity) GPIO.setup(GND_1, GPIO.OUT, initial=GPIO.LOW) GPIO.setup(GND_2, GPIO.OUT, initial=GPIO.LOW) GPIO.setup(GND_3, GPIO.OUT, initial=GPIO.LOW) GPIO.setup(GND_4, GPIO.OUT, initial=GPIO.LOW) #Set Motor positions and counts. V_Pos = 0 H_Pos = 0 V_Count = 0 H_Count = 0 #Direction flag Dir = False Count = 0 pulseV = 15 #for alternating pulse counts pulseH = 15 #******************************LIGHT SENSOR / File SETUP****************************************** #this can change with different sensors DEVICE = 0x23 READ = 0x20 bus = smbus.SMBus(1) #Function that returns light sensor measurement. def readLight(addr=DEVICE): data = bus.read_i2c_block_data(addr, READ) return ((data[1] + (256 * data[0])) / 1.2) try: readLight() readLight() except: print("I2C sensor not connected") print("Connect first then try again") return #Function that prints light sensor measurement def writeAverageLight(H_Pos, V_Pos): working = False while not working: try: lux = 1.00 * int(readLight()) time.sleep(0.15) working = True #if lux>350: # print("lux too high") #working=False except: working = False #Save light and motor position data to file. f.write(str(lux) + "\n") #print >> f, lux f.write(str(H_Pos) + "\n") #print >> f, H_Pos f.write(str(V_Pos) + "\n") #print >> f, V_Pos #show current position in terminal print("Light Level : " + str(lux) + " lux") print("Horizontal Position: " + str(H_Pos) + " degrees") print("Vertical Position: " + str(V_Pos) + " degrees\n") #User input for data file name. fileNameValid = False #filename = raw_input("Enter file name: ") while not (fileNameValid): filename = input("Enter unique file name: ") try: f = open( "/home/pi/Desktop/LightProgram/Raw_Measurements/" + filename, "a") fileNameValid = True except: print("File name invalid,try again\n") #*******************************MOTOR MOTION CODE************************************* print( "\nMeasurements Starting in %d seconds.\nIf your going to leave, do it now\n", delay) #11 ten degree rotations (Horizontal loop) while H_Count <= 11: #direction of top motor's rotation flips each time Dir = not Dir #11 360 degree rotations (vertical loop) while V_Count < (36): #use Dir to set motor direction if Dir == False: GPIO.output(V_Dir, GPIO.LOW) else: GPIO.output(V_Dir, GPIO.HIGH) #read light intensity writeAverageLight(H_Pos, V_Pos) #step 10 degrees i = 0 while i < pulseV: GPIO.output(V_Pulse, GPIO.HIGH) time.sleep(.02) GPIO.output(V_Pulse, GPIO.LOW) time.sleep(.02) i = i + 1 #alternate betwen 15 steps and 16 steps to reduce error if pulseV == 15: pulseV = 16 else: pulseV = 15 #Increment vertical step count and position. V_Count = V_Count + 1 if Dir == True: V_Pos = V_Pos + 10 else: V_Pos = V_Pos - 10 Count = Count + 1 #pulseV = pulseV - 1 #(Out of Vertical loop) #Reset vertical motor step count V_Count = 0 #read light intensity at 360 degrees or zero degrees writeAverageLight(H_Pos, V_Pos) #Pulse horizontal motor. i = 0 while i < pulseH: GPIO.output(H_Pulse, GPIO.HIGH) time.sleep(.02) GPIO.output(H_Pulse, GPIO.LOW) time.sleep(1) i = i + 1 #alternate betwen 15 steps and 16 steps to reduce error if pulseH == 15: pulseH = 16 else: pulseH = 15 #Increment vertical step count and position. H_Count = H_Count + 1 H_Pos = H_Pos + 10 Count = Count + 1 #closing file (it is at this point where the contents actually save) f.close() #try: GPIO.Cleanup() print("Lux Count: " + str(Count))
def close(self): GPIO.Cleanup(self.pin)