Go Down

Topic: [Solved] don't load the code (Read 525 times) previous topic - next topic

Xendor

Dec 09, 2012, 08:56 am Last Edit: Dec 09, 2012, 10:09 pm by Xendor Reason: 1
Hi all I have a code HTML, and I loaded the code on arduino but it's work up to a point. when I'm adding 2 buttons I can't open the page (is shutdown)
but if remove these 2 buttons the page open OK!.

I proved the code piecemeal. I know that the code is OK.

I feel like arduino is in need more space or memory. when I load or compile the code, bottom (in  sketch) say "binary Sketch size: 15.138 bytes (with a maximum of 32.256 bytes)". then spare me space?  if so then what is the problem? otherwise I'm doing wrong?

if you need more info just call it and I will respond asap.

guix

Hello, yes post all your code (as an attachment to your reply), and which Arduino model do you use?

PaulS

Quote
I feel like arduino is in need more space or memory. when I load or compile the code, bottom (in  sketch) say "binary Sketch size: 15.138 bytes (with a maximum of 32.256 bytes)". then spare me space?  if so then what is the problem? otherwise I'm doing wrong?

There are three kinds of memory on the Arduino. Flash, where your code goes, SRAM, where variables and literal strings go, and EEPROM, where you can persist data between power cycles.

The compiler is telling you how much Flash memory you have used. Nothing tells you how much SRAM you have used. But, the symptoms you describe say that you have used more than you have.

There are ways to move the literal strings out of SRAM, but, as guix says, we need to see your code.

Xendor

#3
Dec 09, 2012, 07:50 pm Last Edit: Dec 09, 2012, 10:10 pm by Xendor Reason: 1

Hello, yes post all your code (as an attachment to your reply), and which Arduino model do you use?


I'm using Arduino Uno R3 + Arduino Ethernet Shield, and Sketch | Arduino 1.0.2
this is the code:


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

//Declaración de la direcciones MAC e IP. También del puerto 80
byte mac[] = {0xB4, 0x00, 0x00, 0x00, 0x00, 0x54};
byte ip[] = { 192, 168, 1, 150 };

EthernetServer servidor(3010);


int PIN_LED=8;
String readString=String(30);
String state=String(3);
String codigo="12345";
String creadorHTML="login";

void setup()
{
  Ethernet.begin(mac, ip); //Inicializamos con las direcciones asignadas
  servidor.begin();
  pinMode(PIN_LED,OUTPUT);
  digitalWrite(PIN_LED,HIGH);
  state="OFF";
 
}

void loop()
{
  EthernetClient cliente= servidor.available();
  if(cliente)
  {
    boolean lineaenblanco=true;
    while(cliente.connected())//Cliente conectado
    {
      if(cliente.available())
      {
        char c=cliente.read();
        if(readString.length()<30)//Leemos petición HTTP caracter a caracter
        {
          readString.concat(c); //Almacenar los caracteres en la variable readString
        }
        if(c=='\n' && lineaenblanco)//Si la petición HTTP ha finalizado
        {
          int OPC = readString.indexOf("cod=");
          if(readString.substring(OPC,OPC+8)=="cod=1234")
          {
            //provando el codigo si funciona prende el LED, e ingresa al index
            creadorHTML="index";
            digitalWrite(PIN_LED,HIGH);
            state="ON";
          }
          else if (readString.substring(OPC,OPC+8)=="cod=4321")
          {
            //provando el codigo si funciona apaga el LED
            digitalWrite(PIN_LED,LOW);
            state="OFF";
          }
         
          if (creadorHTML.equals("login"))
          {
          //Cabecera HTTP estándar
          cliente.print("<!DOCTYPE html PUBLIC '-//W3C//DTD XHTML 1.0 Transitional//EN' 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd'>");
          cliente.print("<html xmlns='http://www.w3.org/1999/xhtml'>");
          cliente.print("<head>");
          cliente.print("<meta http-equiv='Content-Type' content='text/html; charset=utf-8' />");
          cliente.print("<title>Login</title>");         
          cliente.print("</head>");
          cliente.print("<body width=100% height=100%>");
          cliente.print("</body>");
          cliente.print("</html>");

          cliente.stop();//Cierro conexión con el cliente
          readString="";
          }
         
///>>>>>>>Dibuja el index<<<<<<<<<<<<<<<<<<<<<
          else if (creadorHTML.equals("index"))
          {
            cliente.print("<!DOCTYPE html PUBLIC '-//W3C//DTD XHTML 1.0 Transitional//EN' 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd'>");
            cliente.print("<meta http-equiv='Content-Type' content='text/html; charset=UTF-8' />");
            cliente.print("<html>");
           
            cliente.print("<head><title>Selección de módulo</title></head>");
            cliente.print("<body width=100% height=100%>");
            cliente.print("</body>");
            cliente.print("</html>");
            cliente.stop();//Cierro conexión con el cliente
            readString="";
          }
         
          else
          {
            cliente.print("<!DOCTYPE html PUBLIC '-//W3C//DTD XHTML 1.0 Transitional//EN' 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd'>");
            cliente.print("<meta http-equiv='Content-Type' content='text/html; charset=UTF-8' />");
            cliente.print("<html>");
            cliente.print("<head><title>Selección de módulo</title></head>");
            cliente.print("<body width=100% height=100%>");
            cliente.print("<br><br><center><h3>Problema con el if</h3>");
            cliente.print("</body");
            cliente.print("</html>");
            cliente.stop();//Cierro conexión con el cliente
            readString="";


          }
        }
      }     
    }
  }
}

PaulS

Those Strings are killing you. The massive amount of literals is killing you.

The literals can be dealt with easily.
          cliente.print(F("<head>"));
Wrapping the literals in the F() macro will keep them from being copied into SRAM at run time.

Ditching the String class is more complicated, but it is essential if your sketch is to run for more than a few minutes at a time.

Xendor


Those Strings are killing you. The massive amount of literals is killing you.

The literals can be dealt with easily.
          cliente.print(F("<head>"));
Wrapping the literals in the F() macro will keep them from being copied into SRAM at run time.

Ditching the String class is more complicated, but it is essential if your sketch is to run for more than a few minutes at a time.



I did that and work so good!! PaulS da rulz ! thx for all guys

Go Up