Data showing up on Serial, but on webserver NaN. SOLVED, WORKS! No FAIL :-)

I have been struggling with a sketch for days now, and have finally achieved something very close to my goal.

Here is what I have working, and the ")<---" in the CODE will show where I was able to get things working, and what lines I entered.

ATTN: This WORKS. Will NOT FAIL due to /html tag, though I don't understand why. No complaints. Just curious.
CODE:

// Command for server GET and POST request.
void serverCmd(WebServer &server, WebServer::ConnectionType type, char *url_tail, bool tail_complete)
{

int chk;                                       
float t = dht.readTemperature();      )<------ THIS block of 3 lines.
float h = dht.readHumidity();           

  if (type == WebServer::POST)
  {
    bool repeat;
    char name[20], value[16];
    do
    {
      repeat = server.readPOSTparam( name, 20, value, 16);

      if (strcmp( name, "On" ) == 0)
      {
        setLatchChannelOn( atoi(value) );
      }
      if (strcmp( name, "Off" ) == 0)
      {
        setLatchChannelOff( atoi(value) );
      }
      if (strcmp( name, "AllOff" ) == 0)
      {
        sendRawValueToLatch1(0);
        sendRawValueToLatch2(0);
      } 
    } while (repeat);  
    
    server.httpSeeOther(PREFIX);
    return;
  }
  
  server.httpSuccess();

  if (type == WebServer::GET)

  { 
    P(message) =

      "<html>"
      "<head>"
      "<meta http-equiv=\"refresh\" content=\"5\">"             )<-----THIS line
      "<title>"
      "PAGE"
      "</title>"
      "</head>"
      "<body>"      
      "<H1 style='font-family:hobo std;'> PAGE</H1>"
            
      "<form action='/page' method='POST'>"

      "<p><button name='AllOff' value='0'>All Off</button></p>"
      
      "<p><button type='submit' name='On' value='1'>1 On</button><button type='submit' name='Off' value='1'>Off</button>.......<button type='submit' name='On' value='2'>2 On</button><button type='submit' name='Off' value='2'>Off</button></p>"
      "<p><button type='submit' name='On' value='3'>3 On</button><button type='submit' name='Off' value='3'>Off</button>.......<button type='submit' name='On' value='4'>4 On</button><button type='submit' name='Off' value='4'>Off</button></p>"
      "<p><button type='submit' name='On' value='5'>5 On</button><button type='submit' name='Off' value='5'>Off</button>.......<button type='submit' name='On' value='6'>6 On</button><button type='submit' name='Off' value='6'>Off</button></p>"
      "<p><button type='submit' name='On' value='7'>7 On</button><button type='submit' name='Off' value='7'>Off</button>.......<button type='submit' name='On' value='8'>8 On</button><button type='submit' name='Off' value='8'>Off</button></p>"
      
      
      "</form>"

      "</body></html>";

    server.printP(message);
{                                                            
            server.println("<H3>");                    
            server.print("Temperature: ");          
            server.println("</H3>");                   
            server.println("<H2>");                    
            server.print(t*1.8+32);                   
            server.println(" °");                
            server.println("F");                         
            server.println("</H2>");                  
                                                             
            server.println("<H3>");                   )   <--- This, from { to }
            server.print("Humidity: ");               
            server.println("</H3>");                  
            server.println("<p />");                  
            server.println("<H2>");                   
            server.print(h);                             
            server.print(" %\t");                       
            server.println("</H2>");                   
                                                             
      }                                                      
   }
}
//SETUP
void setup()
{
  Ethernet.begin(mac, ip);
  Wire.begin();
  Serial.begin( 9600 );
  dht.begin();

  webserver.setDefaultCommand(&serverCmd);

  webserver.begin();

  initialiseShield(SHIELD_1_I2C_ADDRESS);
  sendRawValueToLatch1(0);    
  
}
//LOOP
void loop()
{

float t = dht.readTemperature();
float h = dht.readHumidity();

  if (isnan(t) || isnan(h)) {
    Serial.println(F("Failed to read from DHT"));
  } else {
    Serial.print(F("Temperature: "));
    Serial.print(t);
    Serial.println(F(" *C"));
    Serial.print(F("Humidity: "));
    Serial.print(h);
    Serial.print(F(" %\t"));
    delay(1000);
  }
  webserver.processConnection();

}
//...->
void initialiseShield(int shieldAddress)
{
  Wire.beginTransmission(shieldAddress);
  Wire.write(0x12);
  Wire.write(0x20); // use table 1.4 addressing
  Wire.endTransmission();

  Wire.beginTransmission(shieldAddress);
  Wire.write(0x00); // IODIRA register
  Wire.write(0x00); // Set all of bank A to outputs
  Wire.endTransmission();
}
//...->
void toggleLatchChannel(byte channelId)
{
  if( channelId >= 1 && channelId <= 8 )
  {
    byte shieldOutput = channelId;
    byte channelMask = 1 << (shieldOutput - 1);
    shield1BankA = shield1BankA ^ channelMask;
    sendRawValueToLatch1(shield1BankA);
  }
}
//...->
void setLatchChannelOn (byte channelId)
{
  if( channelId >= 1 && channelId <= 8 )
  {
    byte shieldOutput = channelId;
    byte channelMask = 1 << (shieldOutput - 1);
    shield1BankA = shield1BankA | channelMask;
    sendRawValueToLatch1(shield1BankA);
  }
}
//...->
void setLatchChannelOff (byte channelId)
{
  if( channelId >= 1 && channelId <= 8 )
  {
    byte shieldOutput = channelId;
    byte channelMask = 255 - ( 1 << (shieldOutput - 1));
    shield1BankA = shield1BankA & channelMask;
    sendRawValueToLatch1(shield1BankA);
  }
}
//...->
void sendRawValueToLatch1(byte rawValue)
{
  Wire.beginTransmission(SHIELD_1_I2C_ADDRESS);
  Wire.write(0x12);        // Select GPIOA
  Wire.write(rawValue);    // Send value to bank A
  shield1BankA = rawValue;
  Wire.endTransmission();
}

The only thing I have left to figure out is how to get the T/H figures to print ABOVE the relay buttons, rather than below, but when I move the lines of code that pertain to the T/H data, it makes my buttons disappear, or the Buttons/Title disappear depending on where I place the code. Which is somewhat confusing.

Maybe someone can help with that part?

Thank you,
Darren

Look at what message consists of. It starts with "" and ends with "". Then, you send a bunch of stuff after that. What do you expect the browser to do with the stuff that follows the /html tag?

PaulS:
Look at what message consists of. It starts with "" and ends with "". Then, you send a bunch of stuff after that. What do you expect the browser to do with the stuff that follows the /html tag?

Paul,

Well, I expect the browser to print it, so I can see it from my phone etc.

Have a look at the pic attached, a few screenprints showing DHT data updates, and light sensor states. I have added a photo sensor, that shows different text below the DHT data, and prints in color according the analog levels of light I have defined for now.

If I move the closing /HTML tag, the form fails. Place the DHT data code anywhere within the P(message) and printP(message) and the page fails to load the buttons; instead showing the title "N.E.M.A.R.C." with DHT data above it but the buttons fail to load. I tried at least 30-40 iterations, but nothing "normal" made sense.

I have built several websites (since before editors), and feel most comfortable with HTML, but this is not behaving at all as expected.

Well, I expect the browser to print it, so I can see it from my phone etc.

The html tag says "here is some data to render".
The /html tags "No more data to render".

So, why would you expect the browser to render anything that comes after the /html tag?

If I move the closing /HTML tag, the form fails.

So, I'm guessing that you moved it to the wrong place. Since you failed to post the code in which you did that, all I can do is guess.

Place the DHT data code anywhere within the P(message) and printP(message) and the page fails to load the buttons;

Again, you failed to post any such code, so I guess you just want to complain. Time for me to change the channel. Later.

PaulS:
The html tag says "here is some data to render".
The /html tags "No more data to render".
So, why would you expect the browser to render anything that comes after the /html tag?

Normally, that may be true, but in this case, the close /html is still allowing the server.print and showing the data as shown by the code in the OP that makes the webpage you see 3 screen prints of in the PNG I attached to post #2.

So, I'm guessing that you moved it to the wrong place. Since you failed to post the code in which you did that, all I can do is guess.

People love to sling that fail slang around. I will PM you all attempts if you want, believe me, it's not too exciting...

Again, you failed to post any such code, so I guess you just want to complain. Time for me to change the channel. Later.

fail fail FAIL!

Paul,

No, the code that is pasted in the 1st post DOES work (so long as you remove the "<---notes" I put in there), just as I have shown in the PNG file that is attached to post. I have since added an additional sensor, with no ill effect to the DHT.

I am not complaining at all, simply asking if anyone knows a bit more about this, and trying to provide as much detail as possible about what has been done, showing what works, and explaining what hasn't.

You implied that the sketch shouldn't work, "What do you expect the browser to do with the stuff that follows the /html tag?" But it does work, exactly as it is, any many edits brought about unexpected results.

I don't think it would be productive to upload 40+ failure iterations, unless you really want to have a look, but I bet I would get more failures for being over 9000 characters in a post... hmm.

So, please stop assuming I am complaining, and asserting that I am failing, as I am clearly not. I am enjoying everything about this challenge, except for these b.s. banters. I have read many threads here where people get great help, for easily searchable terms, free of failure comments or flame. If all you can say is someone if failing, for asking questions and trying to be as diligent as possible, you can stay off my channel all you like. PTFO