zeeph

Untitled

Feb 12th, 2019
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.56 KB | None | 0 0
  1. #include <ESP8266WiFi.h>
  2. const char* ssid = "FEVER";
  3. const char* password = "fever95400@@";
  4. WiFiServer server( 80 ); //démarrage du serveur
  5. const int pinTemp = A0;
  6.  
  7. void setup() {
  8.  
  9. pinMode(pinTemp, INPUT);
  10.  
  11. Serial.begin(9600); // Ouverture du port serie
  12. delay(10);
  13. Serial.print("Connecting to "); //Wifi
  14. Serial.println(ssid);
  15. WiFi.begin(ssid, password); // On se connecte au réseau WiFi
  16. while (WiFi.status() != WL_CONNECTED) {
  17. delay(500);
  18. Serial.print(".");
  19. }
  20. Serial.println("");
  21. Serial.println("WiFi OK"); // connexion OK, on demarre le server
  22. server.begin();
  23. Serial.println("Server OK");
  24.  
  25. Serial.println(WiFi.localIP()); // On indique sur le port serie l'adresse ip
  26. }
  27. void loop() {
  28. int valeur = analogRead(pinTemp);
  29. float temperature = valeur * (3.3 / 1023.0 * 100.0);
  30. delay(2500);
  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("<html>");
  50. client.println("<head>");
  51. client.println("<meta http-equiv=\"refresh\" content=\"6\">");
  52. client.println("<meta charset='utf-8'/>");
  53. client.println("<link rel='stylesheet' href='https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css' integrity='sha384-MCw98/SFnGE8fJT3GXwEOngsV7Zt27NXFoaoApmYm81iuXoPkFOJwJ8ERdknLPMO' crossorigin='anonymous'>");
  54. client.println("<link rel='stylesheet' href='https://use.fontawesome.com/releases/v5.6.3/css/all.css' integrity='sha384-UHRtZLI+pbxtHCWp1t77Bi1L4ZtiqrqD80Kn4Z8NTSRyMA2Fd33n5dQ8lWUE00s/' crossorigin='anonymous'>");
  55. client.println("</head>");
  56. client.println("<body>");
  57. client.println("<title>Temperature sensor!</title>");
  58. client.println("<div class='container'>");
  59. client.println("<h1 style='text-align : center'>Temperature en C° : </h1>");
  60. client.println("<button type='button' class='btn btn-primary btn-lg container-fluid'>Large</button>");
  61. client.println("<br>");
  62. client.println("<div style='font-size : 6em; text-align : center'>");
  63. client.println("<i class='fas fa-temperature-low'></i>");
  64. client.println(temperature);
  65. client.println("</div>");
  66. client.println("</p>");
  67. client.println("</div>");
  68. client.println("</body>");
  69. client.println("</html>");
  70. }
  71. }
Add Comment
Please, Sign In to add comment