How can I pass a value from Arduino C To HTML?

Posts: 99
Joined: Mon Mar 05, 2018 12:44 am

Re: How can I pass a value from Arduino C To HTML?

Postby Archibald » Mon Aug 06, 2018 2:23 pm

Hi Herbie,

I am pleased that you are now seeing the temperature displayed on your web page. The function server.send_P is for when you have pointers to 'char' arrays.

I don't have much expertise in this area, but I see the constructor for your server object can also take two parameters: an IP address (as a IPAddress object) and a port (as an 'int' variable).

So try something like this (placing the #include near the top of your code):

Code: Select all

#include <IPAddress.h>

IPAddress a(192,168,1,20);    // create IPAddress object
ESP8266WebServer server(a,80);     // create server object with IP address and port

You will find code of IPAddress.h, IPAddress.cpp, ESP8266WebServer.h and ESP8266WebServer.cpp on GitHub.

If my suggestion does not work and nobody else steps in to help, I suggest you start a new forum thread.

Posts: 15
Joined: Sun Jul 01, 2018 9:54 am

Thanks for the help!!!!

Postby herbie » Tue Aug 07, 2018 9:27 am

Hello Archibald,

sadly your solution didn´t work but I found one elsewhere. I really appreciate your help and of course of the others that tried to help too. I enjoy this forum and it´s friendly users very much!!!!! :D :D :D :D :D
Here´s the final code for all people that may be interested.

Code: Select all

#include <ESP8266WiFi.h>
#include <WiFiClient.h>
#include <ESP8266WebServer.h>
//#include <ESP8266mDNS.h> /for DNS - comment void setup() first block after "sensors.begin
#include <OneWire.h>
#include <DallasTemperature.h>

#define ONE_WIRE_BUS 2 // GPIO of ESP8266 = GPIO2
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensors(&oneWire); // Pass our oneWire reference to Dallas Temperature.

String temperature_string = "";
float temperature;
const char before[] {"<!DOCTYPE html>\n<html>\n<head>\n<meta http-equiv=\"refresh\" content=\"5\"/>\n<style>\nh1 {\n    color: blue;\n    font-family: verdana;\n    font-size: 300%;\n\n}\np  </style>\n</head>\n<body>\n\n<center><h1>"};
const char after[] {"<center></h1>\n\n\n</body>\n</html>\n"};
const char* ssid = "DLINK";
const char* password = "C63SxIpdTT";

EspClass ESPm;

ESP8266WebServer server(80);

void handleRoot() {

  temperature_string = "Temperatur: " + String((float)temperature, 1) + " C";
  server.send(200, "text/html", before + temperature_string + after);


void handleNotFound() {

  String message = "File Not Found\n\n";
  message += "URI: ";
  message += server.uri();
  message += "\nMethod: ";
  message += (server.method() == HTTP_GET) ? "GET" : "POST";
  message += "\nArguments: ";
  message += server.args();
  message += "\n";
  for (uint8_t i = 0; i < server.args(); i++) {
    message += " " + server.argName(i) + ": " + server.arg(i) + "\n";
  server.send(404, "text/plain", message);


void setup() {

  sensors.begin(); /* Initialize Dallas temperature library */
  // config static IP
  IPAddress ip(192, 168, 1, 20);
  IPAddress gateway(192, 168, 1, 1);
  IPAddress subnet(255, 255, 255, 0);
  WiFi.config(ip, gateway, subnet);

  WiFi.begin(ssid, password);

  // Wait for connection
  while (WiFi.status() != WL_CONNECTED) {
  Serial.print("Connected to ");
  Serial.print("IP address: ");

  //if (MDNS.begin("esp8266")) {
  //Serial.println("MDNS responder started");
  // }

  server.on("/", handleRoot);

  server.on("/inline", []() {
    server.send(200, "text/plain", "this works as well");


  Serial.println("HTTP server started");

void get_temperature() {

  // Get temperature

  temperature = sensors.getTempCByIndex(0);

  Serial.print(temperature, 1);
  Serial.print(" Grad Celsius");
  Serial.print("IP address: ");

void loop() {

Who is online

Users browsing this forum: No registered users and 3 guests