Loop with if? webserver dosen't work

hi guys i have this sketch:

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


byte mac[] = {0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED}; 
byte ip[] = {192, 168, 1, 3}; 
byte gateway[] = {192, 168, 1, 1};
byte subnet[] = {255, 255, 255, 0};

EthernetServer server(80);

String readString; 

boolean PORTONE = false; 
boolean GARAGE = false; 
boolean SCALA = false; 

IRsend My_Sender;
int khz=38; // frequenza

//ARIA CALDA
unsigned int C30[] = {4492,4432,596,1600,592,508,592,1608,588,1608,596,504,588,508,596,1604,592,504,596,504,596,1604,592,504,600,500,592,1604,600,1600,596,504,596,1600,596,504,596,504,588,1608,596,1600,596,1604,588,1608,600,1600,592,1604,592,1604,600,1600,592,508,596,500,592,508,596,504,596,504,588,508,596,1604,588,508,596,1604,588,1608,600,1600,592,1604,592,508,592,508,596,500,592,1608,596,500,592,508,596,504,596,504,588,1608,596,1604,592,5268,4520,4424,592,1608,596,504,588,1608,596,1604,592,504,600,500,592,1608,596,500,592,508,592,1604,592,508,596,504,596,1600,596,1604,588,508,596,1604,592,504,596,504,600,1600,592,1604,592,1604,600,1600,596,1600,592,1608,588,1608,596,1604,592,504,596,504,600,500,592,508,592,504,600,500,592,1604,592,508,592,1604,592,1608,596,1600,592,1608,588,508,596,504,596,504,588,1608,596,504,600,500,592,504,596,504,588,1612,592,1604,592,1000}; //AnalysIR Batch Export - RAW
unsigned int C29[] = {4488,4436,592,1604,592,508,592,1604,592,1608,596,504,588,512,592,1604,588,512,592,504,600,1600,592,508,596,500,592,1608,596,1600,596,504,596,1600,596,504,596,504,592,1604,600,1600,592,1604,592,1608,596,1600,596,1604,592,1604,588,1612,596,500,592,508,592,508,596,500,592,508,592,508,596,1600,596,504,596,1604,592,504,596,1604,592,1604,592,508,592,508,596,500,592,1608,596,504,588,1608,600,500,592,508,592,1604,592,1604,600,5264,4516,4432,596,1600,592,508,596,1600,596,1604,588,512,592,504,600,1600,592,508,596,500,592,1608,596,504,588,508,596,1604,588,1608,596,504,592,1604,600,500,592,508,592,1604,592,1608,596,1600,596,1604,592,1604,588,1612,596,1600,592,1608,588,508,592,508,596,504,588,508,596,504,596,504,588,1608,600,500,592,1608,596,500,592,1608,596,1600,596,504,600,500,588,508,596,1604,592,508,592,1604,592,508,596,500,600,1600,596,1600,592,1000}; //AnalysIR Batch Export - RAW
unsigned int C28[] = {4496,4424,592,1608,596,504,592,1604,600,1600,592,504,600,500,592,1608,596,500,592,508,596,1604,588,508,596,504,600,1600,592,1604,592,508,592,1604,592,508,596,504,596,1600,596,1604,592,1604,600,1600,592,1604,592,1604,600,1600,596,1600,596,504,596,504,600,500,592,504,596,504,600,500,592,1604,600,500,592,508,596,504,596,1600,596,1604,588,508,596,504,600,500,592,1604,600,1600,596,1600,592,508,596,504,588,1608,596,1604,592,5268,4520,4428,600,1596,596,504,600,1600,596,1600,592,508,596,504,596,1600,596,504,600,500,592,1604,588,512,592,508,592,1604,592,1604,592,508,592,1608,588,508,596,504,596,1604,592,1604,588,1612,596,1600,592,1608,588,1608,596,1604,592,1604,588,512,592,504,600,500,588,512,592,508,596,500,600,1600,596,504,596,500,592,508,596,1604,592,1604,588,512,592,508,592,504,600,1600,596,1600,592,1608,588,508,592,508,596,1604,592,1604,588,1000}; //AnalysIR Batch Export - RAW


void setup(){
  Ethernet.begin(mac, ip, gateway, subnet);

  pinMode(5, OUTPUT);
  pinMode(6, OUTPUT);
  pinMode(7, OUTPUT);    

  Serial.begin(9600);
  digitalWrite(5, HIGH);
  digitalWrite(6, HIGH);
  digitalWrite(7, HIGH);
}

void loop(){
  EthernetClient client = server.available();

  if (client) {
    boolean currentLineIsBlank = true;

    while (client.connected()) {
      if (client.available()) {  
        char c = client.read();
        readString.concat(c);   
        if (c == '\n' && currentLineIsBlank) {
          Serial.print(readString);
          
 

          //PORTONE CASA
          if(readString.indexOf("L=1") > 0) {
            digitalWrite(5, LOW);
            delay(500);
            digitalWrite(5, HIGH);
            PORTONE = true;      
          }

          // GARAGE
          if(readString.indexOf("L=2") > 0) {
            digitalWrite(6, LOW);
            delay(500);
            digitalWrite(6, HIGH);
            GARAGE = true;      
          }
          
          //LUCE SCALA
          if(readString.indexOf("L=3") > 0) {
            digitalWrite(7, LOW);
            delay(500);
            digitalWrite(7, HIGH);
            SCALA = true;      
          }
        /*  
          // CONDIZIONATORE -- ARIA CALDA --
          if(readString.indexOf("C=30") > 0) 
            My_Sender.IRsendRaw::send(C30, sizeof(C30)/sizeof(int), khz);

          if(readString.indexOf("C=29") > 0) 
            My_Sender.IRsendRaw::send(C29, sizeof(C29)/sizeof(int), khz);
            
          if(readString.indexOf("C=28") > 0) 
            My_Sender.IRsendRaw::send(C28, sizeof(C28)/sizeof(int), khz);
            
          if(readString.indexOf("C=27") > 0) 
            My_Sender.IRsendRaw::send(C27, sizeof(C27)/sizeof(int), khz);
            
          if(readString.indexOf("C=26") > 0) 
            My_Sender.IRsendRaw::send(C26, sizeof(C26)/sizeof(int), khz);
            
          if(readString.indexOf("C=25") > 0) 
            My_Sender.IRsendRaw::send(C25, sizeof(C25)/sizeof(int), khz);
            
          if(readString.indexOf("C=24") > 0) 
            My_Sender.IRsendRaw::send(C24, sizeof(C24)/sizeof(int), khz);
            
          if(readString.indexOf("C=23") > 0) 
            My_Sender.IRsendRaw::send(C23, sizeof(C23)/sizeof(int), khz);
            
          if(readString.indexOf("C=22") > 0) 
            My_Sender.IRsendRaw::send(C22, sizeof(C22)/sizeof(int), khz);
            
          if(readString.indexOf("C=21") > 0) 
            My_Sender.IRsendRaw::send(C21, sizeof(C21)/sizeof(int), khz);
            
          if(readString.indexOf("C=20") > 0) 
            My_Sender.IRsendRaw::send(C20, sizeof(C20)/sizeof(int), khz);
            
          if(readString.indexOf("C=19") > 0) 
            My_Sender.IRsendRaw::send(C19, sizeof(C19)/sizeof(int), khz);
            
          if(readString.indexOf("C=18") > 0) 
            My_Sender.IRsendRaw::send(C18, sizeof(C18)/sizeof(int), khz);
            
          if(readString.indexOf("C=17") > 0) 
            My_Sender.IRsendRaw::send(C17, sizeof(C17)/sizeof(int), khz);
          
          
          
          
          // CONDIZIONATORE -- ARIA FREDDA --
          if(readString.indexOf("F=30") > 0) 
            My_Sender.IRsendRaw::send(F30, sizeof(F30)/sizeof(int), khz);
            
          if(readString.indexOf("F=29") > 0) 
            My_Sender.IRsendRaw::send(F29, sizeof(F29)/sizeof(int), khz);

          if(readString.indexOf("F=28") > 0) 
            My_Sender.IRsendRaw::send(F28, sizeof(F28)/sizeof(int), khz);

          if(readString.indexOf("F=27") > 0) 
            My_Sender.IRsendRaw::send(F27, sizeof(F27)/sizeof(int), khz);

          if(readString.indexOf("F=26") > 0) 
            My_Sender.IRsendRaw::send(F26, sizeof(F26)/sizeof(int), khz);

          if(readString.indexOf("F=25") > 0) 
            My_Sender.IRsendRaw::send(F25, sizeof(F25)/sizeof(int), khz);

          if(readString.indexOf("F=24") > 0) 
            My_Sender.IRsendRaw::send(F24, sizeof(F24)/sizeof(int), khz);

          if(readString.indexOf("F=23") > 0) 
            My_Sender.IRsendRaw::send(F23, sizeof(F23)/sizeof(int), khz);

          if(readString.indexOf("F=22") > 0) 
            My_Sender.IRsendRaw::send(F22, sizeof(F22)/sizeof(int), khz);

          if(readString.indexOf("F=21") > 0) 
            My_Sender.IRsendRaw::send(F21, sizeof(F21)/sizeof(int), khz);

          if(readString.indexOf("F=20") > 0) 
            My_Sender.IRsendRaw::send(F20, sizeof(F20)/sizeof(int), khz);

          if(readString.indexOf("F=19") > 0) 
            My_Sender.IRsendRaw::send(F19, sizeof(F19)/sizeof(int), khz);

          if(readString.indexOf("F=18") > 0) 
            My_Sender.IRsendRaw::send(F18, sizeof(F18)/sizeof(int), khz);

          if(readString.indexOf("F=17") > 0) 
            My_Sender.IRsendRaw::send(F17, sizeof(F17)/sizeof(int), khz);


*/

          // INIZIO DICHIARAZIONE PAGINA HTML
          client.println("HTTP/1.1 200 OK");
          client.println("Content-Type: text/html");
          client.println();
          client.print("<html><head><title>ARDUINO Controllo via WEB</title><meta http-equiv='Content-Type' content='text/html; charset=iso-8859-1' ></head><body>");

....continue....

There is a problem.
When i comment this part :

if(readString.indexOf("C=30") > 0) 
            My_Sender.IRsendRaw::send(C30, sizeof(C30)/sizeof(int), khz);
....
....

my webserver work. How to solve this problem?
i have cutted the code… for the forum
Thank you

Put the massive arrays in PROGMEM, and start using the F() macro for constant strings

can u write a example please?
thank you!!

can u write a example please?

Yes, I could, but why?
There are plenty of examples already.

Yes but i haven't understand with implement in my code...
thank you

client.println(F("HTTP/1.1 200 OK"));

etc

Yes, and the array???
sorry but i'm noob

Example

The following code fragments illustrate how to read and write unsigned chars (bytes) and ints (2 bytes) to PROGMEM.
#include <avr/pgmspace.h>

// save some unsigned ints
PROGMEM prog_uint16_t charSet = { 65000, 32796, 16843, 10, 11234};

in my case:

PROGMEM prog_uint16_t myArray[] = {C30[], C29[], C28, C27, ... }

???
Thank you

EDIT:

PROGMEM prog_uint16_t C30[] = {4492,4432,596,1600,592,508,592,1608,588,1608,596,504,588,508,596,1604,592,504,596,504,596,1604,592,504,600,500,592,1604,600,1600,596,504,596,1600,596,504,596,504,588,1608,596,1600,596,1604,588,1608,600,1600,592,1604,592,1604,600,1600,592,508,596,500,592,508,596,504,596,504,588,508,596,1604,588,508,596,1604,588,1608,600,1600,592,1604,592,508,592,508,596,500,592,1608,596,500,592,508,596,504,596,504,588,1608,596,1604,592,5268,4520,4424,592,1608,596,504,588,1608,596,1604,592,504,600,500,592,1608,596,500,592,508,592,1604,592,508,596,504,596,1600,596,1604,588,508,596,1604,592,504,596,504,600,1600,592,1604,592,1604,600,1600,596,1600,592,1608,588,1608,596,1604,592,504,596,504,600,500,592,508,592,504,600,500,592,1604,592,508,592,1604,592,1608,596,1600,592,1608,588,508,596,504,596,504,588,1608,596,504,600,500,592,504,596,504,588,1612,592,1604,592,1000}; //AnalysIR Batch Export - RAW
PROGMEM prog_uint16_t C29[] = {4488,4436,592,1604,592,508,592,1604,592,1608,596,504,588,512,592,1604,588,512,592,504,600,1600,592,508,596,500,592,1608,596,1600,596,504,596,1600,596,504,596,504,592,1604,600,1600,592,1604,592,1608,596,1600,596,1604,592,1604,588,1612,596,500,592,508,592,508,596,500,592,508,592,508,596,1600,596,504,596,1604,592,504,596,1604,592,1604,592,508,592,508,596,500,592,1608,596,504,588,1608,600,500,592,508,592,1604,592,1604,600,5264,4516,4432,596,1600,592,508,596,1600,596,1604,588,512,592,504,600,1600,592,508,596,500,592,1608,596,504,588,508,596,1604,588,1608,596,504,592,1604,600,500,592,508,592,1604,592,1608,596,1600,596,1604,592,1604,588,1612,596,1600,592,1608,588,508,592,508,596,504,588,508,596,504,596,504,588,1608,600,500,592,1608,596,500,592,1608,596,1600,596,504,600,500,588,508,596,1604,592,508,592,1604,592,508,596,500,600,1600,596,1600,592,1000}; //AnalysIR Batch Export - RAW
PROGMEM prog_uint16_t C28[] = {4496,4424,592,1608,596,504,592,1604,600,1600,592,504,600,500,592,1608,596,500,592,508,596,1604,588,508,596,504,600,1600,592,1604,592,508,592,1604,592,508,596,504,596,1600,596,1604,592,1604,600,1600,592,1604,592,1604,600,1600,596,1600,596,504,596,504,600,500,592,504,596,504,600,500,592,1604,600,500,592,508,596,504,596,1600,596,1604,588,508,596,504,600,500,592,1604,600,1600,596,1600,592,508,596,504,588,1608,596,1604,592,5268,4520,4428,600,1596,596,504,600,1600,596,1600,592,508,596,504,596,1600,596,504,600,500,592,1604,588,512,592,508,592,1604,592,1604,592,508,592,1608,588,508,596,504,596,1604,592,1604,588,1612,596,1600,592,1608,588,1608,596,1604,592,1604,588,512,592,504,600,500,588,512,592,508,596,500,600,1600,596,504,596,500,592,508,596,1604,592,1604,588,512,592,508,592,504,600,1600,596,1600,592,1608,588,508,592,508,596,1604,592,1604,588,1000}; //AnalysIR Batch Export - RAW

PROGMEM prog_uint16_t *item = {C30,C29,C28…};

it’s ok?

it's ok?

No, it isn't. Did you even bother trying to compile?

Sorry sorry :slight_smile:

etc...
...................
........................
PROGMEM prog_uint16_t  F17[] = {4492,4432,592,1604,592,508,592,1604,592,1608,596,504,588,512,592,1604,588,512,592,504,596,1604,592,508,596,500,592,1608,596,1600,592,508,596,1600,596,504,596,504,600,1596,596,1604,592,1604,600,1600,596,1600,592,1608,596,1600,596,1604,592,508,592,508,596,500,592,508,592,508,596,500,592,508,592,512,592,504,588,508,596,504,596,504,588,512,592,504,596,1604,592,1604,592,1608,596,1604,588,1608,600,1596,596,1604,592,1604,600,5264,4512,4436,592,1604,592,508,592,1608,596,1600,596,504,600,500,588,1608,600,500,592,508,592,1604,592,508,592,508,596,1600,596,1604,588,508,596,1604,588,512,592,504,600,1600,592,1604,592,1608,596,1600,596,1604,588,1608,596,1604,592,1604,600,500,592,508,596,500,600,500,592,508,596,504,596,500,592,508,596,504,596,504,592,508,592,504,600,500,592,508,592,1604,592,1608,596,1600,592,1608,588,1608,596,1604,592,1604,600,1600,596,1000}; //AnalysIR Batch Export - RAW

//OFF
PROGMEM prog_uint16_t OFF[] = {4492,4432,592,1608,588,508,596,1604,588,1608,596,504,588,512,592,1604,600,500,592,508,596,1600,592,508,596,504,596,1600,596,1604,588,512,592,1604,592,508,592,1604,592,1608,596,1600,596,1604,588,508,596,1604,588,1608,596,1604,592,508,592,508,596,500,592,508,596,1600,592,508,596,504,596,1600,596,1604,592,1604,600,500,592,508,592,508,596,500,592,508,592,508,596,504,588,508,596,1604,588,1608,596,1604,592,1608,596,1600,596,5264,4524,4424,592,1608,596,504,588,1608,596,1604,592,504,596,504,600,1600,592,508,596,500,592,1608,596,500,592,508,596,1604,588,1608,596,504,588,1608,600,500,592,1608,596,1600,592,1608,588,1608,596,504,588,1608,596,1604,592,1608,596,500,592,508,596,504,596,500,592,1608,596,504,588,508,596,1604,592,1604,600,1600,592,508,596,500,592,508,592,508,596,504,588,508,596,504,596,504,588,1608,596,1604,592,1604,592,1608,596,1600,592,1000}; //AnalysIR Batch Export - RAW

PROGMEM prog_uint16_t *IR[] = {C30, C29, C28, C27, C26, C25, C24, C23, C22, C21, C20, C19, C18, C17, F30, F29, F28, F27, F26, F25, F24, F23, F22, F21, F20, F19, F18, F17, OFF};

And i edited here...

          if(readString.indexOf("C=30") > 0)
            My_Sender.IRsendRaw::send(IR[0], sizeof(IR[0])/sizeof(int), khz);

compile [OK] but dosen't work... why?

but dosen’t work… why?

Because you haven’t provided a method to read the data from PROGMEM.

I have tried...:

unsigned int buffer[256];

in void loop()

if(readString.indexOf("C=30") > 0){
            strcpy_P(buffer, (int*)pgm_read_word(&(IR[0])));

            My_Sender.IRsendRaw::send(IR[0], sizeof(IR[0])/sizeof(int), khz);
          }
sketch_arduino_con_raw.ino: In function 'void loop()':
sketch_arduino_con_raw:122: error: cannot convert 'unsigned int*' to 'char*' for argument '1' to 'char* strcpy_P(char*, const prog_char*)'

Can you help me please?

Why not forget your IR controller web server for a little while, and get comfortable with using PROGMEM?

Ok ok! i have created new sketch with array and progmem!
i don't understand...
how read this progmem!
I have this:

PROGMEM prog_uint16_t  array[] = {1,2,3,4,5,6,7,8,9...};

See reply #7.

unsigned int displayInt;
int k;    // counter variable
char myChar;  

// read back a 2-byte int
 displayInt = pgm_read_word_near(charSet + k)

this?? displayInt = pgm_read_word_near(charSet + k)

i have tried this but i recive:

sketch_arduino_new: In function 'void loop()':
sketch_arduino_new:32: error: 'charSet' was not declared in this scope

what's CharSet??

I'll start posting more than snippets of answers when you start posting more than snippets of code.

Hi this is my sketch:

#include <avr/pgmspace.h>

PROGMEM prog_uint16_t  array1[] = {1,2,3,4,5,6,7,8,9};
PROGMEM prog_uint16_t  array2[] = {10,11,12,13,14,15,16,17,18,19};

PROGMEM prog_uint16_t *item[] = {array1,array2};
unsigned int displayInt;
int k;  

void setup()
{
  Serial.begin(9600);
}
void loop() {
  
   displayInt = pgm_read_word_near(item[0] + k);
  Serial.println(displayInt);
  delay(1000);
}

Serial monitor print “1”
but if i set k++

void loop() {
  
   displayInt = pgm_read_word_near(item[0] + k);
   k++;
  Serial.println(displayInt);
  delay(1000);
}


i have this output:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
104
122
821
9233
48671
61391
57560

any solution?

any solution?

Stop printing anonymous data.
Stop reading when you reach the end of the array.