#define time 1000 #include #include #include byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED }; IPAddress ip(10, 50, 1, 95); byte gateway[] = { 10, 0, 0, 0 }; byte subnet[] = { 255, 0, 0, 0 }; const int LM35 = A0; float temperatura; char mailserver[] = "smtps.bol.com.br"; //Mailserver EthernetClient client; EthernetServer server(80); void setup() { Serial.begin(9600); while (!Serial) { ; } Ethernet.begin(mac, ip); server.begin(); Serial.print("server is at "); Serial.println(Ethernet.localIP()); void loop() { // escutar clientes entrantes EthernetClient client = server.available(); if (client) { Serial.println("new client"); // um pedido de http termina com uma linha em branco boolean currentLineIsBlank = true; //verifica conexão while (client.connected()) { if (client.available()) { char c = client.read(); Serial.write(c); if (c == '\n' && currentLineIsBlank) { client.println("HTTP/1.1 200 OK"); client.println("Content-Type: text/html"); client.println("Connection: close"); client.println("Refresh: 2"); client.println(); client.println(""); client.println(""); client.println(""); //Tentativa de chamar a função temperatura = (float(analogRead(LM35)) * 5 / (1023)) / 0.01; if(temperatura > 24){ if(sendEmail1()) Serial.println(F("Email sent")); else Serial.println(F("Email failed")); client.println(""); client.println("Medidior de temperatura"); client.println(""); client.println(""); client.println("

Monitoramento de Temperatura

"); client.println("

Temperatura.:

"); client.print(
temperatura
); client.print(F("°")); // Referência do carater(graus º) na codificação Latin-1 (ISO-8859-1) client.println(F("C")); client.println(""); client.println(""); client.println(""); if (c == '\n') { // você está começando uma nova linha currentLineIsBlank = true; } else if (c != '\r') { // você conseguiu um personagem na linha atual currentLineIsBlank = false; } } } // dê tempo ao navegador da web para receber os dados delay(1); // feche a conexão: client.stop(); Serial.println("client disconnected"); } } //envio do e-mail fora do loop byte sendEmail1() { char server[] = "smtps.bol.com.br"; //Gmail e Yahoo não funcionaram int port = 587; //previousMillis2 = millis(); //Reiniciando a contagem de tempo do LCD //lcd.setBacklight(255); //Ligando a luz do LCD //lcd.clear(); //Limpa o LCD //lcd.print(" Enviando Email "); //Emite mensagem //lcd.setCursor(0,1); //Muda de linha //lcd.print(" de Alerta . . ."); //Emite mensagem byte thisByte = 0; byte respCode; if(client.connect(server,port) == 1) { Serial.println(F("connected")); } else { Serial.println(F("connection failed")); return 0; } if(!eRcv()) return 0; Serial.println(F("Sending hello")); // replace 1.2.3.4 with your Arduino's ip client.println("EHLO 1.2.3.4"); if(!eRcv()) return 0; Serial.println(F("Sending auth login")); client.println("auth login"); if(!eRcv()) return 0; Serial.println(F("Sending User")); // Change to your base64 encoded user //http://www.motobit.com/util/base64-decoder-encoder.asp client.println("bW9uaXRvcmFtZW50by50ZW1wZUBib2wuY29tLmJy"); if(!eRcv()) return 0; Serial.println(F("Sending Password")); // change to your base64 encoded password client.println("R0BtYXNvdXphMjAxOA=="); if(!eRcv()) return 0; // change to your email address (sender) Serial.println(F("Sending From")); client.println("MAIL From: "); //Seu e-mail do Bol //Não funciona com Gmail e Yahoo if(!eRcv()) return 0; // change to recipient address Serial.println(F("Sending To")); client.println("RCPT To: "); if(!eRcv()) return 0; Serial.println(F("Sending DATA")); client.println("DATA"); if(!eRcv()) return 0; Serial.println(F("Sending email")); // change to recipient address client.println("To: You "); // change to your address client.println("From: ALARME CASA "); client.println("Subject: Detecção de movimento em casa\r\n"); client.println("Alarme detectou movimento em casa! Ligar para: xxxx-xxxx"); client.println("."); if(!eRcv()) return 0; Serial.println(F("Sending QUIT")); client.println("QUIT"); if(!eRcv()) return 0; client.stop(); Serial.println(F("disconnected")); return 1; } byte eRcv() { byte respCode; byte thisByte; int loopCount = 0; while(!client.available()) { delay(1); loopCount++; // if nothing received for 10 seconds, timeout if(loopCount > 10000) { client.stop(); Serial.println(F("\r\nTimeout")); return 0; } } respCode = client.peek(); while(client.available()) { thisByte = client.read(); Serial.write(thisByte); } if(respCode >= '4') { efail(); return 0; } return 1; } void efail() { byte thisByte = 0; int loopCount = 0; client.println(F("QUIT")); while(!client.available()) { delay(1); loopCount++; // if nothing received for 10 seconds, timeout if(loopCount > 10000) { client.stop(); Serial.println(F("\r\nTimeout")); return; } } while(client.available()) { thisByte = client.read(); Serial.write(thisByte); } client.stop(); Serial.println(F("disconnected")); }