deleting values

I need help. I wrote a program for controlling the TV with the help of Arduino and web interface. I have attached IR LED 3 and IR receivers on the 5th
Originally I thought html code, save to SD. After about 10 rewrite the program I was looking for a bug that is also reflected in the simplified code. Following the adoption of the headers from the browser to store the first row to the variable (lineone) then sends the HTML browser. Transformations subsequently evaluate. The problem comes when you add additional html code. This transformation is not empty and what to evaluate.
I attach the code. Pro Setup Error simply uncomment another html code.
I’ve already thought of it and bad arduino.

Can you please help?

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

// Enter a MAC address and IP address for your controller below.
// The IP address will be dependent on your local network:
byte mac[] = {0x22, 0x11, 0x1A, 0x0B, 0x41, 0x56 };
IPAddress ip(10,0,0, 150); // IP address, may need to change depending on network

// Initialize the Ethernet server library
// with the IP address and port you want to use 
// (port 80 is default for HTTP):
EthernetServer server(80);

String lineone = "";
IRsend irsend;
unsigned int raw1[] = {16340,8950,4350,600,500,600,500,600,1650,600,500,600,500,600,500,600,500,600,500,600,1600,600,1650,550,550,550,1650,600,1600,600,1650,600,1600,600,1650,600,500,600,1600,600,500,600,500,600,500,600,500,600,500,600,500,600,1650,600,500,600,1600,600,1650,600,1600,600,1650,600,1600,600,1650,600};
String baf = "";

void setup() {
 // Open serial communications and wait for port to open:
   while (!Serial) {
    ; // wait for serial port to connect. Needed for Leonardo only
  // start the Ethernet connection and the server:
  Ethernet.begin(mac, ip);
  Serial.print("server is at ");
    // disable the SD card by switching pin 4 high
    // not using the SD card in this program, but if an SD card is left in the socket,
    // it may cause a problem with accessing the Ethernet chip, unless disabled
    pinMode(4, OUTPUT);
    digitalWrite(4, HIGH);  

void loop() {
  // listen for incoming clients
  EthernetClient client = server.available();
  if (client) {
    Serial.println("new client");
    // an http request ends with a blank line
//    lineone = "";
    boolean currentLineIsBlank = true;
    baf = "";
    byte radek = 0;
    while (client.connected()) {
      if (client.available()) {
        char c =;
        baf += 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("<!DOCTYPE HTML>");
          //client.println("<meta name='viewport' content='initial-scale=1.0,minimum-scale=1.0,maximum-scale=1.0,width=device-width,height=device-height,target-densitydpi=device-dpi,user-scalable=yes' />");
          client.println("<meta name='viewport' content='width=device-width, user-scalable=no'>");

          client.println("<title>Arduinio Server - REMOTE control</title>");
          // output the value of each analog input pin
          client.println("<a href='?but01=101'><button style='background:red;width:49%;height:40px'>POWER</button></a>");
          client.println("<a href=''><button style='background:green;width:49%;height:40px'>MUTE</button></a>

          client.println("<a href='?but01=103'><button style='background:green;width:49%;height:40px'>VOL+</button></a>");
	  client.println("<a href='?but01=104'><button style='background:green;width:49%;height:40px'>PROG+</button></a>

          client.println("<a href='?but01=105'><button style='background:green;width:49%;height:40px'>VOL-</button></a>");
	  client.println("<a href='?but01=201'><button style='background:green;width:49%;height:40px'>PROG-</button></a>
          client.println("<center><a href='?but01=105'><button style='background:green;width:49%;height:40px'>UP</button></a></center>
          client.println("<a href='?but01=105'><button style='background:green;width:49%;height:40px'>LEFT</button></a>");
	  client.println("<a href='?but01=201'><button style='background:green;width:49%;height:40px'>RIGHT</button></a>
          client.println("<center><a href='?but01=105'><button style='background:green;width:49%;height:40px'>DOWN</button></a></center>

        if (c == '\n') {
          // you're starting a new line
          radek ++;
          if (radek == 1) {
            lineone = baf;
            baf = ""; 
          currentLineIsBlank = true;
        else if (c != '\r') {
          // you've gotten a character on the current line
          currentLineIsBlank = false;
    // give the web browser time to receive the data
    // close the connection:
    Serial.println("client disonnected");
    if (lineone.length()>14) {
      String temp;
      int indexbut = lineone.indexOf("but");  //najde but v prvnim radku
      if (indexbut != -1) {                  //pokud BUT existuje alespon jednou sloz nazev souboru
        temp = lineone.substring(indexbut+6,indexbut+9);  //vyrizne jmeno souboru
      } else { temp = "nic"; }
      if (temp=="103") {
        for (int i = 0; i < 4; i++) {
          irsend.sendNEC(0x20DF40BF, 32);
      if (temp=="105") {
        for (int i = 0; i < 4; i++) {
          irsend.sendNEC(0x20DFC03F, 32);
      if (temp=="101") {
        for (int i = 0; i < 2; i++) {
          irsend.sendNEC(0x20DF10EF, 32);
      if (temp=="201") {
        for (int i = 0; i < 2; i++) {
          irsend.sendRaw(raw1, 68, 38);

How much memory SRAM is used?


The board has ATmega328. Size SRAM is therefore 2KB.
USED ??size of the current program? How do I find?

What you described was typically what happens when you run out of memory. Any serious Arduino project always need to understand the memory footprint (SRAM, PROGMEM, EEMEM). The new IDE (1.5.5 beta) will report the memory usage. There are also a few utility functions available in AVR. Just do a search and you will find them.

That was the first take on this subject. If you get the memory footprint and it is too high what to do about that?

The first thing is to understand that many variables (in SRAM) are actually constants and can be moved into program memory. This makes more SRAM available but will require more program memory. More advanced is to understand how to transform global data structures to temporary on the stack.

You are using a lot of strings. Move them to program memory.
You have a constant vector of integer. Move them…

Now moving data to program memory is easy. The hard problem is access it as you cannot rely on the compiler to help with access code. You have to write it yourself. Again just do a search and you will find how to do this.

I see that you are using two Arduino libraries that produce memory issues; String and Ethernet. String uses the heap and Ethernet TCP/IP socket will force you to construct the whole message before sending. There are better libraries and solutions. Search and…


thank you very much

understand the issues. Learn and transcripts.