Home » Display analog inputs from a web page

A small program to display the analog inputs on a web page in real time:


The program

#include <ESP8266WiFi.h>
#include <ESP8266WebServer.h>
#include <esusBoard.h>

const char* ssid = "your_SSID";
const char* pass = "your_PASSWORD";
ESP8266WebServer server(80);

// adresse IP :
IPAddress ip(192, 168, 1, 13); 
IPAddress gateway(192,168,1,1);
IPAddress subnet(255,255,255,0); 

void AnalogInputsRead() 

  char temp[400];
  int ana0 = MCP3008_read(A0);
  int ana1 = MCP3008_read(A1);
  int ana2 = MCP3008_read(A2);
  int ana3 = MCP3008_read(A3);
  int ana4 = MCP3008_read(A4);
  int ana5 = MCP3008_read(A5);

snprintf ( temp, 400,

    <meta http-equiv='refresh' content='0.5'/>\
    <title>Esus board demo</title>\
      body { background-color: #cccccc; font-family: Arial, Helvetica, Sans-Serif; Color: #000088; }\
    <h1>Analog inputs</h1>\
    <p>A0: %04d</p>\
    <p>A1: %04d</p>\
    <p>A2: %04d</p>\
    <p>A3: %04d</p>\
    <p>A4: %04d</p>\
    <p>A5: %04d</p>\

    ana0, ana1, ana2, ana3, ana4, ana5

  server.send ( 200, "text/html", temp );
void setup()

  // init wifi
  WiFi.begin(ssid, pass);
  WiFi.config(ip, gateway, subnet);
  // Wait connexion
  while (WiFi.status() != WL_CONNECTED) 
  server.on("/", AnalogInputsRead);
void loop()