Développeur>Tutoriels>Afficher les entrées analogique sur une page web
Un petit programme pour afficher les entrées analogiques sur une page web en temps réel :
Le programme
#include <ESP8266WiFi.h>
#include <ESP8266WebServer.h>
#include <esusBoard.h>
const char* ssid = "your_SSID";
const char* pass = "your_PASSWORD";
ESP8266WebServer server(80);
// configuration de l'adresse IP : 192.168.1.13
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,
"<html>\
<head>\
<meta http-equiv='refresh' content='0.5'/>\
<title>Esus board demo</title>\
<style>\
body { background-color: #cccccc; font-family: Arial, Helvetica, Sans-Serif; Color: #000088; }\
</style>\
</head>\
<body>\
<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>\
</body>\
</html>",
ana0, ana1, ana2, ana3, ana4, ana5
);
server.send ( 200, "text/html", temp );
}
void setup()
{
initEsusBoard();
// initialisation du reseau wifi
WiFi.begin(ssid, pass);
WiFi.config(ip, gateway, subnet);
// Attente de la connexion
while (WiFi.status() != WL_CONNECTED)
{
delay(100);
}
server.on("/", AnalogInputsRead);
server.begin();
}
void loop()
{
server.handleClient();
}

