So you're a Noob? Post your questions here until you graduate! Don't be shy.

User avatar
By Diablillowilly
#59990 I´ve made this webserver, but when sending it, it doesnt appear from the pressure variable to the end of the webserver, what is wrong?
Sry for my bad english


Code: Select all
void responder_peticion() {





  WiFiClient client = server.available();
  if (client)
  {
    peticion = true;

    //Serial.println("\n[Client connected]");
    while (client.connected())
    {
      if (client.available())
      {
        String line = client.readStringUntil('\r');
        //Serial.print(line);
        if (line.length() == 1 && line[0] == '\n')
        {
          client.println(prepareHtmlPage0());
          cantidad_envios++;
          break;
        }
      }
    }
    client.stop();
    //Serial.printf("[Client disonnected]\n");
  }
}



String prepareHtmlPage0()
{
  String htmlPage =
    String("HTTP/1.1 200 OK\r\n") +
    "Content-Type: text/html\r\n" +
    "Connection: close\r\n" +
    "Refresh: 1\r\n" +
    "\r\n" +
    "<!DOCTYPE html>\r\n" +
    "<meta charset=\"utf-8\">" +

    "<html>" +

    "<head>" +
    "<h1 style = \"text-align: center;\">" +
    "webpage" +
    "</h1>" +
    "<title>" +
    "site" +
    "</title>" +
    "<pre>" +
    "</pre>" +

    "</head>" +

    "<body>" +
    " <div id=\"page\" style=\"width: 980px; text-align: center; margin: auto; \">" +

    "<pre>" +

    "</pre>" +


    "<p style=\"text-align: center;\">temp= " + temp + " ºC</p>" +

    "<p style=\"text-align: center;\">hr= " + hum + " %</p>" +

    "<p style=\"text-align: center;\">Presure= " + pres + /* FROM HERE IT DOESNT APPEAR" mB</p>" +

    "<h5 style=\"text-align: center;\">Numero de envios = " + cantidad_envios + "</h5>" +

    "</div>" +
    "</body>" +

    "</html>" +

    "\r\n";

  return htmlPage;
}



User avatar
By jeffas
#60252 You say "it doesn't appear". Do you mean "I do not see it in the browser"?
The first thing to do is check what is actually being sent. Is it as you expect? If so, then there is something wrong with the HTML.
But there may be something wrong with the sending.
I suggest using something like wireshark (or tcpdump on Linux) to capture the web traffic.
Or you could use a command-line fetcher (e.g. wget) which does not try to make sense of the HTML; it will just show the text that it received.
Or maybe "view source" in the browser.
It could be helpful to remove the "refresh" header while you are investigating.