Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def send_email(recipient, subject, body):
- import smtplib
- user='XXXX@gmail.com'
- pwd='XXXX'
- FROM = user
- TO = recipient if isinstance(recipient, list) else [recipient]
- SUBJECT = subject
- TEXT = body
- # Prepare actual message
- message = """From: %s\nTo: %s\nSubject: %s\n\n%s
- """ % (FROM, ", ".join(TO), SUBJECT, TEXT)
- try:
- server = smtplib.SMTP("smtp.gmail.com", 587)
- server.ehlo()
- server.starttls()
- server.login(user, pwd)
- server.sendmail(FROM, TO, message)
- server.close()
- print ('successfully sent the mail')
- except:
- print ("failed to send mail")
- import datetime
- def dateS():
- return datetime.datetime.now().strftime('%Y-%m-%d')
- def timeS():
- return datetime.datetime.now().strftime('%H:%M:%S')
- import serial, time,os
- #arduino = os.popen("sudo aimsadmin /dev/ttyAMA0", "r") # send terminal commande with root permission and save the resulte in "arduino"
- arduino = serial.Serial('/dev/ttyACM0', 9600, timeout=.1)
- print("Port is open")
- time.sleep(1) #give the connection a second to settle
- while True:
- data = arduino.readline()
- if data:
- if data==b'Alert!!!\r\n':
- print("Alert!!!")
- else:
- if data==b'Used\r\n':
- print('Generator on')
- else:
- print (float(data)) #strip out the new lines for now
- send_email('XXXXXXX@gmail.com','Fueling Operation','Prototype'+'\n'+float(data)+'\n'+dateS()+'\n'+timeS())
- # (better to do .read() in the long run for this reason
- time.sleep(2)
- else:
- print("Empty")
- time.sleep(2)
Add Comment
Please, Sign In to add comment