Webserver trava e retorna a funcionar normalmente após reboot.

   Olá pessoal,

       Tenho uma dúvida pois tenho um código rodando normalmente mas após um certo tempo de uso o que acontece o webserve trava, o ethernet shield continua recebendo pings normalmente mas quando tento abrir o arduino pelo ip no browser ele dá página não encontrada e após efetuar o reboot ele volta a responder normalmente.Se alguém puder dar uma força ai agradeço desde de já.

Código Arduino:

#include <SPI.h>
#include <Ethernet.h>
#include <md5.h>

// 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 };
byte ip[] = { 192,168,100, 10 };
byte gateway[] = { 192,168,100, 1 };
byte subnet[] = { 255, 255, 255, 0 };


int idx=0;

md5_hash_t comandoAbrePortao;
char sComandoAbrePortao[32];
char sComandoAcendeHolofote[32];
char sComandoApagaHolofote[32];
char sComandoAlarme[32];
uint8_t macCliente[6];

uint8_t macValido[] = { 0x00, 0x17, 0x31, 0x4F, 0x29, 0x9C };
//uint8_t macValido[] = { 0x00, 0x1E, 0xC9, 0x05, 0x72, 0x73 };

// Initialize the Ethernet server library
// with the IP address and port you want to use
// (port 80 is default for HTTP):
Server server(8081);
MD5 md5Hasher;
char senharecebida[32];
int i=0;
void setup()
{
// start the Ethernet connection and the server:
pinMode(2, OUTPUT);
pinMode(8, OUTPUT);
pinMode(5, OUTPUT);
digitalWrite(2, LOW);
digitalWrite(8, LOW);
digitalWrite(5, LOW);
delay(1000);
//Ethernet.begin(mac, ip);
Ethernet.begin(mac, ip, gateway, subnet);
server.begin();
Serial.begin(9600);
calculateHash();
Serial.print("inicializou \n");
}

void loop()
{
// listen for incoming clients
Client client = server.available();
//Serial.print("no loop \n");
delay(500);
if (client)
{
//Serial.print("cliente == true \n");
while (client.connected())
{

//Serial.print("cliente conectado \n");
if (client.available())
{
//Serial.print("client.available() \n");
char c = client.read();
senharecebida[i] = c;
//Serial.print(c,HEX);
i++;
//Serial.print(c);
//Serial.print(i);
//Serial.print(",");
if(i==32)
{
i=0;
//Serial.print(sComandoAbrePortao);
if (strncmp(senharecebida, sComandoAbrePortao,32) == 0)
{
digitalWrite(2, HIGH);
delay(5000);
digitalWrite(2, LOW);
Serial.print("Senha valida para abrir portao!! \n");
client.println("Senha valida");

}
else if(strncmp(senharecebida, sComandoAcendeHolofote,32) == 0)
{
digitalWrite(8, HIGH);
delay(5000);
digitalWrite(8, LOW);
Serial.print("Senha valida para acender holofote!! \n");
client.println("Senha valida");
}
else if (strncmp(senharecebida, sComandoAlarme,32) == 0)
{
digitalWrite(5, HIGH);
delay(5000);
digitalWrite(5, LOW);
Serial.print("Senha valida para alarme!! \n");
client.println("Senha valida");

}
else
{
Serial.print("Senha invalida!! \n");
client.println("Senha invalida");
client.stop();
}
}
}
}


// give the web browser time to receive the data
delay(1);
// close the connection:
client.stop();
}
}


void calculateHash()
{

md5Hasher.ComputeHash(&comandoAbrePortao, "senha1"); 
MD5::ToHexString(comandoAbrePortao, sComandoAbrePortao);

md5Hasher.ComputeHash(&comandoAbrePortao, "senha2");
MD5::ToHexString(comandoAbrePortao, sComandoAcendeHolofote);

md5Hasher.ComputeHash(&comandoAbrePortao, "senha3"); 
MD5::ToHexString(comandoAbrePortao, sComandoApagaHolofote);

md5Hasher.ComputeHash(&comandoAbrePortao, "senha4");
MD5::ToHexString(comandoAbrePortao, sComandoAlarme);

delay(1000);
}

boolean validaMac(Client client)
{
boolean macValidado=true;
client.getMac(macCliente);
Serial.print(macCliente[0],HEX);
Serial.print(macCliente[1],HEX);
Serial.print(macCliente[2],HEX);
Serial.print(macCliente[3],HEX);
Serial.print(macCliente[4],HEX);
Serial.print(macCliente[5],HEX);
for(idx=0; idx<6;idx++)
{
if(macCliente[idx]!=macValido[idx])
{
macValidado=false;
}
}

if(macValidado==true)
{
Serial.print("MAC valido.!");
}
else
{
Serial.print("MAC Invalido!");
}
return macValidado;

}

Exibições: 446

Responder esta

© 2024   Criado por Marcelo Rodrigues.   Ativado por

Badges  |  Relatar um incidente  |  Termos de serviço