Using Progmem and Builing Strings with muiltiple variables.

Hi All,

I am trying to build a web interface to one of my projects running on an Arduino Mega. I had found Arduino Playground - WebServer and liked the structure because it provides for multiple pages allowing the separation of different levels of Running information and setup information.

I have come across an issue when modifying it for my needs. I am trying to setup the web page to display sensor data but am having issues with inserting the variables into the progmem char value.

This is an example of the section of code I am trying to modify. For the full sketch of the web server see: Arduino Playground - WebServer

// Page 2
PROGMEM prog_char http_uri2[] = "/page2";
PROGMEM prog_char content_title2[] = "<h2>Page 2</h2>";
PROGMEM prog_char content_page2[] = "<hr /><h3>Content of Page 2</h3><p>Nothing here.</p>";

I have been able to modify the Title, and Headings with out issue. Where I have stumbled is in changing "

Nothing here.

" to suit my needs. I have a series of values showing operation time and operation mode and am trying to display there values here. I have tried numerous ways of modifying this line of code to include the needed values. The Ideal output would look like "

Current Run Time: intRT Total Run Time: intRT_T Operation Mode: intMode

". intMode,intRT, and intRT_T are the variables I am trying to access.

Can anyone help shed some light on how I would go about doing this or a better method for it?

Thanks
Chris

Where I have stumbled is in changing "

Nothing here.

" to suit my needs.

You need to store the static parts in PROGMEM, not the dynamic parts. You can't change data in PROGMEM, so it makes no sense to store the dynamic part of the string.

Create two variables, content_page2_header and content_page2_footer that you store in PROGMEM. When it is time to output page 2, output the header, the dynamic stuff, and the footer.

If you want to store a string in PROGMEM that includes placeholders, the placeholder should include a recognizable symbol, like %intMode. This makes searching for them, after you have copied the string out of PROGMEM, but before you send it, much easier.

Exactly how to do that depends on how you copy the data out of PROGMEM.