I am currently working on a project that is detecting light. I have a system that will turn a light on when it is in an error state. I currently have a photo resistor that is detecting this light. I would like to send an email if this light is on for more than 2 minutes. Any suggestions on sending emails?
Any help would be greatly appreciated. I looked through several online services and Nimbits seems to be the only that will an email based on an event.
If so, you should be able to do it yourself by using the SMTP protocol. It's not particularly hard. Google for examples.
I would advise you to make sure you only send one every few minutes. You don't want tens of thousands of emails being sent the moment the light is on for over 2 minutes.
Thank you for the direction. I will definitely take a look. This will be in a remote location. Would it make sense to provide more logic to check in with device to verify that it is online?
Email test code that sends an email when an "e" is sent from the serial monitor to the arduino.
//zoomkat 4/08/12
//email test code using DNS
//developed from code posted by various persons
#include <SPI.h>
#include <Ethernet.h>
#include <SPI.h>
#include <Ethernet.h>
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED }; //physical mac address
char serverName[] = "smtp.yourISP.net"; // your ISP's SMTP server
EthernetClient client;
//////////////////////
void setup(){
Serial.begin(9600);
Serial.println("DNS and DHCP-based email test 4/08/12"); // so I can keep track of what is loaded
Serial.println("Send an e in serial monitor to test"); // what to do to test
// start the Ethernet connection:
if (Ethernet.begin(mac) == 0) {
Serial.println("Failed to configure Ethernet using DHCP");
// no point in carrying on, so do nothing forevermore:
while(true);
}
// print your local IP address:
Serial.print("Arduino IP address: ");
for (byte thisByte = 0; thisByte < 4; thisByte++) {
// print the value of each byte of the IP address:
Serial.print(Ethernet.localIP()[thisByte], DEC);
Serial.print(".");
}
Serial.println();
Serial.println();
}
void loop()
{
byte inChar;
inChar = Serial.read();
if(inChar == 'e')
{
if(sendEmail()) Serial.println("Email sent"); //start sendEmail()
else Serial.println("Email failed");
}
}
//////////////////////////////// email function
byte sendEmail() //sendEmail() function that returns 1 or 0
{
//start and check for email server connection
if (client.connect(serverName, 25)) {
Serial.println("connected");
}
else {
Serial.println("connection failed");
return 0; //send 0 (failed) back to sendEmail() function
}
//wait for server "queing" response
while(!client.available()) delay(1);
client.println("HELO itismeletschat"); /*hello (statement after helo is needed but irrelevant)*/
//wait for server "hello" response
while(!client.available()) delay(1);
client.println("MAIL From: me@athome.net"); // identify sender, this should be the same as the smtp server you are using*/
//wait for server "sender ok" response
while(!client.available()) delay(1);
client.println("RCPT To: you@athome.net"); /* identify recipient */
//wait for server "receipent ok" response
while(!client.available()) delay(1);
client.println("DATA");
//wait for server to say "enter your message" response
while(!client.available()) delay(1);
//send email message to server
client.println("To: you@athome.net"); /* identify recipient */
client.println("Subject: You Have Arduino Mail!!"); /* insert subject */
client.println("Please let me know it worked!!!"); /* insert body */
client.println("."); /* end email */
//wait for server "message accepted" response
while(!client.available()) delay(1);
client.println("QUIT"); /* terminate connection */
//wait for server "goodby" response
while(!client.available()) delay(1);
//stop client connection
client.stop();
Serial.println("disconnected");
return 1; //send 1 (success) back to sendEmail() function
}