Cero:
Y pensé que pudo ser por la memoria, y ya estoy pensando en comprar un MEGA
Quizá no haga falta. Con una buena optimización puede que sea suficiente:
#include <Time.h>
#include <TimeLib.h>
#include <SPI.h>
#include <SD.h>
#include <Dhcp.h>
#include <Dns.h>
#include <Ethernet.h>
#include <EthernetClient.h>
#include <EthernetServer.h>
#include <EthernetUdp.h>
#include <Servo.h>
#define SD_CARD 4
#define BOTON 6
#define DATOS 7
#define RECIBIR 0
#define SOLTAR 170
#define NOMBRE_ARCHIVO "registro.bd"
/*SERVIDOR*******************************************/
byte mac[] = {0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xEE};
IPAddress ip(192, 168, 1, 80);
EthernetServer eServer(80);
String readString;
/*SERVIDOR*******************************************/
/*SERVOMOTOR*/
Servo SG90;
/*SERVOMOTOR*/
File archivo;
void setup() {
Serial.begin(9600);
SG90.attach(DATOS);
Ethernet.begin(mac, ip);
eServer.begin();
pinMode(SD_CARD, OUTPUT);
pinMode(BOTON, INPUT);
SG90.write(RECIBIR);
iniciarLecturaSD();
setTime(00,00,00,21,11,2017);
}
void loop() {
webApp();
onBoton();
}
void webApp() {
EthernetClient client = eServer.available();
if (client) {
while (client.connected()) {
if (client.available()) {
char c = client.read();
if (readString.length() < 100) {
readString += c;
}
if (c == '\n') {
// No se ve muy ordenado, pero al menos así te carga la página un poco más rápido y sin sacrificar mucha RAM
client.println(F("HTTP/1.1 200 OK\r\nContext-Type: text/html\r\n\r\n<html><head><title> Link Feeder </title></head><body><h1>LINK FEEDER</h1><h2>Alimentacion de Mascotas Remotamente</h2><h3><a href=\"/?feed\"\">Alimentar</a></h3>"));
client.println(F("<table>"));
archivo = SD.open(NOMBRE_ARCHIVO);
if (archivo) {
while(archivo.available()) {
client.write(archivo.read());
}
archivo.close();
}
client.println(F("</table></html>"));
if (readString.indexOf("?feed") > 0) {
onServo();
}
readString = "";
delay(500);
client.stop();
}
}
}
}
}
void onServo() {
SG90.write(SOLTAR);
delay(2000);
SG90.write(RECIBIR);
saveNewFeed();
}
void onBoton() {
if (digitalRead(BOTON) == HIGH) {
onServo();
}
}
void iniciarLecturaSD() {
Serial.println(F("Inicializando Tarjeta SD..."));
if (!SD.begin(SD_CARD)) {
Serial.println(F("ERROR - Fallo al inicializar."));
return;
}
Serial.println(F("LISTO! - Tarjeta SD Inicializada."));
if (!SD.exists(fileName)) {
Serial.print(F("ERROR - No se encuentra "));
Serial.print(NOMBRE_ARCHIVO);
Serial.println('!');
return;
}
Serial.print(F("LISTO! - "));
Serial.print(NOMBRE_ARCHIVO);
Serial.println(F(" disponible y accesible."));
}
void saveNewFeed(){
iniciarLecturaSD();
File archivoTwo = SD.open(NOMBRE_ARCHIVO, FILE_WRITE);
if (archivoTwo) {
Serial.println(F("Escribiendo..."));
archivoTwo.println(F("<tr>\r\n<td>asd</td>\r\n<td>asd</td>\r\n</tr>"));
archivoTwo.close();
}
}