我想开始一个涉及 arduino 和电子邮件通知的项目。我不确定以前是否有过这样的事情,但我猜它有某种形式。让我解释。基本上,我想用一些压电传感器或 kinect 设置 arduino,以便在执行操作(或感应到压力)时自动发送电子邮件(或推文)。我确信这可以完成,但我不确定从哪里开始,我想知道是否有人有想法?提前致谢。
问问题
4972 次
3 回答
1
我没有测试下面的代码,但这是你想要做的最基本的结构。
在 Arduino 上,设置您的代码以在您想发送电子邮件时在串行线路(“arduino_output”)上输出一些东西。然后在计算机上,等待该事件。
Linux 非常简单,因为可以将串行端口视为读取文件。
#!/usr/bin/perl
use open ':std';
use MIME::Lite;
#Open the COM port for reading
#just like a file
open FILE, "<", "/dev/usbTTY0" or die $!;
#setup e-mail message
$msg = MIME::Lite->new(
From => '"FirstName LastName" <something@gmail.com>',
To => "somebody@hotmail.com",
Subject => "subject",
Type => "text/plain"
);
#loop forever (until closed w/ ctrl+c)
while (1){
while (<FILE>){
# if there is output from the arduino (ie: Serial.write(...))
# then the e-mail will be sent
if ($_ == "arduino_output"){
MIME::Lite->send('smtp','mailrelay.corp.advancestores.com',Timeout=>60);
$msg->send();
}
}
}
祝你的项目好运。
于 2012-07-19T18:29:07.370 回答
0
用arduino查邮件很简单!
我在这里写了一篇文章http://www.albertopasca.it/whiletrue/arduino-mail-notifier-with-c/
在 Windows 上使用 C# 来检查 gmail 邮件。
您可以调整代码以在所需的每个操作系统上使用它。
希望这可以帮助。
于 2012-07-23T14:30:50.027 回答
0
我建议使用Pyserial
然后从arduino你只需将数据发送到python
void setup(){
Serial.begin(9600);
}
void loop(){
if (EVENT BECOME TRUE /* sensor value or whatever */){
Serial.write("Send mail");
}
}
然后形成 python { 安装后 pyserial }
import serial
import smtplib
def sendMail(receiver,message):
try:
s=smtplib.SMTP_SSL()
s.connect("smtp.gmail.com",465)
s.login("YOUR-SENDER-MAIL@gmail.com", "Password")
s.sendmail("your.log.result@gmail.com", receiver, message)#write the destination at receiver parameter
except Exception,R:
print R
ser = serial.Serial('/dev/tty.usbserial', 9600)# or in windows you could write port name
while 1:
receive = ser.readline()
if receive == "send mail":sendMail("send-me-notification@gmail.com","YOU got mail from arduino!")
好吧,您可以根据您的 MAIL 主机更改 smtp,在我的情况下,我使用了 gmail,祝您的项目好运:D
于 2012-07-27T10:50:55.197 回答