makalah mikroelektronika
TRANSCRIPT
MIKROELEKTRONIKA
RASPBERRY PI REMOTE CAMERA MONITOR
Oleh:
KAISAR MUHAMMAD PARAMATUAH
SUHENDHIK
DEPRILIZ PUTRI AKBARI
RINI FAUZIAH
TRI MULYANA OKTARINA
MUHAMMAD FADLI
JURUSAN SISTEM KOMPUTER
FAKULTAS ILMU KOMPUTER
UNIVERSITAS SRIWIJAYA
2013
DESKRIPSI
Tujuan:
a. Membuat suatu alat berupa remote camera monitor menggunakan raspberry pi dan usb kamera.
Manfaat:
Cara kerja:
Program akan memeriksa account Gmail khusus untuk email yang belum dibaca. Jika ada pesan baru, maka program akan men scrapes alamat pengirim, mengambil gambar menggunakan web cam, dan membalas dengan catatan singkat beserta gambar yang di attachmen.
PROGRAM YANG DIGUNAKAN:
#!/usr/bin/env python #generic importsimport timeimport osfrom time import sleep, strftimefrom datetime import datetimefrom subprocess import *from subprocess import call #imports for emailimport imaplibimport smtplibimport emailfrom email.mime.text import MIMETextfrom email.parser import HeaderParserfrom email.MIMEMultipart import MIMEMultipartfrom email.MIMEBase import MIMEBasefrom email.Utils import COMMASPACE, formatdatefrom email import Encoders # email login credentialsUSERNAME = "#######@gmail.com" PASSWORD = "#######" #program repeat intervalprogrampause = 5 # function to check the email inbox and call scrape_senders (below)def check_email(): status, email_ids = imap_server.search(None, '(UNSEEN)') if email_ids == ['']: print('No Unread Emails') mail_list = [] else: mail_list = get_senders(email_ids) print('List of email senders: ', mail_list) print len(mail_list), print("New image request") imap_server.close() return mail_list # function that scrapes sender data from new emaildef scrape_senders(email_ids): senders_list = [] for e_id in email_ids[0].split(): resp, data = imap_server.fetch(e_id, '(RFC822)') perf = HeaderParser().parsestr(data[0][1]) senders_list.append(perf['From']) return senders_list # send new email with pic attacheddef send_secure_pic(mail_list): for item in mail_list: files = [] files.append("snap.jpg") text = 'A new image was taken at ' + str(datetime.now()) assert type(files)==list msg = MIMEMultipart() msg['Subject'] = 'New Monitor Image' msg['From'] = USERNAME msg['To'] = item msg.attach ( MIMEText(text) ) for file in files: part = MIMEBase('application', "octet-stream") part.set_payload( open(file,"rb").read() ) Encoders.encode_base64(part) part.add_header('Content-Disposition', 'attachment; filename="%s"' % os.path.basename(file)) msg.attach(part) server = smtplib.SMTP('smtp.gmail.com:587') server.ehlo_or_helo_if_needed() server.starttls() server.ehlo_or_helo_if_needed() server.login(USERNAME,PASSWORD) server.sendmail(USERNAME, item, msg.as_string() ) server.quit()
print('Email sent to ' + item + '!') # function calls uvccapture to take a picture with given settings. I repeat this# and overwrite the original file to get over some webcam short-comingsdef takepicture(): call(["uvccapture", "-v", "-S55", "-B190", "-C35", "-G50", "-x1280", "-y960"]) time.sleep(5) call(["uvccapture", "-v", "-S55", "-B190", "-C35", "-G50", "-x1280", "-y960"]) # the program loopwhile True: check = "yes" temp_list = [] if check == "yes": print "-"*30 print datetime.now() sendthankyou = "no" print "Checking for unread emails" imap_server = imaplib.IMAP4_SSL("imap.gmail.com",993) imap_server.login(USERNAME, PASSWORD) imap_server.select('INBOX') mail_list = check_email() temp_list = temp_list + mail_list if len(mail_list) > 0: takepicture() send_secure_pic(mail_list) else: print"-"*30