{Solved} Help With PROGMEM Webserver Example

Hello,

I have been using the progmem web-server example found at:http://arduino.cc/playground/Code/WebServer. Out of the two examples shown, the one I am referencing is the first one, higher up on the page than the other. All that is needed to get the example server working is change the IP address to an unused one one your network(in my case 192.168.1.230), plug the Arduino uno into your router, and upload the code.

Libraries it is using:
#include <SPI.h>
#include <Ethernet.h>
#include <avr/pgmspace.h>
#include <string.h>

This example web-server displays a title webpage with links across the top to other pages. What I am trying to do seems simple, but I haven't been able to find a way, both through searching and forum scouring.

What I want to do:
On the first http page, shown in the code as "Page 1", There is a bit of text that says "Nothing... yet.".

I am trying to change that text "Nothing... yet." to either "On" or "Off" based on the reading from an analogread command in a function that I am adding lower in the code.

But, because the text ""Nothing... yet." is inside of an array (or array pointer), I cant change it.

I have looked into changing elements in arrays, but this web-server example uses arrays in a way that I can't locate which place(or element) in the array it is, to change the text.

This is the idea of how I want to change it:

Example code(unchanged):

PROGMEM prog_char content_page1[] = "<hr /><h3>Content of Page 1</h3><p>Nothing... yet.</p>
<form action=\"/login\" method=\"POST\"><input type=\"text\" name=\"prova\"><input type=\"submit\" value=\"post\"></form>";

Example code(with my code):

PROGMEM prog_char content_page1[] = "<hr /><h3>Content of Page 1</h3><p>onOrOff();</p>
<form action=\"/login\" method=\"POST\"><input type=\"text\" name=\"prova\"><input type=\"submit\" value=\"post\"></form>";

///////Further Down in the Code/////////
void PROGMEM onOrOff() {
if(analogRead(5)<500)  //965 = on, 0 = off
      {
        return "On";
      }
      else
        {
          return "Off";
        }
}

This is the idea that I have to change it, not the code that must be used. I know this code wouldn't work anyways.

I have tried numerous ways to try and change that text, but no success.

I have even added code that printed every single char from a certain array(that I chose) out to serial when ever I would hit a certain button, and even with that, I couldn't find the http data chars "Nothing... yet.". I didn't try EVERY single array tho.

I take any help, ideas, examples, etc.

I really have no preference on the method, I can alter it after I get it working.

I am stuck.

I am still having trouble trying to find exactly in this webserver example where to tag each individual char, in real time, as it goes out. I know that I would have to put a %{} around my HTML text, but where in this code do I setup the varHandler and reqHandler like you have.

Just to repeat what I have said before, All I want to do is change a button label or text label to "on" or "off" depending on what the corresponding analogRead or digitalRead is getting. I would use an simpler webserver/PROGMEM example for my needs, but this is the only one I could find. The buttons work right now, and turn on pins, but I have no way to know which pins are "on" or "off".

Full code is attached: its too big to post.

8_light_webserver_control.ino (25.4 KB)

I ended up doing something like splitting up the print statements. I inserted my monitoring code in between where the title is printed to HTML and where the Body is printed to HTML, and it ended up looking pretty good.

FYI for future readers though...If you want to add any more code to this monitoring section, either use PROGMEM or the SD card to store the html, because at this point, this program is pretty close to its limit.

Thank you Delta_G

/**********************************************************************************************************************
*                                                              Send Pages
***********************************************************************************************************************/
void PROGMEM sendPage(EthernetClient client,struct HTTP_DEF http_def) {

  // send HTML header
  // contentPrinter(client,(char*)pgm_read_word(&(contents_main[CONT_HEADER])));
  contentPrinter(client,(char*)pgm_read_word(&(contents_main[CONT_TOP])));

  // send menu
  contentPrinter(client,(char*)pgm_read_word(&(contents_main[CONT_MENU])));

  // send title
  contentPrinter(client,(char*)pgm_read_word(&(contents_titles[http_def.pages-1])));
  
/**********************************************************************************************************************
*                                                            Monitor (Analog and Digital channel checks)
***********************************************************************************************************************/

  if(analogRead(5)>200) 
  {client.print(" [***NE***] ");
   //client.print(analogRead(5));
 }
  else if(analogRead(5)<200)   
  {client.print(" [___NE___] ");}
  //client.println("
"); 

   if(analogRead(4)>200) 
  {client.print(" [***N***] ");
   //client.print(analogRead(4));
 }
  else if(analogRead(4)<200)   
  {client.print(" [___N___] ");}
  //client.println("
");
 
   if(analogRead(3)>200) 
  {client.print(" [***NW***] ");
   //client.print(analogRead(3));
 }
  else if(analogRead(3)<200)   
  {client.print(" [___NW___] ");
}
  //client.println("
"); 
 
   if(analogRead(2)>200) 
  {client.print(" [***W***] ");
   //client.print(analogRead(2));
 }
  else if(analogRead(2)<200)   
  {client.print(" [___W___] ");}
  //client.println("
");
  
   if(analogRead(1)>200) 
  {client.print(" [***SW***] ");
   //client.print(analogRead(1));
 }
  else if(analogRead(1)<200)   
  {client.print(" [___SW___] ");}
  //client.println("
"); 

   if(analogRead(0)>200) 
  {client.print(" [***S***] ");
   //client.print(analogRead(0));
 }
  else if(analogRead(0)<200)   
  {client.print(" [___S___] ");}
  //client.println("
"); 
  
   if(digitalRead(8)!=0) 
  {client.print(" [***SE***] ");
   //client.print(digitalRead(8));
 }
  else if(digitalRead(8)==0)   
  {client.print(" [___SE___] ");}
  //client.println("
"); 
 
  if(digitalRead(7)!=0) 
  {client.print(" [***E***] ");
   //client.print(digitalRead(7));
 }
  else if(digitalRead(7)==0)   
  {client.print(" [___E___] ");}
  client.println("
");   
  //***********************************************End Monitor********************************************************

  // send the body for the requested page
  sendContent(client,http_def.pages-1);

  client.print("
");
  // send POST variables
  client.print(vars);

  // send footer
  contentPrinter(client,(char*)pgm_read_word(&(contents_main[CONT_FOOTER])));
}