Arduino TSP Emailer

Geek, Lighting Tech, Maker

Arduino TSP Emailer

Made With:

This will Take a dallas semiconductor temperature sensor and send you an email once every 5 minutes .

Note: You will need to complete the Arduino TSP tutorial before you start this project. 

Thie Arduino TSP tutorial  can be located HERE


#include <SPI.h>
#include <Ethernet.h>
#include <OneWire.h>
#include <DallasTemperature.h>

// Data wire is plugged into port 2 on the Arduino
#define ONE_WIRE_BUS 6
const int buttonPin = 2;
OneWire oneWire(ONE_WIRE_BUS);

// Pass our oneWire reference to Dallas Temperature.
DallasTemperature sensors(&oneWire);

// Enter a MAC address and IP address for your controller below.
// The IP address will be dependent on your local network:
byte mac[] = {
0x00, 0xAA, 0xBB, 0xCC, 0xDE, 0x02 };
IPAddress ip(192,168,1, 177);
IPAddress gateway(192,168,1, 1);
IPAddress subnet(255, 255, 0, 0);
// Enter the IP address of the server you're connecting to:
IPAddress server(xxx,xxx,xxx,xxx);

// Initialize the Ethernet client library
// with the IP address and port of the server
// that you want to connect to (port 23 is default for telnet;
// if you're using Processing's ChatServer, use port 10002):
EthernetClient client;

void setup() {


// Start up the library
sensors.begin();
pinMode(buttonPin, INPUT);
// start the Ethernet connection:
Ethernet.begin(mac);
// start the serial library:
Serial.begin(9600);
// give the Ethernet shield a second to initialize:
delay(1000);
// print your local IP address:
Serial.print("My IP address: ");
ip = Ethernet.localIP();
for (byte thisByte = 0; thisByte < 4; thisByte++) {
// print the value of each byte of the IP address:
Serial.print(ip[thisByte], DEC);
Serial.print(".");
}
Serial.println("0 connecting...");

// if you get a connection, report back via serial:
if (client.connect(server, 25)) {
Serial.println("1 connected");
}
else {
// if you didn't get a connection to the server:
Serial.println("2 connection failed");
}
}

void loop()
{


// call sensors.requestTemperatures() to issue a global temperature
// request to all devices on the bus

sensors.requestTemperatures(); // Send the command to get temperatures





// if there are incoming bytes available
// from the server, read them and print them:


// if the state has changed, increment the counter


// save the current state as the last state,
//for next time through the loop
if (client.available()) {
char c = client.read();
Serial.print(c);
}

// as long as there are bytes in the serial queue,
// read them and send them out the socket if it's open:


char inChar = Serial.read();
if (client.connected()) {
client.print(inChar);
Serial.println("connected");
client.println("EHLO www.flint.com");
client.println("MAIL FROM:<testing@docbox.flint.com>");
client.println("RCPT TO:<cpyarger@docbox.flint.com>");
client.println("DATA");
client.println("From: <arduinotesting@docbox.flint.com>");
client.println("TO: <cpyarger@docbox.flint.com>");
client.print("SUBJECT: The temp is ");
client.println(sensors.getTempFByIndex(0));
client.println();
client.println("The Temp is:");
client.println(sensors.getTempFByIndex(0));
client.println(".");
client.println(".");
delay(300000);
}
else {
Serial.println("connection failed");
Serial.println(client.read());
}


// if the server's disconnected, stop the client:
if (!client.connected()) {
Serial.println();
Serial.println("disconnecting.");
client.stop();
// do nothing:
while(true);
}
}


No Comments

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.