Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Arduino Automatic Email Notification

I'd like to get started on a project involving the arduino and email notifications. I'm not sure anything like this has been done before, but I'm guessing some form of it has. Let me explain. Basically I would like to set up the arduino with either some piezo sensors or a kinect so that when an action is performed (or pressure is sensed) an email (or tweet) will automatically be sent. I'm sure this can be done, but I'm not sure where to start and I wondering if anyone had an idea? Thanks in advance.

like image 786
Peter Avatar asked Nov 14 '22 01:11

Peter


1 Answers

I haven't tested the below code, but this is the most basic structure for what you're trying to do.

On the Arduino, set setup your code to output something on the serial line ("arduino_output") when you want to send an e-mail. Then on the computer, wait for that event.

Linux is really easy because a serial port can be treated the same as reading a file.

#!/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" <[email protected]>',
    To          => "[email protected]",
    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();
        }
    }  
}

Good luck on your project.

like image 136
ZnArK Avatar answered Dec 23 '22 09:12

ZnArK