Bonjour
j'ai un Arduino Uno et un esp8266-01
Avec plusieurs morceau de code j'ai réussi a crée un serveur web avec mon esp8266.
je désire envoyer la valeur d'un capteur analogique 0-5v branché sur ma borne A0 vers un esp8266 par la liaison série.
Le soucis que je rencontre c'est que je n'arrive pas à faire afficher sur ma page web la valeur qui correspond ,à mon capteur analogique .
je vous rajoute l'image que me renvoie l'esp sur ma page web.
#include <SoftwareSerial.h>
#define DEBUG true
#define rxPin 10
#define txPin 11
#include<math.h>
int analogValue;
int pression;
int temerature;
// broche 10 de l'arduino en RX et broche 11 en TX : vous pouvez choisir d'autres broches
// connectez votre ESP8266 en mode croisé RX<=>TX
SoftwareSerial esp8266(10, 11);
void setup()
{
Serial.begin(9600); // com serie de l' ARDUINO a 9600 bauds
esp8266.begin(9600); // ESP8266 a 9600 bauds
sendData("AT+RST\r\n", 2000, DEBUG); // reinitialise le module ESP8266
sendData("AT+CWMODE=2\r\n", 1000, DEBUG); // configure en TCP
sendData("AT+CWSAP?\r\n", 2000, DEBUG); // recupere nom et mot de passe de l' ESP
sendData("AT+CIFSR\r\n", 1000, DEBUG); // recupere l'adresse IP de l' ESP
sendData("AT+CIPMUX=1\r\n", 1000, DEBUG); // configure en connexion multiple
sendData("AT+CIPSERVER=1,80\r\n", 1000, DEBUG); // ouvre le serveur sur le port 80
}
void loop()
{
if (esp8266.available()) // teste si l'ESP envoi un message
{
if (esp8266.find("+IPD,")) // avance jusqu'a trouver +IPD
{
delay(1000);
// read the analog input on pin 0:
int analogValue = analogRead(0);
// print it out in many formats:
esp8266.println(pression); // print as an ASCII-encoded decimal
int connectionId = esp8266.read() - 48;
// soustrait 48 parceque la fonction read() retourne la valeur ASCII decimale , zero (0) par exemple vaut 48 en ASCII decimal
// ci dessous serie de commande qui renvoie du texte sur le port serie (page web)
String webpage = "<h1>HAMET</h1><h2>PRESSION: bars ";
String cipSend = "AT+CIPSEND=";
cipSend += connectionId;
cipSend += ",";
cipSend += webpage.length();
cipSend += "\r\n";
sendData(cipSend, 100, DEBUG);
sendData(webpage, 100, DEBUG);
float analogV = map (analogValue, 0, 1024, 0, 16);
webpage = Serial.print(analogV);
cipSend = "AT+CIPSEND=";
cipSend += connectionId;
cipSend += ",";
cipSend += webpage.length();
cipSend += "\r,\n";
sendData(cipSend, 100, DEBUG);
sendData(webpage, 100, DEBUG);
String closeCommand = "AT+CIPCLOSE=0";
closeCommand += connectionId; // fermer la connexion
closeCommand += "\r,\n";
sendData(closeCommand, 100, DEBUG);
}
}
}
// fonction sendData utilisee pour initialiser l' ESP
String sendData(String command, const int timeout, boolean debug)
{
String response = "";
esp8266.print(command); // envoi le caractere a l' esp8266
long int time = millis();
while ( (time + timeout) > millis())
{
while (esp8266.available())
{
char c = esp8266.read(); // lit le caracter suivant
response += c;
}
}
if (debug)
{
Serial.print(response);
}
return response;
// delay 10 milliseconds before the next reading:
delay(10);
}