I'm able to show and input date via input boxes etc from examples but really don't know enough about html or how it meshes with displaying variables on a webpage, specifically a number.
#include <ESP8266WiFi.h>
const char ssid[] = "mckinley_guest";
const char password[] = "redwoodcreek";
// Create an instance of the server
// specify the port to listen on as an argument
WiFiServer server(80);
void setup() {
Serial.begin(115200);
// Connect to WiFi network
Serial.println();
Serial.println();
Serial.print(F("Connecting to "));
Serial.println(ssid);
WiFi.mode(WIFI_STA);
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(F("."));
}
Serial.println();
Serial.println(F("WiFi connected"));
// Start the server
server.begin();
Serial.println(F("Server started"));
// Print the IP address
Serial.println(WiFi.localIP());
}
void loop() {
// Check if a client has connected
if (WiFiClient client = server.available()) {
Serial.println(F("new client"));
// Send the response to the client
// it is OK for multiple small client.print/write,
// because nagle algorithm will group them into one single packet
client.print(F("HTTP/1.1 200 OK\r\nContent-Type: text/html\r\n\r\n<!DOCTYPE HTML>\r\n<html>\r\n"));
unsigned int theAnswer = 42;
client.print(theAnswer);
Serial.println(F("Disconnecting from client"));
}
}
You can add a dynamic number like below, with the appropriate parts in initial conditions and the read and print in the body.
const int analogInPin = A0;
int sensorValue = 0;
client.println("Analog pin A0 value is ");
sensorValue = analogRead(analogInPin);
client.println(sensorValue);