ARDUINO UNO WIFI REV2 - FLASH memory usage

Hello everybody,
Is it possible to load datas (i.e. HTML code) in flash memory to make a real server on an Arduino Wifi rev2 using this kind of prog: const char html_code PROGMEM = R"=====(xyz.......)====";
Thanks
Michel

That will work, but you have to make sure that the number of = signs is balanced in your example.

yes, the numbers of '=' is balanced in my prog, i've just forgotten one when i wrote my question.
In fact, my sketch compiles, but i can't get back the characters when i answer the client:Client.println(HTML_code);

That is the downside of using progmem.

You can get the characters by using the pgm_read_byte function.

You could try something like this.

char c = -1;
for (size_t i = 0; c; i++) {
  c = pgm_read_byte(html_code + i);
  Serial.print(c);
}

Thank you very much for this solution which runs. Sorry but i don't understand the syntax: for (size_t i = 0; c; i++)

I presume you know what the following means?

for (int i = 0; i < 10; i++)

The for-loop ends when the stop condition i < 10 is no longer true. In the snippet shared in post #4, we use a different stop condition: the character that we read from FLASH should not be zero (which indicates the end of the string).

for (int i = 0; c != 0; i++)

This can be abbreviated to:

for (int i = 0; c; i++)

And since we are using an array (sort of), it is customary to use the type size_t instead of int.

for (size_t i = 0; c; i++)

[edit]

P.S. Please mark the most helpful post as the solution, it prevents helpers spending time on a solved issue and it will lead people with the same question to the right answer directly.

1 Like

Thanks jfjlaros
You helped me so much. I learn every day something new with this community.
Kind regards. Michel

I re-open this thread with an other solution:
client.print((__FlashStringHelper*) page_html);

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.