Hello, first of all many thanks in advance for any help you can bring me. This is my first post and english is not my first language, so I'll do my best.
It is probably a simple issue, since I'm quite beginner with programming. Anyway a brief explanation of what I'm trying.
With an Arduino Ethernet + Nano Router as Client + 2 Temperature sensors + hmailserver I'm being able to send an email when temperature reaches some point. The problem is that once temperature falls down, and once again it reaches that point I don't get any email anymore...so it only works the first time, and in order to make it work again I've to reset.
Here's the code I'm using:
#include <Ethernet.h>
#include <SPI.h>
float temperatura1=0;
float temperatura2=0;
int led=9;
EthernetClient client;
void alarm(); //Function that sends the email
void setup()
{
pinMode(led, OUTPUT);
}
void loop()
{
temperatura1 = (5.0 * analogRead(0)*100.0)/1023.0; // Sensor 1
temperatura2 = (5.0 * analogRead(1)*100.0)/1023.0; // Sensor 2
delay (500);
if((temperatura1>=28)||(temperatura2>=28)) // If any sensor is beyond 28, call alarm()
{
alarm();
}
}
void alarm()
{
byte server[] = { 192, 168, 1, 28 }; // Arduino IP
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
byte ip[] = { 192, 168, 1, 35 }; // hmailserver IP
digitalWrite(led, HIGH); // LED ON
Ethernet.begin(mac, ip);
delay(1000);
if (client.connect(server, 25)) { // Send the email with telnet commands
delay(100);
client.println("helo localhost");
delay(100);
client.println("auth login");
delay(100);
client.println("BASE64 email acount1");
delay(100);
client.println("BASE64 pwd email acount1");
delay(100);
client.println("MAIL FROM: email acount 1");
delay(100);
client.println("rcpt to: email account 2");
delay(100);
client.println("DATA");
delay(100);
client.println("Subject: Temperature level alarm");
delay(100);
client.println("La temperatura mesurada a la sala CPD excedeix els 28ºC!");
delay(100);
client.println(".");
delay(100);
client.println("quit");
while((temperatura1>=28)||(temperatura2>=28)) // Until temperature is under 28, check sensors
{
temperatura1 = (5.0 * analogRead(0)*100.0)/1023.0;
temperatura2 = (5.0 * analogRead(1)*100.0)/1023.0;
}
digitalWrite(led, LOW); // Once temperature is ok, turn OFF the led.
}
}
Any idea why is only working one first time?
Many thanks!