SHARE
TWEET

Untitled

zeeph Jan 8th, 2019 72 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <ESP8266WiFi.h>
  2. const char* ssid =  "iPhone de Ludovic";
  3. const char* password = "moi12345678";
  4. WiFiServer server( 80 ); //démarrage du serveur
  5. const int pinTemp = A0;
  6. float tempC;
  7.  
  8. void setup() {
  9.  
  10. pinMode(pinTemp, INPUT);
  11.  
  12. Serial.begin(9600); // Ouverture du port serie
  13. delay(10);
  14. Serial.print("Connecting to "); //Wifi
  15. Serial.println(ssid);
  16. WiFi.begin(ssid, password); // On se connecte au réseau WiFi
  17. while (WiFi.status() != WL_CONNECTED) {
  18. delay(500);
  19. Serial.print(".");
  20. }
  21. Serial.println("");
  22. Serial.println("WiFi OK"); // connexion OK, on demarre le server
  23. server.begin();
  24. Serial.println("Server OK");
  25.  
  26. Serial.println(WiFi.localIP()); // On indique sur le port serie l'adresse ip
  27. }
  28. void loop() {
  29. int valeur = analogRead(pinTemp);
  30. float temperature = valeur * (3.3 / 1023.0 * 100.0);
  31. // Serial.println(temperature);
  32. WiFiClient client = server.available();// intéroger lsereur s'il est //dispo
  33. if(!client){
  34. return;
  35. }
  36. //Attente d’un client
  37. Serial.println( "new client" );
  38. while( !client.available() ){
  39. delay( 10 );
  40. }
  41. // Récupération de la première ligne de la requête
  42. String request = client.readStringUntil( '\r' );
  43. client.flush();
  44. {
  45. client.println( "HTTP/1.1 200 OK" );
  46. client.println( "Content-Type: text/html" );
  47. client.println(); //  Mandatory !
  48. client.println( "<!DOCTYPE HTML>" );
  49. client.println("temperature :");
  50. client.println(temperature);
  51. client.println( "</html>" );
  52. client.println("<meta http-equiv=\"refresh\" content=\"3\">"); //refresh every 10 seconds
  53. }
  54. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top