SHARE
TWEET

Untitled

paulolimaum Mar 26th, 2019 (edited) 82 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <DHT.h>
  2. #include <DHT_U.h>
  3.  
  4. #include <ESP8266WebServer.h>
  5. #include <ESP8266WebServerSecure.h>
  6. #define OFF 1
  7. #define ON 0
  8. #define WAIT_STEP 50
  9.  
  10. const int statusLed = LED_BUILTIN;
  11. #include <ESP8266WebServerSecureAxTLS.h>
  12. #include <ESP8266WebServerSecureBearSSL.h>
  13.  
  14. #include <BearSSLHelpers.h>
  15. #include <CertStoreBearSSL.h>
  16. #include <ESP8266WiFi.h>
  17. #include <ESP8266WiFiAP.h>
  18. #include <ESP8266WiFiGeneric.h>
  19. #include <ESP8266WiFiMulti.h>
  20. #include <ESP8266WiFiScan.h>
  21. #include <ESP8266WiFiSTA.h>
  22. #include <ESP8266WiFiType.h>
  23. #include <WiFiClient.h>
  24. #include <WiFiClientSecure.h>
  25. #include <WiFiClientSecureAxTLS.h>
  26. #include <WiFiClientSecureBearSSL.h>
  27. #include <WiFiServer.h>
  28. #include <WiFiServerSecure.h>
  29. #include <WiFiServerSecureAxTLS.h>
  30. #include <WiFiServerSecureBearSSL.h>
  31. #include <WiFiUdp.h>
  32.  
  33. #include <ESP8266WiFi.h>
  34. #include <ESP8266WebServer.h>
  35. #include "DHT.h"
  36.  
  37. // Uncomment one of the lines below for whatever DHT sensor type you're using!
  38. //#define DHTTYPE DHT11   // DHT 11
  39. //#define DHTTYPE DHT21   // DHT 21 (AM2301)
  40. #define DHTTYPE DHT22   // DHT 22  (AM2302), AM2321
  41.  
  42. /*Put your SSID & Password*/
  43. const char* ssid = "MEO-8EA371_EXT";  // Enter SSID here
  44. const char* password = "inesbaba";  //Enter Password here
  45.  
  46. ESP8266WebServer server(100);
  47.  
  48. // DHT Sensor
  49. uint8_t DHTPin = D2;
  50. // DHT Sensor
  51. uint8_t DHTPin = D4;
  52. // DHT Sensor
  53. uint8_t DHTPin = D5;
  54.                
  55. // Initialize DHT sensor.
  56. DHT dht(DHTPin, DHTTYPE);                
  57.  
  58. float Temperature;
  59. float Humidity;
  60.  
  61. void setup() {
  62.   Serial.begin(115200);
  63.   delay(100);
  64.  
  65.   pinMode(DHTPin, INPUT);
  66.  
  67.   dht.begin();              
  68.  
  69.   Serial.println("Connecting to ");
  70.   Serial.println(ssid);
  71.  
  72.   //connect to your local wi-fi network
  73.   WiFi.begin(ssid, password);
  74.  
  75.   //check wi-fi is connected to wi-fi network
  76.   while (WiFi.status() != WL_CONNECTED) {
  77.   delay(1000);
  78.   Serial.print(".");
  79.   }
  80.   Serial.println("");
  81.   Serial.println("WiFi connected..!");
  82.   Serial.print("Got IP: ");  Serial.println(WiFi.localIP());
  83.  
  84.   server.on("/", handle_OnConnect);
  85.   server.onNotFound(handle_NotFound);
  86.  
  87.   server.begin();
  88.   digitalWrite(statusLed, ON);
  89.   Serial.println("HTTP server started");
  90.  
  91. }
  92. void loop() {
  93.  
  94.   server.handleClient();
  95.  
  96. }
  97.  
  98. void handle_OnConnect() {
  99.  
  100.  Temperature = dht.readTemperature(); // Gets the values of the temperature
  101.   Humidity = dht.readHumidity(); // Gets the values of the humidity
  102.   server.send(200, "text/html", SendHTML(Temperature,Humidity));
  103. }
  104.  
  105. void handle_NotFound(){
  106.   server.send(404, "text/plain", "Not found");
  107. }
  108.  
  109. String SendHTML(float Temperaturestat,float Humiditystat){
  110.   String ptr = "<!DOCTYPE html> <html>\n";
  111.   ptr +="<head><meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0, user-scalable=no\">\n";
  112.   ptr +="<link href=\"https://fonts.googleapis.com/css?family=Open+Sans:300,400,600\" rel=\"stylesheet\">\n";
  113.   ptr +="<title>ESP8266 Weather Report</title>\n";
  114.   ptr +="<style>html { font-family: 'Open Sans', sans-serif; display: block; margin: 0px auto; text-align: center;color: #333333;}\n";
  115.   ptr +="body{margin-top: 50px;}\n";
  116.   ptr +="h1 {margin: 50px auto 30px;}\n";
  117.   ptr +=".side-by-side{display: inline-block;vertical-align: middle;position: relative;}\n";
  118.   ptr +=".humidity-icon{background-color: #3498db;width: 30px;height: 30px;border-radius: 50%;line-height: 36px;}\n";
  119.   ptr +=".humidity-text{font-weight: 600;padding-left: 15px;font-size: 19px;width: 160px;text-align: left;}\n";
  120.   ptr +=".humidity{font-weight: 300;font-size: 60px;color: #3498db;}\n";
  121.   ptr +=".temperature-icon{background-color: #f39c12;width: 30px;height: 30px;border-radius: 50%;line-height: 40px;}\n";
  122.   ptr +=".temperature-text{font-weight: 600;padding-left: 15px;font-size: 19px;width: 160px;text-align: left;}\n";
  123.   ptr +=".temperature{font-weight: 300;font-size: 60px;color: #f39c12;}\n";
  124.   ptr +=".superscript{font-size: 17px;font-weight: 600;position: absolute;right: -20px;top: 15px;}\n";
  125.   ptr +=".data{padding: 10px;}\n";
  126.   ptr +="</style>\n";
  127.   ptr +="</head>\n";
  128.   ptr +="<body>\n";
  129.  
  130.    ptr +="<div id=\"webpage\">\n";
  131.    
  132.    ptr +="<h1>Paulo Lima Weather Report</h1>\n";
  133.    ptr +="<div class=\"data\">\n";
  134.    ptr +="<div class=\"side-by-side temperature-icon\">\n";
  135.    ptr +="<svg version=\"1.1\" id=\"Layer_1\" xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\" x=\"0px\" y=\"0px\"\n";
  136.    ptr +="width=\"9.915px\" height=\"22px\" viewBox=\"0 0 9.915 22\" enable-background=\"new 0 0 9.915 22\" xml:space=\"preserve\">\n";
  137.    ptr +="<path fill=\"#FFFFFF\" d=\"M3.498,0.53c0.377-0.331,0.877-0.501,1.374-0.527C5.697-0.04,6.522,0.421,6.924,1.142\n";
  138.    ptr +="c0.237,0.399,0.315,0.871,0.311,1.33C7.229,5.856,7.245,9.24,7.227,12.625c1.019,0.539,1.855,1.424,2.301,2.491\n";
  139.    ptr +="c0.491,1.163,0.518,2.514,0.062,3.693c-0.414,1.102-1.24,2.038-2.276,2.594c-1.056,0.583-2.331,0.743-3.501,0.463\n";
  140.    ptr +="c-1.417-0.323-2.659-1.314-3.3-2.617C0.014,18.26-0.115,17.104,0.1,16.022c0.296-1.443,1.274-2.717,2.58-3.394\n";
  141.    ptr +="c0.013-3.44,0-6.881,0.007-10.322C2.674,1.634,2.974,0.955,3.498,0.53z\"/>\n";
  142.    ptr +="</svg>\n";
  143.    ptr +="</div>\n";
  144.    ptr +="<div class=\"side-by-side temperature-text\">Temperature</div>\n";
  145.    ptr +="<div class=\"side-by-side temperature\">";
  146.    ptr +=(int)Temperaturestat;
  147.    ptr +="<span class=\"superscript\">C</span></div>\n";
  148.    ptr +="</div>\n";
  149.    ptr +="<div class=\"data\">\n";
  150.    ptr +="<div class=\"side-by-side humidity-icon\">\n";
  151.    ptr +="<svg version=\"1.1\" id=\"Layer_2\" xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\" x=\"0px\" y=\"0px\"\n\"; width=\"12px\" height=\"17.955px\" viewBox=\"0 0 13 17.955\" enable-background=\"new 0 0 13 17.955\" xml:space=\"preserve\">\n";
  152.    ptr +="<path fill=\"#FFFFFF\" d=\"M1.819,6.217C3.139,4.064,6.5,0,6.5,0s3.363,4.064,4.681,6.217c1.793,2.926,2.133,5.05,1.571,7.057\n";
  153.    ptr +="c-0.438,1.574-2.264,4.681-6.252,4.681c-3.988,0-5.813-3.107-6.252-4.681C-0.313,11.267,0.026,9.143,1.819,6.217\"></path>\n";
  154.    ptr +="</svg>\n";
  155.    ptr +="</div>\n";
  156.    ptr +="<div class=\"side-by-side humidity-text\">Humidity</div>\n";
  157.    ptr +="<div class=\"side-by-side humidity\">";
  158.    ptr +=(int)Humiditystat;
  159.    ptr +="<span class=\"superscript\">%</span></div>\n";
  160.    ptr +="</div>\n";
  161.  
  162.   ptr +="</div>\n";
  163.   ptr +="</body>\n";
  164.   ptr +="</html>\n";
  165.   return ptr;
  166. }
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