Passing variable to the webserver.

global variable 

color = in this place i don't know whitch will best variable;


bfill.emit_p(PSTR(
   "HTTP/1.0 200 OK\r\n"
   "Content-Type: text/html\r\n"
   "Pragma: no-cache\r\n"
   "\r\n"
   "<meta http-equiv='refresh' content='6'/>"
   "<title>BodyColor</title>" 
   "<body style='background-color:$D'>"),
     color);

 return bfill.position();

void loop() 
{

if ((temperature > 60) || (humadity > 55) ) {
 
    color = in this place i don't know whitch will best variable ;
}
else {

color = in this place i don't know whitch will best variable;}

}

Hey,

I do not know how to pass variables to the page background changed from green to red when the condition 'if' is met. Someone help.

Do you mean that you do not know how to incorporate a variable into the HTTP string ?

If so, what should the string look like when the background is read and when it is green ?

Hi,
What format should I use this variable to pass HTTP to alter the ground. When using a variable of type char color [] = red{ nothing changes.

  if (digitalRead(inPin) == 0) {
    color = 'red';
  }
  else {

    color = 'green';

  }
    color = 'red';

Single quotes are for single characters. Can you post a picture of your keyboard with the 'red' key circled?

Hay,

Maybe I should correct my question.

I have webserwer with temerature and humadity measure. I want to change background color when temp. or humad. exeed some set value. Normal background should be green, after exeed some set val. sholud be change to red. That's all. Which variable will better use, sending to my HTML string. Color variables in HTML can be name=red, hex=#fff or rgb=255,22,0. In my code , variable name is "color" but in HTML is set $D. I corrected my first code.

Thx for all answer.

bfill.emit_p(PSTR(
   "HTTP/1.0 200 OK\r\n"
   "Content-Type: text/html\r\n"
   "Pragma: no-cache\r\n"
   "\r\n"
   "<meta http-equiv='refresh' content='6'/>"
   "<title>BodyColor</title>" 
   "<body style='background-color:$D'>"),
     color);

You can't put a variable ('color', whatever it's type is) into a fixed PSTR (in program memory).
You'll need a sprintf() for including a variable.
HTML is looking for a string so just make your 'color' variable a cstring, "red" or "green" or whatever hex codes HMTL wants.

Could you give me some example? How I should use it.

Ihave found solution himself. :slight_smile:

//global variable

char* myString[] = { "yellow", "red"}

static word homePage()
{

int z;

if ((temperature > 60) || (humadity > 55) ) {

z = 1; //warring red
}
else {

z = 0;} // normal yellow

bfill.emit_p(PSTR(
"HTTP/1.0 200 OK\r\n"
"Content-Type: text/html\r\n"
"Pragma: no-cache\r\n"
"\r\n"
""
"BodyColor"
""),
myString[z]);

return bfill.position();

}
void loop()
{
....

}