- Book mode https://hackmd.io/@ncnu-opensource/book [TOC] # raspberry pi ### 與 Pi 溝通 / 透過 UART > 支援 UART 傳輸的驅動程式 > [Windows Driver](https://drive.google.com/uc?id=1NNhZ7LnnhPWTIAEpqjt8Gkd5QkTqtFsE&export=download) ### 開機時自動發送 IP 到自己的信箱 ```python= #!/usr/bin/python import subprocess import smtplib import socket from email.mime.text import MIMEText import datetime # Which email address want to send # 明文的帳密 to = '' # Using specific mail account user = '' password = '' # SMTP command smtpserver = smtplib.SMTP_SSL('smtp.gmail.com', 465) smtpserver.login(user, password) today = datetime.date.today() # Linux Specific shell command arg='hostname -I' p=subprocess.Popen(arg,shell=True,stdout=subprocess.PIPE) data = p.communicate() split_data = data[0].split() ipaddr = split_data[0].decode("utf-8") my_ip = 'Your ip is %s' % ipaddr msg = MIMEText(my_ip) msg['Subject'] = 'IP For RaspberryPi on %s' % today.strftime('%b %d %Y') msg['From'] = user msg['To'] = to smtpserver.sendmail(user, [to], msg.as_string()) smtpserver.quit() ``` 1. 在家目錄建一個寄 email 的程式 - `vim mail.py` 2. 複製貼上上面的程式碼,儲存之後執行看看 - `python mail.py` 3. 成功執行的話,增加該檔案的執行權限 - `chmod +x ./mail.py` 4. 在( `/etc`下 ) `rc.local` 裡增加執行該檔案 ![](https://i.imgur.com/MFWMlZm.png) - 結尾的 `&` : 在背景執行