A maior rede de estudos do Brasil

Grátis
LidarPythonCode

Pré-visualização | Página 3 de 7

data to report<br>"
 try:
 if (len(sConstants[iZero])):
 #print("send mail")
 ## sFromAddr = sConstants[iSix]
 ## sToAddr = sConstants[iSeven]
 sSubject = "Pi report " + str(datetime.datetime.now())
 sHeaders = "\r\n".join(["from: " + sConstants[iSix],
 "subject: " + sSubject,
 "to: " + sConstants[iSeven],
 "mime-version: 1.0",
 "content-type: text/html"])
 # body_of_email can be plaintext or html 
 sContent = sHeaders + "\r\n\r\n" + sBody
 #try:
 server = smtplib.SMTP("smtp.gmail.com", 587)
 server.ehlo()
 server.starttls()
 server.login( sConstants[iSix], sConstants[8] )
 server.sendmail( sConstants[iSix], sConstants[iSeven], sContent )
 server.close()
 #except SMTPAuthenticationError:
 #print("smtplib.SMTPAuthenticationError")
 #finally:
 else:
 print("password is 0 length")
 except Exception as e:
 print("fSendMail(sBody) " + str(e))
 
 return;
####################################################################################
#05-02-2018
'''
if password is not returned to pi and arduino told password has been received at pi
pi will not continue nor will arduino begin collection and control.
A password request disables arduino from data collection.
password arrives in fProcessData().most likely password arrives while this routine is asleep.
The pwdRcvd is sent to allow arduono to collect and control.
'''
####################################################################################
##def fPWD_Request():
##
### password request
## if (len(sPWD) == iZero):
## serialPort.write(sPASSWORD.encode('utf-8'))
## #fSendSerial("PASSWORD")
## fDisplayOLED_Message("PWD Wait")
## time.sleep(iTwo)
######
## if (len(sPWD) != iZero):
## serialPort.write("pwdRcvd".encode('utf-8'))
## time.sleep(iOne) #pause to give arduino time to process
## return True;
## else:
## return False;
## else:
## return False;
###################################################################################
#
###################################################################################
class cObjectDetection:
 iDog = 0
 sMsg = ""
 sOLED_AlertMessage = "empty"
 DistanceLength = 0
 oScans = { 0:0 }
 DistanceAngle = 0
 bAspectChangeInProgress = False
 
 def __init__( self ):
 self.oTrigger = threading.Event()
 self.procOD = threading.Thread(target = self.fObjectDetection )
 self.oLockCM = threading.Lock()
 self.ReturnPulse = 0
 self.SignalStrength = 0
 self.bMotion = False
 self.fOD_Init()
 
 def fOD_Init( self ):
 self.oTrigger.clear()
 self.procOD.daemon = True
 self.procOD.start()
 def fDoTheObjectDetectThing( self, sDistanceLength, sSignalStrength, sMotion ):
 try: 
 self.ReturnPulse = int(sDistanceLength)
 self.SignalStrength = int( sSignalStrength )
 self.bMotion = bool( sMotion )
 ## print( "oOD.fDoTheObjectDetectThing 0" )
 ## print( self.ReturnPulse )
 self.oTrigger.set()
 except Exception as e:
 print("oOD.fDoTheObjectDetectThing " + str(e)) 
 return;
 def fObjectDetection( self ):
 #sReturnPulse is the echo return from Arduino LIDAR
 while ( 1 ):
 ## print( "cObjectDetection.fObjectDetection 1" )
 with self.oLockCM:
 if ( self.oScans[self.DistanceAngle] == 0 ):
 self.oScans[self.DistanceAngle] = self.ReturnPulse 
 self.DistanceLength = self.ReturnPulse 
 if ( self.DistanceAngle != 0.0 ):
####
 ## print( "cObjectDetection.fObjectDetection %d " %( self.ReturnPulse ) )
 if ( not self.bAspectChangeInProgress ):
 ## print( "bAspectChange false" )
####
 try:
 ## print( "fObjectDetection 0 " + str((abs(self.DistanceLength - self.ReturnPulse))) + " RTN " + str(self.ReturnPulse) + " DistL: " + str(self.DistanceLength) )
 if ( (self.oScans[self.DistanceAngle]!= self.ReturnPulse) and self.bMotion ):
 if( (self.SignalStrength <= 600) and (self.SignalStrength >= 100) ):
 ## print( "fObjectDetection1 RTN " + str(self.ReturnPulse) + " DistL: " + str(self.iDistanceLength) )
 if ( self.ReturnPulse < self.oScans[self.DistanceAngle]):
 ## print("alarm? fObjectDetection" ) 
 # as the LIDAR sits in one spot the LIDAR ditstance increases
 # signal strength falls
 # if an object moves away not an alert condition
 # so LIDAR increasing distsnce is not an issue 
 if ( (abs(self.oScans[self.DistanceAngle]- self.ReturnPulse)) > 29 ):
 ## print( "fObjectDetection 0 diff:" + str((abs(self.oScans[self.DistanceAngle] - self.ReturnPulse))) + " RTN " + str(self.ReturnPulse) + " DistL: " + str(self.iDistanceLength) + " signal " + str(self.SignalStrength) )
 ## print( "cObjectDetection.fObjectDetection %d angle:value %d : %d" %( self.ReturnPulse, self.DistanceAngle, self.oScans[self.DistanceAngle]) )
 ## sTemp = "%d,%d\r\n" %( self.ReturnPulse, self.SignalStrength )
 ## print ( sTemp )
# oF = open("ObjectDetect.csv", "a+")
# oF.write(sTemp)
# oF.close()
 self.fTrigger()
 dt = datetime.datetime.now()
 ## self.sMsg += str(datetime.datetime.now()) + " " + "Angle " + str(iDistanceAngle) + " Dist " + str(self.iScans[self.iCurrentCell]) + " @cm " + sReturnPulse + " diff: " + str((abs(iDistanceLength - int(sReturnPulse)))) + "<br>"
 self.sOLED_AlertMessage = "%02d%02d %d @ %scm" %( dt.hour, dt.minute, self.DistanceAngle, self.ReturnPulse )
 ## print( "fObjectDetection " + sOLED_AlertMessage ) 
 except Exception as e:
 print("oOD.fObjectDetection " + str(e))
 finally:
 self.iDog = 0
 ## print( "fObjectDetection iDistanceLength = ReturnPulse" ) 
 self.DistanceLength = self.ReturnPulse
 self.oScans[self.DistanceAngle] = self.ReturnPulse
 ## print( "finally" )
 self.oTrigger.clear()
 ## oTriggerOLED.set() ## trigger display
 oAspectChange.set() ## release aspect change
 self.oTrigger.wait()
 return;
 def fTrigger( self ):
 ## print("BBBBBBBuzzzzzzzzz")
 GPIO.output(iPinBuzzer0, GPIO.HIGH)
 time.sleep(.5)
 GPIO.output(iPinBuzzer0, GPIO.LOW)
 return;
##############################################################################
#
##############################################################################

Crie agora seu perfil grátis para visualizar sem restrições.