I have an Arduino Uno with Ethernet Shield. I currently have it programmed to control my Chicken Coop. It looks at various sensors and controls door and relays based on inputs. It also publishes all this to webpage, via Arduino WebServer, for me to see data and status of various items. That all works GREAT, the problem is I want to send e-mail on certain events, Temp too Low, Water or food too low, Ect.... I have a remote server ( www.hscfire.com ) that I have an e-mail script sitting on that all it requires is to call a URL Ex: "www.hscfire.com/script/arduino.php?Message= put in message info here" . What I want is to call this script based on certain things happening and put various data points, ex.- temps, door status, fan status, in the Message= Section! I have searched everywhere and can find examples that will send e-mails via PHP or host webpage like I'm currently doing but not BOTH at the same time? Any and all help is greatly appreciated.
Thanks,
Chris
Malvern, Arkansas
My Current Code: Kinda long and could probably be cleaned up a little but I'm still new and learning.
Had to remove some code at various points - //**********************************Removed Stuff
Mainly In/out setup and web display of raw in/out status stuff
/*
// Load various Libraries
#include <OneWire.h> //One Wire Sensors
#include <DallasTemperature.h> //Dallas Temp Sensors
#include <SPI.h> // ??
#include <Ethernet.h> //Ethernet Shield
// Enter a MAC address and IP address for your controller below.
// The IP address will be dependent on your local network:
byte mac[] = {
0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
IPAddress ip(192,168,1,200); //IP address for Webserver
// Initialize the Ethernet server library
// with the IP address and port you want to use
EthernetServer server(83);
//**********************************Removed Stuff
void setup() {
// Open serial communications and wait for port to open:
Serial.begin(9600);
Serial.println("Gaines' Arduino Chicken Coop Controler!");
while (!Serial) {
; // wait for serial port to connect. Needed for Leonardo only
// Start up the Sensor library
sensors.begin();
Serial.println( "Sensors started!" );
}
// start the Ethernet connection and the server:
Ethernet.begin(mac, ip);
server.begin();
Serial.print("server is at ");
Serial.println(Ethernet.localIP());
//**********************************Removed Stuff
}
void loop() {
// Read and store the value of various analog & digital sensors
//**********************************Removed Stuff
//Rain Barrel Level - OK LED Control
if (OK2Pump <= 100) { // If rain barrel has enough water to pump
// turn Rain Barrel LED on:
digitalWrite(rainBarrel, HIGH);
}
else { // turn Rain Barrel LED OFF:
digitalWrite(rainBarrel, LOW);
[b]Would like to send e-mail HERE![/b]
}
//Vent Fan Control
// Turn off the Vent fan outlet when the Walk Door is open,
// or if Inside Temp gets above insideTempVent Setting at top of code above Setup.
if (walkdoorState == LOW && insideTemperature >= insideTempVent) {
// If Walk Through Door is CLOSED & Inside Temp is over insideTempVent Setting
// turn Vent Fan On:
digitalWrite(ventFan, LOW);
}
else { // turn Vent Fan OFF:
digitalWrite(ventFan, HIGH); }
//**********************************Removed Stuff
/*
*********************************************************************
*/
//ETHERNET Stuff
// listen for incoming clients
EthernetClient client = server.available();
if (client)
Serial.println("New client on WebPage!!");
// an http request ends with a blank line
boolean currentLineIsBlank = true;
while (client.connected()) {
if (client.available()) {
char c = client.read();
Serial.write(c);
// if you've gotten to the end of the line (received a newline
// character) and the line is blank, the http request has ended,
// so you can send a reply
if (c == '\n' && currentLineIsBlank) {
// send a standard http response header
client.println("HTTP/1.1 200 OK");
client.println("Content-Type: text/html");
client.println("Connection: close"); // the connection will be closed after completion of the response
client.println("Refresh: 10"); // refresh the page automatically every 5 sec
client.println();
client.println("<!DOCTYPE HTML>");
client.println("<html>"); //Set HTML
//Sets Heading
client.println("<head> <title> Gaines Family Farm Coop </title> </head>"); // Change Heading in Title Bar of Browser
client.println("<body bgcolor=AliceBlue>");
// Title Line!
client.print("<b>Gaines' ARDUINO Chicken Coop WebServer"); client.println("
");
client.print("<hr>") ; //Print Horizontal Line on Webpage
client.println("
"); //Enter Blank Line after title
//Analog Input Readings
//**********************************Removed Stuff
//Print Various Sensor & Output Status'
//Chicken Door Status
if (chickendoorState <= 100) { // if Check Door input is under 100 Door is Open
// Print Chicken Door is Open:
client.print("Chicken Door is <b>OPEN</b>") ;
}
else if (chickendoorState >= 900) { // If Chicken Door input is over 900, door is closed.
client.print("Chicken Door is CLOSED") ;}
else { // If not Open or Closed
client.print("<b>Chicken Door Status is UNKNOWN!!</b>") ;
[b]Would like to send email HERE[/b]
}
client.println("
"); client.println("
");
//**********************************Removed Stuff
//Rain Barrel Status
if (OK2Pump <= 150) { // If rain barrel has enough water to pump
// Print Rain Barrel is OK in BLUE Font:
client.print("Rain Barrel Level is OK") ;
}
else { // If not Print Rain Barrel Level is LOW! in RED Font:
client.print("<b><strong><font color=#DF0101>Rain Barrel Level is LOW!!!</font></b></strong>") ;}
client.println("
"); client.println("
");
//**********************************Removed Stuff
client.print("<hr>") ; //Print Horizontal Line on Webpage
client.println("
"); // Blank Line
//TEMPERATURE AREA!!
//Print Inside Temperature
client.print("<b>Coop Inside Temperature is: ");
client.print(insideTemperature);
client.print(" deg."); client.println("
");
client.println("
");
//Print Outside Temperature
client.print("Coop Outside Temperature is: ");
client.print(outsideTemperature);
client.print(" deg.</b>");client.println("
");
client.println("
");
client.print("<hr>") ; //Print Horizontal Line on Webpage
client.println("
"); // Blank Line
// End HTML
client.println("</html>");
break;
} // Closes if C = current line blank
if (c == '\n') {
// you're starting a new line
currentLineIsBlank = true;
}
else if (c != '\r') {
// you've gotten a character on the current line
currentLineIsBlank = false;
}
// Closer for Ethernat Stuff
} // Closes "if Client Avaliable" Line
} // Closes While Client
// give the web browser time to receive the data
delay(1);
// close the connection:
client.stop();
Serial.println("client disconnected");
} //Loop Closer