Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <ESP8266WiFi.h>
- const char* ssid = "iPhone de Ludovic";
- const char* password = "moi12345678";
- WiFiServer server( 80 ); //démarrage du serveur
- const int pinTemp = A0;
- float tempC;
- void setup() {
- pinMode(pinTemp, INPUT);
- Serial.begin(9600); // Ouverture du port serie
- delay(10);
- Serial.print("Connecting to "); //Wifi
- Serial.println(ssid);
- WiFi.begin(ssid, password); // On se connecte au réseau WiFi
- while (WiFi.status() != WL_CONNECTED) {
- delay(500);
- Serial.print(".");
- }
- Serial.println("");
- Serial.println("WiFi OK"); // connexion OK, on demarre le server
- server.begin();
- Serial.println("Server OK");
- Serial.println(WiFi.localIP()); // On indique sur le port serie l'adresse ip
- }
- void loop() {
- int valeur = analogRead(pinTemp);
- float temperature = valeur * (3.3 / 1023.0 * 100.0);
- // Serial.println(temperature);
- WiFiClient client = server.available();// intéroger lsereur s'il est //dispo
- if(!client){
- return;
- }
- //Attente d’un client
- Serial.println( "new client" );
- while( !client.available() ){
- delay( 10 );
- }
- // Récupération de la première ligne de la requête
- String request = client.readStringUntil( '\r' );
- client.flush();
- {
- client.println( "HTTP/1.1 200 OK" );
- client.println( "Content-Type: text/html" );
- client.println(); // Mandatory !
- client.println( "<!DOCTYPE HTML>" );
- client.println("temperature :");
- client.println(temperature);
- client.println( "</html>" );
- client.println("<meta http-equiv=\"refresh\" content=\"3\">"); //refresh every 10 seconds
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement