Buenos dias, tengo un Arduino UNO con el que controlo un sensor DHT22 y un sensor de humo, y muestro las mediciones en un webserver, a su vez envia alertas cuando supera determinado rango (de humo o temperatura)
Bueno el problema que tengo es que solamente me deja ingresar desde un navegador a la vez, si lo dejo abierto y pruebo ingresar desde otra pc se queda en cargando hasta que da error "No se puede acceder a este sitio web 192.168.0.13 ha tardado demasiado tiempo en responder."
Quisiera saber si es normal o si podria ser por algun problema de memoria, aclaro que estan al 70%
#include <SPI.h>
#include <Ethernet.h>
#include <SD.h>
//variables para sensor de humo
int SensorHumo = 6; // elegir el pin de entrada para el sensor de Humo
int valor = 0; // variable para leer el estado del pin 6
// size of buffer used to capture HTTP requests
#define REQ_BUF_SZ 50
// MAC address from Ethernet shield sticker under board
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
char servidor[] = "192.168.0.20";
IPAddress ip(192, 168, 0, 13);
EthernetServer server(80);
EthernetClient client;
File webFile; // the web page file on the SD card
char HTTP_req[REQ_BUF_SZ] = {0}; // buffered HTTP request stored as null terminated string
char req_index = 0; // index into HTTP_req buffer
#include <DHT.h>
#define DHTPIN 7 // pin donde esta conectado sensor de humo
#define DHTTYPE DHT22 // tipo de sensor
DHT dht(DHTPIN, DHTTYPE);
void setup()
{
pinMode(SensorHumo, INPUT);
dht.begin();
// disable Ethernet chip
pinMode(10, OUTPUT);
digitalWrite(10, HIGH);
Serial.begin(9600); // for debugging
// initialize SD card
if (!SD.begin(4)) {
return; // init failed
}
// check for index.htm file
if (!SD.exists("index.htm")) {
return; // can't find index file
}
Ethernet.begin(mac, ip); // initialize Ethernet device
server.begin(); // start to listen for clients
}
void loop()
{
valor = digitalRead(SensorHumo);
if (valor == LOW) { // comprobamos si la entrada es HIGH
delay(2000);
Envio_mail();//Llama a la función Envio_mail
}
int h = dht.readHumidity();
float t = dht.readTemperature();
int maxTemp = 27;
if (t >= maxTemp) { // comprobamos si la temperatura es mayor a 27
delay(2000);
Envio_mail();//Llama a la función Envio_mail
}
EthernetClient client = server.available(); // try to get client
if (client) { // got client?
boolean currentLineIsBlank = true;
while (client.connected()) {
if (client.available()) { // client data available to read
char c = client.read(); // read 1 byte (character) from client
// buffer first part of HTTP request in HTTP_req array (string)
// leave last element in array as 0 to null terminate string (REQ_BUF_SZ - 1)
if (req_index < (REQ_BUF_SZ - 1)) {
HTTP_req[req_index] = c; // save HTTP request character
req_index++;
}
// last line of client request is blank and ends with \n
// respond to client only after last line received
if (c == '\n' && currentLineIsBlank) {
// send a standard http response header
client.println("HTTP/1.1 200 OK");
// remainder of header follows below, depending on if
// web page or XML page is requested
// Ajax request - send XML file
if (StrContains(HTTP_req, "ajax_inputs")) {
// send rest of HTTP header
client.println("Content-Type: text/xml");
client.println("Connection: keep-alive");
client.println();
// send XML file containing input states
XML_response(client);
}
else { // web page request
// send rest of HTTP header
client.println("Content-Type: text/html");
client.println("Connection: keep-alive");
client.println();
// send web page
webFile = SD.open("index.htm"); // open web page file
if (webFile) {
while(webFile.available()) {
client.write(webFile.read()); // send web page to client
}
webFile.close();
}
}
// display received HTTP request on serial port
Serial.print(HTTP_req);
// reset buffer index and all buffer elements to 0
req_index = 0;
StrClear(HTTP_req, REQ_BUF_SZ);
break;
}
// every line of text received from the client ends with \r\n
if (c == '\n') {
// last character on line of received text
// starting new line with next character read
currentLineIsBlank = true;
}
else if (c != '\r') {
// a text character was received from client
currentLineIsBlank = false;
}
} // end if (client.available())
} // end while (client.connected())
delay(1); // give the web browser time to receive the data
client.stop(); // close the connection
} // end if (client)
}
// send the XML file containing analog value
void XML_response(EthernetClient cl)
{
// int analog_val;
float analog_val;
cl.print("<?xml version = \"1.0\" ?>");
cl.print("<inputs>");
// read analog pin A2
// analog_val = analogRead(2);
analog_val = dht.readHumidity();
cl.print("<analog>");
cl.print(analog_val);
cl.print("</analog>");
// analog_val = analogRead(3);
analog_val = dht.readTemperature();
cl.print("<analog>");
cl.print(analog_val);
cl.print("</analog>");
cl.print("</inputs>");
}
// sets every element of str to 0 (clears array)
void StrClear(char *str, char length)
{
for (int i = 0; i < length; i++) {
str[i] = 0;
}
}
// searches for the string sfind in the string str
// returns 1 if string found
// returns 0 if string not found
char StrContains(char *str, char *sfind)
{
char found = 0;
char index = 0;
char len;
len = strlen(str);
if (strlen(sfind) > len) {
return 0;
}
while (index < len) {
if (str[index] == sfind[found]) {
found++;
if (strlen(sfind) == found) {
return 1;
}
}
else {
found = 0;
}
index++;
}
return 0;
}
////////////////////////////////
void Envio_mail() {
Ethernet.begin(mac, ip);
delay(100);
Serial.println("conectando espere...");
if (client.connect(servidor, 80)) {
Serial.println("conectado :-)");//Si se establece la conexión
// Make a HTTP request:
client.println("GET /mail/mail.php HTTP/1.1");// Colocar la dirección del archivo que se va a leer en el servidor
client.println("Host: 192.168.0.20");//Dirección del servidor
client.println();
delay(2000);
Serial.println("Mail Enviado");
delay(5000);
}
}