Webserver strange behaviour

Hi everybody

I'm new to arduino, and i'm stuck since one week with my problem.

The project is to build a touch screen (MCU Friend shield) interface to select material missing in a lab that will be displayed outside it on another arduino via I2C (master), and also accessible through the web using the ethernet shield.

So far i'm able to make the two arduino communicate, and updating the screen.
When i add the web server problems starts :

First one : if i do not press a button, the server is not accessible
Second one : if i select all the buttons , the webpage is well updated, then if i unselect on item, server is unaccessible.
Third one : let say i stay in a config where the page is accessible, after one night (maybe less) the server is no more accessible (all the other functions are still working)

I tried to comment the I2C communication, doesn't solved the issue

If someone has a hint, i will appreciate

Afficheur_slave_webserver.ino (17.1 KB)

 String matos [26]= { "Pipet 5ml", "Pipet 10ml", "Pipet 25 ml","Pipet Pasteur", "Tips 1000", "Tips 200", "Tips 20", "Tips 10 ", "Tips no Filter", "Eppi 2ml", "Eppi 1,5ml", "Eppi 0,5ml", "Gloves S", "Gloves M","Gloves L", "Falcon 15","Falcon 50", "Flask 25", "Flask 75", "Flask 150", "Surfanios", "Wipes", "White Bag", "Red bag", "Pipet Bag", "Tips bag" };

You do NOT need to piss away resources on the String class, wrapping constant strings. Change the type to const char *.

  #if defined(MCUFRIEND_KBV_H_)
uint16_t scrollbuf[320];    // my biggest screen is 320x480
#define READGRAM(x, y, buf, w, h)  tft.readGRAM(x, y, buf, w, h)
#else
uint16_t scrollbuf[320];    // Adafruit only does 240x320
// Adafruit can read a block by one pixel at a time
int16_t  READGRAM(int16_t x, int16_t y, uint16_t *block, int16_t w, int16_t h)
{
    uint16_t *p;
    for (int row = 0; row < h; row++) {
        p = block + row * w;
        for (int col = 0; col < w; col++) {
            *p++ = tft.readPixel(x + col, y + row);
        }
    }
}
#endif

Get your enter key fixed. Use white space. It's free.

 // draw screen and button     
    tft.fillScreen(BLACK);



  tft.drawRect(1, 1, 319, 20, WHITE);
  tft.fillRect(2, 2, 317, 18, YELLOW);
 
            
            tft.setTextSize(1);
            tft.setTextColor(BLACK);
             tft.setCursor(10,5);

Were you drunk when you typed this mess. Sober up, and use Tools + Auto Format, so you look like you car what you code looks like.

Put the button handling code in a function. Get all that out of loop().

Learn to use arrays. That code could be MUCH shorter, since it is so repetitious.

  Buffer[0]=table[0];
  Buffer[1]=table[1];
  Buffer[2]=table[2];
  Buffer[3]=table[3];
  Buffer[4]=table[4];
  Buffer[5]=table[5];
  Buffer[6]=table[6];
  Buffer[7]=table[7];
  Buffer[8]=table[8];
  Buffer[9]=table[9];
  Buffer[10]=table[10];
  Buffer[11]=table[11];
  Buffer[12]=table[12];
  Buffer[13]=table[13];
  Buffer[14]=table[14];
  Buffer[15]=table[15];
  Buffer[16]=table[16];
  Buffer[17]=table[17];
  Buffer[18]=table[18];
  Buffer[19]=table[19];
  Buffer[20]=table[20];
  Buffer[21]=table[21];
  Buffer[22]=table[22];
  Buffer[23]=table[23];
  Buffer[24]=table[24];
  Buffer[25]=table[25];

4 lines of code bloated to 25. Why? Are you paid by the line? Use a for loop!

If someone has a hint, i will appreciate

I can't even make sense of your code, because it is laid out so poorly. Put EVERY { on a line BY ITSELF. Put EVERY } on a line BY ITSELF. Use Tools + Auto Format.

I do NOT see any reason why you should have to press a button or hold your nose just right, or anything else, to handle a client request, since the call to webserver() is the last statement in loop(), and will be unconditionally executed, on every pass through loop().

Hi many thanks for the reply

Sadly i'm not drunk just ... not good at it.

Anyway i will try to make the code more clean following your advice, and optimise it in order not to waste memory