Advertisement
Guest User

Untitled

a guest
Dec 27th, 2019
718
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 21.24 KB | None | 0 0
  1. /* ESP8266 Programmable Thermostat IoT
  2.    Version 1.0  1/7/2017  Version 1.0   Damon Borgnino
  3.    Revision by: Martin Chlebovec (martinius96)
  4.    Web: https://arduino.php5.sk?lang=en
  5. */
  6. #include <ESP8266WiFi.h>
  7. #include <WiFiClient.h>
  8. #include <ESP8266WebServer.h>
  9. #include <FS.h> // FOR SPIFFS
  10. #include <ctype.h> // for isNumber check
  11. #include <OneWire.h>
  12. #include <DallasTemperature.h>
  13. #define ONE_WIRE_BUS 2  //D4
  14. OneWire oneWire(ONE_WIRE_BUS);
  15. DallasTemperature sensors(&oneWire);
  16. #define RELAYPIN 4 // D2
  17. const char* ssid     = "huawei-2929";
  18. const char* password = "chefrolet";
  19.  
  20. int CoolingOn = 73;
  21. int CoolingOff = 69;
  22. String relayState = "OFF";
  23. const static String fName = "prop.txt";
  24. const static String dfName = "data.txt";
  25. int dataLines = 0;
  26. int maxFileData = 20;
  27.  
  28.  
  29. ESP8266WebServer server(80);
  30.  
  31. // Initialize DHT sensor
  32.  
  33. // This is for the ESP8266 processor on ESP-01
  34. //DHT dht(DHTPIN, DHTTYPE, 11); // 11 works fine for ESP8266
  35.  
  36. float temp_f, temp_f2;  // Values read from sensor
  37. String webString = "";   // String to display
  38. String webMessage = "";
  39. // Generally, you should use "unsigned long" for variables that hold time to handle rollover
  40. unsigned long previousMillis = 0;        // will store last temp was read
  41. unsigned long interval = 20000;              // interval at which to read sensor
  42.  
  43.  
  44. // reads the temp and Temperature 2 from the DHT sensor and sets the global variables for both
  45. void gettemperature() {
  46.   sensors.requestTemperatures();
  47.   delay(1000);
  48.   temp_f = sensors.getTempCByIndex(0);
  49.   temp_f2 = sensors.getTempCByIndex(1);
  50.   if (temp_f >= CoolingOn)
  51.   {
  52.     digitalWrite(RELAYPIN, HIGH);
  53.     relayState = "ON";
  54.   }
  55.   else if (temp_f <= CoolingOff)
  56.   {
  57.     digitalWrite(RELAYPIN, LOW);
  58.     relayState = "OFF";
  59.   }
  60. }
  61.  
  62. /////////////////////////////////////////////////
  63.  
  64. void clearDataFile() // deletes all the stored data
  65. {
  66.   File f = SPIFFS.open(dfName, "w");
  67.   if (!f) {
  68.     Serial.println("data file open to clear failed");
  69.   }
  70.   else
  71.   {
  72.     Serial.println("-- Data file cleared =========");
  73.     f.close();
  74.   }
  75. }
  76.  
  77. ///////////////////////////////////////////////////////////////////////////////////
  78. // removes the first line of a file by writing all data except the first line
  79. // to a new file. The old file is deleted and new file is renamed.
  80. ///////////////////////////////////////////////////////////////////////////////////
  81.  
  82. void removeFileLine(String fi)
  83. {
  84.   File original = SPIFFS.open(fi, "r");
  85.   if (!original) {
  86.  
  87.     Serial.println("original data file open failed");
  88.   }
  89.  
  90.   File temp = SPIFFS.open("tempfile.txt", "w");
  91.   if (!temp) {
  92.  
  93.     Serial.println("temp data file open failed");
  94.   }
  95.   Serial.println("------ Removing Data Lines ------");
  96.   //Lets read line by line from the file
  97.   for (int i = 0; i < maxFileData; i++) {
  98.     String str = original.readStringUntil('\n'); // read a line
  99.     if (i > 0) { // skip writing first line to the temp file
  100.       temp.println(str);
  101.     }
  102.   }
  103.  
  104.   int origSize = original.size();
  105.   int tempSize = temp.size();
  106.   temp.close();
  107.   original.close();
  108.  
  109.   Serial.print("size orig: "); Serial.print(origSize); Serial.println(" bytes");
  110.   Serial.print("size temp: "); Serial.print(tempSize); Serial.println(" bytes");
  111.  
  112.   if (! SPIFFS.remove(dfName))
  113.     Serial.println("Remove file failed");
  114.  
  115.  
  116.   if (! SPIFFS.rename("tempfile.txt", dfName))
  117.     Serial.println("Rename file failed");
  118.   // dataLines--;
  119. }
  120.  
  121. //////////////////////////////////////////////////////////////////////
  122. // writes the most recent variable values to the data file          //
  123. //////////////////////////////////////////////////////////////////////
  124.  
  125. void updateDataFile()
  126. {
  127.   Serial.println("dataLines: ");
  128.   Serial.println(dataLines);
  129.   if (dataLines >= maxFileData)
  130.   {
  131.     removeFileLine(dfName);
  132.   }
  133.   ///////
  134.   File f = SPIFFS.open(dfName, "a");
  135.   if (!f) {
  136.  
  137.     Serial.println("data file open failed");
  138.   }
  139.   else
  140.   {
  141.     Serial.println("====== Writing to data file =========");
  142.  
  143.     f.print(relayState); f.print(":");
  144.     f.print(temp_f); f.print( ","); f.println(temp_f2);
  145.  
  146.     Serial.println("Data file updated");
  147.     f.close();
  148.   }
  149.  
  150.   Serial.print("millis: ");
  151.   Serial.println(millis());
  152.  
  153. }
  154.  
  155. //////////////////////////////////////////////////////////////////////////////
  156. // reads the data and formats it so that it can be used by google charts    //
  157. //////////////////////////////////////////////////////////////////////////////
  158.  
  159. String readDataFile()
  160. {
  161.   String returnStr = "";
  162.   File f = SPIFFS.open(dfName, "r");
  163.  
  164.   if (!f)
  165.   {
  166.     Serial.println("Data File Open for read failed.");
  167.  
  168.   }
  169.   else
  170.   {
  171.     Serial.println("----Reading Data File-----");
  172.     dataLines = 0;
  173.  
  174.     while (f.available()) {
  175.  
  176.       //Lets read line by line from the file
  177.       dataLines++;
  178.       String str = f.readStringUntil('\n');
  179.       String switchState =  str.substring(0, str.indexOf(":")  );
  180.       /*
  181.           String tempF = str.substring(str.indexOf(":") + 1, str.indexOf(",")  );
  182.         //  String humid = str.substring(str.indexOf(",") + 1 );
  183.         //    String milliSecs = str.substring(str.indexOf("~") + 1 , str.indexOf("~"));
  184.         //   Serial.println(tempF);
  185.         //   Serial.println(humid);
  186.         //  Serial.println(str);
  187.       */
  188.  
  189.       returnStr += ",['" + switchState + "'," + str.substring(str.indexOf(":") + 1) + "]";
  190.     }
  191.     f.close();
  192.   }
  193.  
  194.   return returnStr;
  195.  
  196. }
  197.  
  198. ////////////////////////////////////////////////////////////////////////////////////
  199. //      creates the HTML string to be sent to the client                          //
  200. ////////////////////////////////////////////////////////////////////////////////////
  201.  
  202. void setHTML()
  203. {
  204.   webString = "<html><head>\n";
  205.   webString += "<meta http-equiv=\"refresh\" content=\"60;url=http://" + WiFi.localIP().toString() + "\"> \n";
  206.  
  207.   ///////////// google charts script
  208.   webString += "<script type=\"text/javascript\" src=\"https://www.gstatic.com/charts/loader.js\"></script> \n";
  209.   webString += "   <script type=\"text/javascript\"> \n";
  210.   webString += "    google.charts.load('current', {'packages':['corechart','gauge']}); \n";
  211.   webString += "    google.charts.setOnLoadCallback(drawTempChart); \n";
  212.   webString += "    google.charts.setOnLoadCallback(drawHumidChart); \n";
  213.   webString += "    google.charts.setOnLoadCallback(drawChart); \n ";
  214.  
  215.   // draw temp guage
  216.   webString += "   function drawTempChart() { \n";
  217.   webString += "      var data = google.visualization.arrayToDataTable([ \n";
  218.   webString += "        ['Label', 'Value'], ";
  219.   webString += "        ['Temp\xB0',  ";
  220.   webString += temp_f;
  221.   webString += " ], ";
  222.   webString += "       ]); \n";
  223.   // setup the google chart options here
  224.   webString += "    var options = {";
  225.   webString += "      width: 250, height: 150,";
  226.   webString += "      min: -10, max: 120,";
  227.   webString += "      greenFrom: -10, greenTo: " + String(CoolingOff) + ",";
  228.   webString += "      yellowFrom: " + String(CoolingOff) + ", yellowTo: " + String(CoolingOn) + ",";
  229.   webString += "      redFrom: " + String(CoolingOn) + ", redTo: 120,";
  230.   webString += "       minorTicks: 5";
  231.   webString += "    }; \n";
  232.   webString += "   var chart = new google.visualization.Gauge(document.getElementById('chart_divTemp')); \n";
  233.   webString += "  chart.draw(data, options); \n";
  234.   webString += "  } \n";
  235.  
  236.   // draw Temperature 2 guage
  237.   webString += "   function drawHumidChart() { \n";
  238.   webString += "      var data = google.visualization.arrayToDataTable([ \n";
  239.   webString += "        ['Label', 'Value'], ";
  240.   webString += "        ['Temprature 2',  ";
  241.   webString += temp_f2;
  242.   webString += " ], ";
  243.   webString += "       ]); \n";
  244.   // setup the google chart options here
  245.   webString += "    var options = {";
  246.   webString += "      width: 250, height: 150,";
  247.   webString += "      min: -10, max: 120,";
  248.   webString += "      greenFrom: -10, greenTo: " + String(CoolingOff) + ",";
  249.   webString += "      yellowFrom: " + String(CoolingOff) + ", yellowTo: " + String(CoolingOn) + ",";
  250.   webString += "      redFrom: " + String(CoolingOn) + ", redTo: 120,";
  251.   webString += "       minorTicks: 5";
  252.   webString += "    }; \n";
  253.   webString += "   var chart = new google.visualization.Gauge(document.getElementById('chart_divHumid')); \n";
  254.   webString += "  chart.draw(data, options); \n";
  255.   webString += "  } \n";
  256.  
  257.  
  258.   // draw main graph
  259.   webString += "    function drawChart() { \n";
  260.  
  261.   webString += "     var data = google.visualization.arrayToDataTable([ \n";
  262.   webString += "       ['Hit', 'Temp F', 'Temperature 2'] ";
  263.  
  264.  
  265.   webString += readDataFile();
  266.   // open file for reading
  267.  
  268.   webString += "     ]); \n";
  269.   webString += "     var options = { \n";
  270.   webString += "        title: 'Temp/Temperature 2 Activity', ";
  271.   webString += "        curveType: 'function', \n";
  272.  
  273.   webString += "  series: { \n";
  274.   webString += "         0: {targetAxisIndex: 0}, \n";
  275.   webString += "         1: {targetAxisIndex: 1} \n";
  276.   webString += "       }, \n";
  277.  
  278.   webString += "  vAxes: { \n";
  279.   webString += "         // Adds titles to each axis. \n";
  280.   webString += "         0: {title: 'Temp Fahrenheit'}, \n";
  281.   webString += "         1: {title: 'Temperature 2 %'} \n";
  282.   webString += "       }, \n";
  283.  
  284.   webString += "  hAxes: { \n";
  285.   webString += "         // Adds titles to each axis. \n";
  286.   webString += "         0: {title: 'Cooling On/Off'}, \n";
  287.   webString += "         1: {title: ''} \n";
  288.   webString += "       }, \n";
  289.  
  290.   webString += "         legend: { position: 'bottom' } \n";
  291.   webString += "       }; \n";
  292.  
  293.   webString += "       var chart = new google.visualization.LineChart(document.getElementById('curve_chart')); \n";
  294.  
  295.   webString += "       chart.draw(data, options); \n";
  296.   webString += "      } \n";
  297.  
  298.   ////////////
  299.   webString += "    </script> \n";
  300.   webString += "</head><body>\n";
  301.   webString += "<form action=\"http://" + WiFi.localIP().toString() + "/submit\" method=\"POST\">";
  302.   webString += "<h1>ESP8266-12E DS18B20 Thermostat IoT</h1>\n";
  303.   webString += "<div style=\"color:red\">" + webMessage + "</div>\n";
  304.  
  305.   webString += "<table style=\"width:800px;\"><tr><td>";
  306.   webString += "<div>Cooling On Setting: &ge; " + String((int)CoolingOn) + "&deg; C</div>\n";
  307.   webString += "<div>Cooling Off Setting: &le; " + String((int)CoolingOff) + "&deg; C</div>\n";
  308.   webString += "</td><td style=\"text-align:right\">";
  309.   webString += "Cooling On: &ge; <input type='text' value='" + String((int)CoolingOn) + "' name='CoolingOff' maxlength='3' size='2'><br>\n";
  310.   webString += "Cooling Off: &le; <input type='text' value='" + String((int)CoolingOff) + "' name='CoolingOn' maxlength='3' size='2'><br>\n";
  311.   webString += "</td><td style=\"text-align:right\">";
  312.   webString += "Sample Rate (seconds): <input type='text' value='" + String((long)interval / 1000) + "' name='sRate' maxlength='3' size='2'><br>\n";
  313.   webString += "Maximum Chart Data: <input type='text' value='" + String((long)maxFileData) + "' name='maxData' maxlength='3' size='2'><br>\n";
  314.  
  315.   webString += "</td><td>";
  316.   webString += "<input type='submit' value='Submit' >";
  317.   webString += "</td></tr></table>\n";
  318.  
  319.   webString += "<table style=\"width:800px;\"><tr><td>";
  320.   webString += "<div style=\"width:300px\"><b>Last Readings</b></div>\n";
  321.   webString += "<div>Temperature: " + String(temp_f, 2) + "&deg; C</div>\n";
  322.   webString += "<div>Tempreature2: " + String(temp_f2, 2) + "&deg; C</div>\n";
  323.  
  324.   if (digitalRead(RELAYPIN) == LOW)
  325.     webString += "<div>Cooling is OFF</div>";
  326.   else
  327.     webString += "<div>Cooling is ON</div>";
  328.  
  329.   webString += "<div>Data Lines: " + String((int)dataLines) + "</div> \n";
  330.   //  webString += "<div>Total On Time: " + String( ((onCount * interval) / 1000) / 60 ) + " minutes</div> \n";
  331.   webString += "<div>Sample Rate: " + String(interval / 1000) + " seconds</div> \n";
  332.  
  333.   webString += "<div><a href=\"http://" + WiFi.localIP().toString() + "\">Refresh</a></div>\n";
  334.   webString += "</td><td>";
  335.   webString += "<div id=\"chart_divTemp\" style=\"width: 250px;\"></div>\n";
  336.   webString += "</td><td>";
  337.   webString += "<div id=\"chart_divHumid\" style=\"width: 250px;\"></div>\n";
  338.   webString += "</td></tr></table>\n";
  339.   webString += "<div id=\"curve_chart\" style=\"width: 1000px; height: 500px\"></div> \n";
  340.   webString += "<div><a href=\"/clear\">Clear Data</a></div> \n";
  341.  
  342.   webString += "</body></html>\n";
  343. }
  344.  
  345. //////////////////////////////////
  346. ///  used for error checking   ///
  347. //////////////////////////////////
  348.  
  349. boolean isValidNumber(String str) {
  350.   for (byte i = 0; i < str.length(); i++)
  351.   {
  352.     if (isDigit(str.charAt(i))) return true;
  353.   }
  354.   return false;
  355. }
  356.  
  357. ////////////////////////////////////////////////////////////////////
  358. // handler for web server request: http://IpAddress/submit        //
  359. ////////////////////////////////////////////////////////////////////
  360.  
  361. void handle_submit() {
  362.  
  363.   webMessage = "";
  364.   int tempON = 0;
  365.   int tempOFF = 0;
  366.   long sRate = 0;
  367.   int maxData = 0;
  368.  
  369.   if (server.args() > 0 ) {
  370.     for ( uint8_t i = 0; i < server.args(); i++ ) {
  371.  
  372.       if (server.argName(i) == "CoolingOff") {
  373.  
  374.         if (server.arg(i) != "")
  375.         {
  376.           if (isValidNumber(server.arg(i)) )
  377.             tempON = server.arg(i).toInt();
  378.           else
  379.             webMessage += "Cooling Off must be a number<br>";
  380.         }
  381.         else
  382.           webMessage += "Cooling Off is required<br>";
  383.       }
  384.  
  385.       if (server.argName(i) == "CoolingOn") {
  386.  
  387.         if (server.arg(i) != "")
  388.         {
  389.           if (isValidNumber(server.arg(i)) )
  390.             tempOFF = server.arg(i).toInt();
  391.           else
  392.             webMessage += "Cooling On must be a number<br>";
  393.  
  394.         }
  395.         else
  396.           webMessage += "Cooling On is required<br>";
  397.       }
  398.  
  399.  
  400.       if (server.argName(i) == "sRate") {
  401.  
  402.         if (server.arg(i) != "")
  403.         {
  404.           if (isValidNumber(server.arg(i)) )
  405.             sRate = server.arg(i).toInt();
  406.           else
  407.             webMessage += "Sample Rate must be a number<br>";
  408.         }
  409.         else
  410.           webMessage += "Sample Rate is required<br>";
  411.       }
  412.  
  413.       if (server.argName(i) == "maxData") {
  414.  
  415.         if (server.arg(i) != "")
  416.         {
  417.           if (isValidNumber(server.arg(i)) )
  418.             maxData = server.arg(i).toInt();
  419.           else
  420.             webMessage += "Max Chart Data must be a number<br>";
  421.         }
  422.         else
  423.           webMessage += "Max Chart Data is required<br>";
  424.       }
  425.  
  426.     }
  427.  
  428.     if (tempON <= tempOFF)
  429.       webMessage += "Cooling On must be lower than Cooling Off<br>";
  430.  
  431.     if (sRate < 10)
  432.       webMessage += "Sample Rate must be greater than or equal to 10<br>";
  433.  
  434.     if (maxData < 10 || maxData > 300)
  435.       webMessage += "Max Chart Data must be between 10 and 300<br>";
  436.  
  437.     if (webMessage == "")
  438.     {
  439.       CoolingOn = tempON;
  440.       CoolingOff = tempOFF;
  441.       interval = sRate * 1000;
  442.       maxFileData = maxData;
  443.       ///////
  444.       File f = SPIFFS.open(fName, "w");
  445.       if (!f) {
  446.  
  447.         Serial.println("file open for properties failed");
  448.       }
  449.       else
  450.       {
  451.         Serial.println("====== Writing to config file =========");
  452.  
  453.         f.print(CoolingOn); f.print( ","); f.print(CoolingOff);
  454.         f.print("~"); f.print(sRate);
  455.         f.print(":"); f.println(maxData);
  456.         Serial.println("Properties file updated");
  457.         f.close();
  458.       }
  459.  
  460.     }
  461.   }
  462.  
  463.  
  464.   if (webMessage == "") {
  465.     webMessage = "Settings Updated";
  466.   }
  467.  
  468.  
  469.   gettemperature();
  470.  
  471.   setHTML();
  472.   server.send(200, "text/html", webString);            // send to someones browser when asked
  473.  
  474.   delay(100);
  475. }
  476.  
  477.  
  478. ////////////////////////////////////////////////////////////
  479. // handler for web server request: http://IpAddress/      //
  480. ////////////////////////////////////////////////////////////
  481.  
  482. void handle_root() {
  483.  
  484.   gettemperature();       // read sensor
  485.   webMessage = "";
  486.   setHTML();
  487.   server.send(200, "text/html", webString);            // send to someones browser when asked
  488.  
  489.   delay(100);
  490. }
  491.  
  492. ///////////////////////////////////////
  493. // first funtion to run at power up //
  494. //////////////////////////////////////
  495.  
  496. void setup(void) {
  497.   sensors.begin();
  498.   // You can open the Arduino IDE Serial Monitor window to see what the code is doing
  499.   Serial.begin(115200);  // Serial connection from ESP-01 via 3.3v console cable
  500.  
  501.   pinMode(RELAYPIN, OUTPUT);
  502.   digitalWrite(RELAYPIN, LOW);
  503.   // Connect to WiFi network
  504.   WiFi.begin(ssid, password);
  505.   WiFi.config(IPAddress(192, 168, 1, 201), IPAddress(192, 168, 1, 1), IPAddress(255, 255, 255, 0));
  506.  
  507.   Serial.print("\n\r \n\rWorking to connect");
  508.  
  509.   // Wait for connection
  510.   while (WiFi.status() != WL_CONNECTED) {
  511.     delay(500);
  512.     Serial.print(".");
  513.   }
  514.   Serial.println("");
  515.   Serial.println("DS18B20 server");
  516.   Serial.print("Connected to ");
  517.   Serial.println(ssid);
  518.   Serial.print("IP address: ");
  519.   Serial.println(WiFi.localIP());
  520.  
  521.   //  dht.begin();           // initialize temperature sensor
  522.   delay(10);
  523.  
  524.  
  525.   SPIFFS.begin();
  526.   delay(10);
  527.   ///////////////////
  528.   // SPIFFS.format(); // uncomment to completely clear data
  529.  
  530.  
  531.   File f = SPIFFS.open(fName, "r");
  532.  
  533.   if (!f) {
  534.     // no file exists so lets format and create a properties file
  535.     Serial.println("Please wait 30 secs for SPIFFS to be formatted");
  536.  
  537.     SPIFFS.format();
  538.  
  539.     Serial.println("Spiffs formatted");
  540.  
  541.     f = SPIFFS.open(fName, "w");
  542.     if (!f) {
  543.  
  544.       Serial.println("properties file open failed");
  545.     }
  546.     else
  547.     {
  548.       // write the defaults to the properties file
  549.       Serial.println("====== Writing to properties file =========");
  550.  
  551.       f.print(CoolingOn); f.print( ","); f.print(CoolingOff);
  552.       f.print("~"); f.print(interval / 1000);
  553.       f.print(":"); f.println(maxFileData);
  554.       Serial.println("Properties file created");
  555.       dataLines = 1;
  556.       f.close();
  557.     }
  558.  
  559.   }
  560.   else
  561.   {
  562.     // if the properties file exists on startup,  read it and set the defaults
  563.     Serial.println("Properties file exists. Reading.");
  564.  
  565.     while (f.available()) {
  566.  
  567.       //Lets read line by line from the file
  568.       String str = f.readStringUntil('\n');
  569.  
  570.       String loSet = str.substring(0, str.indexOf(",")  );
  571.       String hiSet = str.substring(str.indexOf(",") + 1, str.indexOf("~") );
  572.       String sampleRate = str.substring(str.indexOf("~") + 1, str.indexOf(":") );
  573.       String maxData = str.substring(str.indexOf(":") + 1 );
  574.  
  575.       Serial.println(loSet);
  576.       Serial.println(hiSet);
  577.       Serial.println(sampleRate);
  578.       Serial.println(maxData);
  579.  
  580.       CoolingOn = loSet.toInt();
  581.       CoolingOff = hiSet.toInt();
  582.       interval = sampleRate.toInt() * 1000;
  583.       maxFileData = maxData.toInt();
  584.     }
  585.  
  586.     f.close();
  587.   }
  588.  
  589.   // now lets read the data file mainly to set the number of lines
  590.   readDataFile();
  591.   // now read the DHT and set the temp and Temperature 2 variables
  592.   gettemperature();
  593.   // update the datafile to start a new session
  594.   updateDataFile();
  595.  
  596.   // web client handlers
  597.   server.on("/", handle_root);
  598.  
  599.   server.on("/submit", handle_submit);
  600.  
  601.   server.on("/clear", []() {
  602.     // handler for http://iPaddress/clear
  603.  
  604.     // deletes all the stored data for temp and Temperature 2
  605.     clearDataFile();
  606.  
  607.     webMessage = "Data Cleared";
  608.  
  609.     // read the DHT and use new values to start new file data
  610.     gettemperature();
  611.     updateDataFile();
  612.     setHTML(); // this will set the webString varialbe with HTML
  613.     server.send(200, "text/html", webString);            // send to someones browser when asked
  614.     delay(100);
  615.  
  616.   });
  617.  
  618.   // start the web server
  619.   server.begin();
  620.   Serial.println("HTTP server started");
  621.  
  622. }
  623.  
  624. ////////////////////////////////////////////////////////////////////////////////
  625.  
  626. void loop(void)
  627. {
  628.  
  629.   // check timer to see if it's time to update the data file with another DHT reading
  630.   unsigned long currentMillis = millis();
  631.  
  632.   // cast to unsigned long to handle rollover
  633.   if ((unsigned long)(currentMillis - previousMillis) >= interval )
  634.   {
  635.     // save the last time you read the sensor
  636.     previousMillis = currentMillis;
  637.  
  638.     gettemperature();
  639.  
  640.     Serial.print("Temp: ");
  641.     Serial.println(temp_f);
  642.     Serial.print("Temp 2: ");
  643.     Serial.println(temp_f2);
  644.  
  645.     updateDataFile();
  646.     readDataFile();
  647.   }
  648.  
  649.   server.handleClient();
  650.  
  651. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement