Go Down

Topic: Webclient não enviar email Arduino uno 3 e Shield W5100 (Read 121 times) previous topic - next topic

jasjefferson

Prezados fiz um código que é server e client no mesmo arduino usando um shield w5100, porem a funcionalidade de server funciona normal já a de client não executa normalmente.

esse é o código


Code: [Select]
#define time 1000
#include <SPI.h>
#include <Ethernet.h>
#include <EthernetClient.h>

byte mac[] = {
  0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED
};
IPAddress ip(10, 50, 1, 95);
IPAddress myDns(10, 50, 1, 29);
IPAddress gateway(10, 0, 0, 65);
IPAddress subnet(255, 0, 0, 0);
const int LM35 = A0;
float temperatura;
char emaserver[] = { 200, 147, 99, 132 }; //Mailserver
EthernetServer server(8080);
EthernetClient client;

void setup() {
  // Open serial communications and wait for port to open:
  Serial.begin(9600);
  while (!Serial) {
    ; // wait for serial port to connect. Needed for native USB port only
  }


  // start the Ethernet connection and the server:
  Ethernet.begin(mac, ip, myDns, gateway, subnet);
  server.begin();
  Serial.print("server is at ");
  Serial.println(Ethernet.localIP());
}


void loop() {
 temperatura = (float(analogRead(LM35)) * 5 / (1023)) / 0.01;
  // listen for incoming clients
  EthernetClient client = server.available();
  if (client) {
    Serial.println("new client");
    // 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: 5");  // refresh the page automatically every 5 sec
          client.println();
          client.println("<!DOCTYPE HTML>");
          client.println("<html>");
            client.println("<meta http-equiv=\"refresh\" content=\"2\">");
          // output the value of each analog input pin
          client.println("<head>");
            client.println("<title>Medidior de temperatura</title>");
            client.println("<head>");
            client.println("<body>");
            client.println("<h1>Monitoramento de Temperatura</h1>");
            client.println("<h2>Temperatura.:</h2>");
            client.print(temperatura);
            client.print("&deg;"); // Referência do caratere(graus º)
            client.println("C");// Exibe o "C"
            client.println("</body>");
            client.println("</head>");
            client.println("</html>");
            break;
            }

        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;
       
        }
      }
    }

if (temperatura > 27.00){
            //Serial.println (temperatura);
            envia();   
           
   // give the web browser time to receive the data
    delay(1);
    // close the connection:
    client.stop();
    Serial.println("client disconnected");
      }
 
  else{
    delay(1);
    // close the connection:
    client.stop();
    Serial.println("client disconnected");
    }
  }
}

void envia()
{
delay(time);
Serial.println("conectando...");
if (client.connect(emaserver,587)) // Porta de conexao do servidor do email.
{
Serial.println("conectado!");
Serial.println("enviando email...");
Serial.println();
client.println( "EHLO localhost" );
recebe();
delay(time);
client.println("AUTH LOGIN");
recebe();
delay(time);
client.println("xxx"); // Email de login em base de 64: http://base64-encoder-online.waraxe.us/
recebe();
delay(time);
client.println("xxxx"); // Senha do email em base de 64: http://base64-encoder-online.waraxe.us/
recebe();
delay(time);
client.println("mail from: <monitoramento.tempe@bol.com.br>"); //Email remetente
recebe();
delay(time);
client.println("rcpt to: <jefferson.as18@gmail.com>"); // Email destinatário
recebe();
delay(time);
client.println("data");
recebe();
delay(time);
client.println("Subject: Teste BYTE IP de Email!"); // Assunto
recebe();
delay(time);
client.println("Alerta sua temperatura esta muita alta !!!!!!!!"); // Corpo
recebe();
delay(time);
client.println("."); // Indica fim do email.
recebe();
delay(time);
client.println();
recebe();
delay(time);
Serial.println("email enviado!");
delay(time);
if (client.connected()) // Desconecta pra deixar pronto para novo envio.
{
Serial.println();
Serial.println("desconectando...");
client.stop();
Serial.println();
Serial.println();
}
}
else
{
Serial.println("connection failed");
}
//Serial.println("Ready. Press 'e' to connect.");
}


void recebe()
{
while (client.available())
{
char c = client.read();
Serial.print(c);
}
}




Go Up