Beruflich Dokumente
Kultur Dokumente
import smtplib
from email.MIMEMultipart import MIMEMultipart
from email.MIMEText import MIMEText
from email.MIMEBase import MIMEBase
from email import encoders
GPIO.setwarnings(False)
GPIO.setmode(GPIO.BOARD)
GPIO.setup(38,1,pull_up_down=GPIO.PUD_UP) #For alcohol
GPIO.setup(36,1,pull_up_down=GPIO.PUD_UP) #for interfacing water sensor
GPIO.setup(31,1,pull_up_down=GPIO.PUD_UP) #Horn
GPIO.setup(33,1,pull_up_down=GPIO.PUD_UP) #Brake
GPIO.setup(35,1,pull_up_down=GPIO.PUD_UP)#right indicator
GPIO.setup(37,1,pull_up_down=GPIO.PUD_UP)#left indicator
GPIO.setup(32,1,pull_up_down=GPIO.PUD_UP)#piezo sensor
msg = MIMEMultipart()
msg['From'] = fromaddr
msg['To'] = toaddr
msg['Subject'] = sub
msg.attach(MIMEText(body, 'plain'))
filename = "Image"
attachment = open("/home/pi/Desktop/image.jpg", "rb")
msg.attach(part)
def mob(msg):
account_sid = "ACb31e6a98d56b4b98a6cf0264a7802ae7" #Your Account SID
from www.twilio.com/console
auth_token = "43a2acfde3aa44c42853962b34643cf8" # Your Auth
Token from www.twilio.com/console
client = TwilioRestClient(account_sid, auth_token)
try:
message = client.messages.create(body=msg,
to="+919947099911", # Replace with your phone number
from_="+18329814729") # Replace with your Twilio number
print 'sent'
except:
print 'msg failed'
time.sleep(delay)
data=str(data)
l=len(data)
rpm=data[data.index('$')+1:l]
print 'rpm='+rpm
print 'temp='+temp
except:
print 'Waiting'
time.sleep(delay)
if(GPIO.input(37)==0):
GPIO.output(10,1)
print 'Left Indicator ON'
LI='\nLeft Indicator ON'
LIS='LION,'
else:
GPIO.output(10,0)
LI=''
LIS='LIOFF,'
if(GPIO.input(38)==0):
print 'Alcohol Detected'
al='\nAlcohol Detected'
als='AD'
else:
als='AnD'
al=''
if(GPIO.input(31)==0):
print 'Horn Pressed'
h='\nHorn Pressed'
HS='HP,'
GPIO.output(40,1)
else:
GPIO.output(40,0)
h=''
HS='HnP,'
if(GPIO.input(33)==0):
print 'Brake Pressed'
b='\nBrake Pressed'
BS='BP,'
else:
b=''
BS='BnP,'
file=open("/home/pi/Desktop/bb.txt","w")
file.write(" ")# write with blank data
file.close()
m=tim+'\nLatitude='+lat+'\nLongitude='+lon+h+b+RI+LI+al+'\nSpeed='+rpm+'\nT
emperature='+temp
file=open("/home/pi/Desktop/bb.txt","w")
file.write(m)
file.close()
TS=tim[0:3]+tim[4:7]+tim[11:19]+',2017,'# collected date and time
ST=RIS+LIS+HS+BS+als+',Temp='+temp+',RPM='+rpm # data collected as
status of vehicle
if(GPIO.input(36)==0):
print 'accident(Plunged into water)'
acc='Accident\n'+'Plunged into
water\n'+'Latitude='+lat+'\nLongitude='+lon
mob(acc)# calling function mob(msg) for sending message to
mobile
os.system("sudo fswebcam -r 320x240
/home/pi/Desktop/image.jpg") # calling command prompt and executing command
to capture the image thru usb cam
mail("blackboxgectcr@gmail.com","Accident Detected") #calling
function mail( TO mail id, Subject-line)
time.sleep(delay)
while(1):
yy=TS+ST
txn(5622692,yy)
time.sleep(delay)
def accident(channel):
if(GPIO.input(32)==0):
print 'accident'
os.system("sudo fswebcam -r 320x240 /home/pi/Desktop/image.jpg")
acc='Accident\n'+'Latitude='+lat+'\nLongitude='+lon
mob(acc)
mail("blackboxgectcr@gmail.com","Accident Detected")
time.sleep(1)
GPIO.add_event_detect(32,GPIO.FALLING,callback=accident,bouncetime=300)#
interrupt for sensing piezo, will call funcion accident
mob('ON')
try:
thread.start_new_thread(gps, ("Thread-1", 1, ) )
thread.start_new_thread(upload, ("Thread-1", 1, ) )
thread.start_new_thread(pic, ("Thread-1", 1, ) )
thread.start_new_thread(status, ("Thread-1", .5, ) )
except:
print "Error: unable to start thread"
while 1:
pass