/*--------------------------------------------------- _____ _-_-_-_ *|* _-_-_-_ -_-_-_-_-\@/-_-_-_-_- HTTP 1.1 Temperature & Humidity Webserver for ESP8266 for ESP8266 adapted in the Arduino IDE Espressif SDK Functionality in the form of a dignostics page Server Layout http://ipaddress/ Web Text to LCD Input /diag SDK Functionality /monitor Google Gauges /graphic Google Line Chart /graphic2 Google Line Chart of BMP180 Pressure /pressure Google Gauge of BMP180 Pressure /table Datalog Table /yfireset Reset the WiFi Connection /srestart Reboot the system(ESP must be cold booted, this will fail directly after uploading a sketch) Credits to Stefan Thesen and The Guy's at .......http://www.ESP8266.com With the use of http://espressif.com/new-sdk-release The ESP8266 Arduino Reference http://arduino.esp8266.com/versions/1.6.5-1160-gef26c5f/doc/reference.html With this release and a 1MByte Flash with 512KB SPIFFS can hold 3328 records of 120 bytes long Approx. 390KB Set up an account at http://smtp2go.com Encrypt your Password & Username using https://www.base64encode.org/ This evolution is the product of the Environment Monitor...... environmental.monitor.log@gmail.com See a feed from 2 DHT11's on twitter at http://twitter.com/DDTMonitor This will read various sensors and send an Email at a time or Sensor Condition With the Data from the Sensors presented via Web Gauges, Graphs & Tables..... Setup = 2 * DHT11 + BMP180 and an ESP8266-07 with 1MB Flash There are various pins used to load boot code so if you change pins and it does not boot this is WHY!! I2C GPios 4 & 5 DHT GPio 14 & 16 To Index to a data point, each record is 64 bytes, there ar place holders to count in the string record to select an individual data point. The SPIFFS Record selction.......to allow reading/modifying a value....... File dataFile1 = SPIFFS.open("/humidlog.CSV", "r"); // a = append/modify, r = read or create w = write if(!dataFile1.seek(0, SeekSet)) // Other Commands are seekCur or seekEnd { Serial.println(F("Rewind fail")); dataFile1.close(); } stringholder = dataFile1.readStringUntil("["); //Start of Record idexed to with file offset currently=0 __________________________________________________________________________________________________ ......Use 5v to 3v Level Shifters as 5V devices like PIR and HC-SR04 can damage your device....... -------------------------------------------------------------------------------------------------- ___/'¬_ /\ {_-_ ^ \_______// / \ \ _ _____ / || || ||| || || ||| ---------------------------------------------------*/ #include #include "FS.h" #include "DHT.h" #include #include #include LiquidCrystal_I2C lcd(0x3F,16,2); // set the LCD address to YOUR LCD ADDRESS !!! SFE_BMP180 pressure; // i2c Address 77h // WiFi connection const char* ssid = "your-SSID"; const char* password = "your-PASSWORD"; //place holders databuckets..... String toaddres = "RCPT To: "; // Where your Last 24Hr Log has to be emailed To.......Time set below.... String frmaddrs = "MAIL From: "; // Where your Log has to be emailed From....... String b64Usernm = "Username"; // B64 Encrypted smtp2go Username String b64Passwd = "Password"; // B64 Encrypted smtp2go Password String emailbutton = "off"; String lastdata; String lastpres; String emailtime; String DsTable; //Discarded parts if the Strings...... String tmtxt1; //Strings from the Web.... String tmtxt2; String stheDate; //System Start Time... String theDate; // The current TimeStamp from Google.... boolean got_text = false; //Print the Text to LCD if true...... boolean barom = false; //Print the Barometric Pressure data to Line Chart..... double baseline; // BMP180 baseline pressure double T,P,p0,a; // BMP180 Data unsigned long ulSecs2000_timer=0; // Timer for loop unsigned long ulMeasCount=0; // values already measured unsigned long ulMeasDelta_ms; // distance to next meas time unsigned long ulNextMeas_ms; // next meas time float pfTemp,pfHum,pfTemp1,pfHum1,pfVcC; // floats for Environment/System measurements stored in SPIFFS unsigned long ulReqcount; // how often has a valid page been requested unsigned long ulReconncount; // how often did we connect to WiFi unsigned long Dfsize; // size of the datalog file // Create an instance of the server on Port 80-89 = Sensor 1 - 10 WiFiServer server(80); WiFiClient client; char popyahoo[] = "smtpcorp.com"; // set email service int port = 2525; //////////////////////////////////// // DHT21 / AMS2301 / DHT11 /DHT22 // //////////////////////////////////// #define DHTPIN 14 #define DHTPIN1 16 ADC_MODE(ADC_VCC); // Uncomment whatever type you're using! #define DHTTYPE DHT11 // DHT 11 //#define DHTTYPE DHT22 // DHT 22 (AM2302) //#define DHTTYPE DHT21 // DHT 21 (AM2301) // Declare each sensor DHT dht(DHTPIN, DHTTYPE,12); DHT dht1(DHTPIN1, DHTTYPE,13); // needed to avoid link error on ram check extern "C" { #include "user_interface.h" } void wsysreset() { //Perform challenge to user before getting here to reboot !!! //Make an attempt to send mail or other backup of log files then reboot ESP.restart(); } ///////////////////// // the setup routine ///////////////////// void setup() { dht.begin(); dht1.begin(); // setup globals ulReqcount=0; ulReconncount=0; pinMode(0, INPUT); //Use the Flash Button......... // initialize the lcd lcd.init(); lcd.backlight(); delay(500); // initialize the SPIFFS if (!SPIFFS.begin()) { lcd.print("SPIFFSinitFailed"); while(1); } // clear any old data.... if (SPIFFS.exists("/humidlog.CSV")){ SPIFFS.remove("/humidlog.CSV");} // if (SPIFFS.exists("/humidlog.CSV")){ SPIFFS.rename("/humidlog.CSV", "/humidlog.old");} if (pressure.begin()) { } else { // Oops, something went wrong, this is usually a connection problem, // see the comments at the top of this sketch for the proper connections. lcd.print("BMP180 init fail"); while(1); // Pause forever. } baseline = getPressure(); delay(500); lcd.print("Sensor Init Done"); // inital connect WiFi.mode(WIFI_STA); delay(1500); WiFiStart(); server.begin(); ulMeasDelta_ms = ( (unsigned long) 60 * 1000); // Sample Interval 60 Seconds, this can be placed above in the declarations.... ulNextMeas_ms = millis()+ulMeasDelta_ms; lcd.clear(); lcd.print("Environmental"); lcd.setCursor(0, 1); lcd.print("Monitor "); emailtime=theDate.substring(11,19); lcd.print(emailtime); delay(2000); pfHum = dht.readHumidity(); pfTemp = dht.readTemperature(); pfHum1 = dht1.readHumidity(); pfTemp1 = dht1.readTemperature(); delay(500); } /////////////////// // (re-)start WiFi /////////////////// void WiFiStart() { ulReconncount++; delay(1000); // Connect to WiFi network lcd.clear(); lcd.print("Connecting to "); lcd.setCursor(0, 1); lcd.print(ssid); WiFi.begin(ssid, password); while (WiFi.status() != WL_CONNECTED) { delay(500); lcd.print("."); } lcd.clear(); lcd.print("WiFi connected"); // Start the server lcd.setCursor(0, 1); server.begin(); lcd.print("Server started"); lcd.clear(); lcd.setCursor(0, 0); lcd.print("Network Started "); // Print the IP address lcd.setCursor(0, 1); lcd.print("IP= "); lcd.print(WiFi.localIP()); /////////////////////////////// // connect to NTP and get time /////////////////////////////// WiFiClient client; while (!!!client.connect("google.com", 80)) { lcd.clear(); lcd.print("connection fail!"); } client.print("HEAD / HTTP/1.1\r\n\r\n"); while(!!!client.available()) { yield(); } while(client.available()){ client.readStringUntil('\n'); String theDate1 = client.readStringUntil('\r'); //Date: Tue, 10 Nov 2015 19:55:38 GMT if (theDate1.startsWith("Date:")) { theDate = theDate1.substring(11,31); stheDate=theDate; client.flush(); client.stop(); } } lcd.clear(); lcd.print("Environment | "); lcd.print(ulReconncount); // lcd.setCursor(0, 1); // lcd.print("Monitor"); lcd.setCursor(0,1); lcd.print(theDate); ulSecs2000_timer -= millis()/1000; // keep distance to millis() counter } double getPressure() { char status; // You must first get a temperature measurement to perform a pressure reading. // Start a temperature measurement: // If request is successful, the number of ms to wait is returned. // If request is unsuccessful, 0 is returned. status = pressure.startTemperature(); if (status != 0) { // Wait for the measurement to complete: delay(status); // Retrieve the completed temperature measurement: // Note that the measurement is stored in the variable T. // Use '&T' to provide the address of T to the function. // Function returns 1 if successful, 0 if failure. status = pressure.getTemperature(T); if (status != 0) { // Start a pressure measurement: // The parameter is the oversampling setting, from 0 to 3 (highest res, longest wait). // If request is successful, the number of ms to wait is returned. // If request is unsuccessful, 0 is returned. status = pressure.startPressure(3); if (status != 0) { // Wait for the measurement to complete: delay(status); // Retrieve the completed pressure measurement: // Note that the measurement is stored in the variable P. // Use '&P' to provide the address of P. // Note also that the function requires the previous temperature measurement (T). // (If temperature is stable, you can do one temperature measurement for a number of pressure measurements.) // Function returns 1 if successful, 0 if failure. status = pressure.getPressure(P,T); if (status != 0) { return(P); } else lcd.print("ror retrieving P"); } else lcd.print("error starting P"); } else lcd.print("ror retrieving T"); } else lcd.print("error starting T"); } ///////////////////////////////////// // make html table for measured data ///////////////////////////////////// unsigned long MakeTable (WiFiClient *pclient, bool bStream) { unsigned long ulLength=0; // here we build a big table. // we cannot store this in a string as this will blow the memory // thus we count first to get the number of bytes and later on // we stream this out if (ulMeasCount==0) { String sTable = "No data available yet.
"; if (bStream) { pclient->print(sTable); } ulLength+=sTable.length(); } else { File logF = SPIFFS.open("/humidlog.CSV", "r"); if (!logF) { lcd.clear(); lcd.print("rOr humidlog.CSV"); while(1); } String sTable; String DsTable=""; sTable = ""; sTable += ""; // for (unsigned long li=0;li1024) { if(bStream) { pclient->print(sTable); //pclient->write(sTable.c_str(),sTable.length()); } ulLength+=sTable.length(); sTable=""; } } // remaining chunk sTable+="
Time / GMTInt Temperature °CInt Humidity %Ext Temperature °CExt Humidity %System VccBMP TempPressure MilliBar
"; ulLength+=sTable.length(); if(bStream) { pclient->print(sTable); //pclient->write(sTable.c_str(),sTable.length()); } } return(ulLength); } //////////////////////////////////////////////////// // make google chart object table for measured data //////////////////////////////////////////////////// unsigned long MakeList (WiFiClient *pclient, bool bStream) { unsigned long ulLength=0; // here we build a big list. // we cannot store this in a string as this will blow the memory // thus we count first to get the number of bytes and later on // we stream this out if (ulMeasCount>0) { File logF = SPIFFS.open("/humidlog.CSV", "r"); if (!logF) { lcd.clear(); lcd.print("rOr humidlog.CSV"); while(1); } String sTable=""; DsTable = logF.readStringUntil('\''); while (logF.available()) { // result shall be ['18:24:08 - 21.5.2015',21.10,49.00], sTable += "['"; sTable += logF.readStringUntil('\''); sTable += "',"; if (barom == true){ DsTable += logF.readStringUntil(']');// Pressure Measurements are a different Scale......hence simple separation.... sTable += logF.readStringUntil(','); } else{ DsTable = logF.readStringUntil(','); sTable += logF.readStringUntil(']');// Pressure Measurements are a different Scale......hence simple separation.... } sTable += "],\n"; DsTable = logF.readStringUntil('\''); // play out in chunks of 1k if(sTable.length()>1024) { if(bStream) { pclient->print(sTable); //pclient->write(sTable.c_str(),sTable.length()); } ulLength+=sTable.length(); sTable=""; } } // remaining chunk if(bStream) { pclient->print(sTable); //pclient->write(sTable.c_str(),sTable.length()); } ulLength+=sTable.length(); } return(ulLength); } ////////////////////////// // create HTTP 1.1 header ////////////////////////// String MakeHTTPHeader(unsigned long ulLength) { String sHeader; sHeader = F("HTTP/1.1 200 OK\r\nContent-Length: "); sHeader += ulLength; sHeader += F("\r\nContent-Type: text/html\r\nConnection: close\r\n\r\n"); return(sHeader); } //////////////////// // make html footer //////////////////// String MakeHTTPFooter() { String sResponse; sResponse = F(" "); sResponse += F("
environmental.monitor.log@gmail.com
ESP8266 With DHT11 & BMP180 Sensors
Compiled Using ver. 1.6.5-1160-gef26c5f, built on Sep 30, 2015"); return(sResponse); } ///////////// // main loop ///////////// void loop() { /////////////////// // do data logging /////////////////// if (millis()>=ulNextMeas_ms) { ulNextMeas_ms = millis()+ulMeasDelta_ms; char status; status = pressure.startTemperature(); if (status != 0) { // Wait for the measurement to complete: delay(status); // Retrieve the completed temperature measurement: // Note that the measurement is stored in the variable T. // Use '&T' to provide the address of T to the function. // Function returns 1 if successful, 0 if failure. } status = pressure.getTemperature(T); status = pressure.startPressure(3); if (status != 0) { // Wait for the measurement to complete: delay(status); // Retrieve the completed pressure measurement: // Note that the measurement is stored in the variable P. http://bbc.in/1HIlwwK // Use '&P' to provide the address of P. // Note also that the function requires the previous temperature measurement (T). // (If temperature is stable, you can do one temperature measurement for a number of pressure measurements.) // Function returns 1 if successful, 0 if failure. } status = pressure.getPressure(P,T); String theDatet = theDate; theDatet.replace("2015 ", "- "); if (theDatet==""){theDatet="Missed NTP";} pfHum1 = dht1.readHumidity(); pfTemp1 = dht1.readTemperature(); pfTemp = dht.readTemperature(); pfHum = dht.readHumidity(); int lc; for (lc=0;lc<6;lc++){ if (pfTemp==11.11){ delay(2000); pfTemp = dht.readTemperature(); pfHum = dht.readHumidity(); } } lastdata=""; lastdata += pfTemp; lastdata += ",hum="; lastdata += pfHum; lastdata += ",temp1="; lastdata += pfTemp1; lastdata += ",hum1="; lastdata += pfHum1; String logdata = "["; logdata += "'"; logdata += theDatet; logdata += "'"; logdata += ","; logdata += pfTemp; logdata += ","; logdata += pfHum; logdata += ","; logdata += pfTemp1; logdata += ","; logdata += pfHum1; logdata += ","; logdata += pfVcC/1000; logdata += ","; logdata += T; logdata += "]"; if(P<1000){logdata += "0";} // Keep 64 Byte Record Size logdata += P; logdata += ","; lastpres = P; File logF = SPIFFS.open("/humidlog.CSV", "a"); if (logF) { logF.print(logdata); logF.close(); ulMeasCount++; } else { lcd.clear(); lcd.print("rOr humidlog.CSV"); while(1); } } if (millis()==(ulNextMeas_ms-(ulMeasDelta_ms/2))){ if (got_text == true){ if (tmtxt1!=""){ lcd.clear(); lcd.setCursor(0, 0); lcd.print(tmtxt1); lcd.setCursor(0, 1); lcd.print(tmtxt2); delay(5000); } else{ // Empty String returned CLEAR SCREEN got_text == false; } } // // Check button for email trigger // int button = 0; // variable for reading the pushbutton status button = digitalRead(0); // read the state of the pushbutton on gpio 0 if (button == LOW) { emailbutton = "Send"; lcd.clear(); lcd.setCursor(0, 0); lcd.print(F("Email Button....")); lcd.setCursor(0, 1); lcd.print(F("......Pressed.!!")); delay(1000); } WiFiClient client; while (!!!client.connect("google.com", 80)) { } client.print("HEAD / HTTP/1.1\r\n\r\n"); while(!!!client.available()) { yield(); } while(client.available()){ client.readStringUntil('\n'); String theDate1 = client.readStringUntil('\r'); // this returns, Date: Tue, 10 Nov 2015 19:55:38 GMT if (theDate1.startsWith("Date:")) { theDate = theDate1.substring(11,31); client.stop(); } } // Use this instead of ESP.getVcc() for modules with LDR Fitted, Alter Display Text from Volts!!! // This is the Start of the LDR Sensor Measurement Percent/10 Saturation of LDR // Keep the Scale relavant for Line Graph or select Different Axis..... /* delay(25); int pfVcC = 10-(constrain(map((analogRead(A0)), 40, 900, 1, 10), 1, 10)) ; delay(25); // // This is the End of the LDR Sensor Measurement // */ emailtime = theDate.substring(12,17); delay(50); pfVcC = ESP.getVcc(); // Only use this if Nothing connected to TOUT / ADC delay(150); lcd.clear(); lcd.setCursor(0, 0); lcd.print(pfTemp); lcd.setCursor(2, 0); lcd.print(F("C ")); lcd.print(pfHum); lcd.setCursor(6, 0); lcd.print(F("% ")); lcd.print(pfTemp1); lcd.setCursor(10, 0); lcd.print(F("C ")); lcd.print(pfHum1); lcd.setCursor(14, 0); lcd.print(F("% ")); lcd.setCursor(0, 1); lcd.print(P); lcd.print(F("mb")); lcd.setCursor(11, 1); lcd.print(emailtime); delay(1000); // Ping or PIR and check email button Halt/Reboot if (emailtime.startsWith("07:51") || emailbutton.startsWith("Sen")) {// Set the time for the Log to be emailed lcd.print(F("Got email - data")); if(sendEmail()) { lcd.clear(); lcd.print(F("mail sent......")); wsysreset(); } else { lcd.clear(); lcd.print(F("Email FAILED..!!!")); while(1); } emailbutton = "off"; } } ////////////////////////////// // check if WLAN is connected ////////////////////////////// if (WiFi.status() != WL_CONNECTED) { WiFiStart(); } /////////////////////////////////// // Check if a client has connected /////////////////////////////////// WiFiClient client = server.available(); if (!client) { return; } // Wait until the client sends some data unsigned long ultimeout = millis()+250; while(!client.available() && (millis()ultimeout) { return; } ///////////////////////////////////// // Read the first line of the request ///////////////////////////////////// String sRequest = client.readStringUntil('\r'); client.flush(); // stop client, if request is empty if(sRequest=="") { client.stop(); return; } // get path; end of path is either space or ? // Syntax is e.g. GET /?show=1234 HTTP/1.1 String sPath="",sParam="", sCmd=""; String sGetstart="GET "; int iStart,iEndSpace,iEndQuest; iStart = sRequest.indexOf(sGetstart); if (iStart>=0) { iStart+=+sGetstart.length(); iEndSpace = sRequest.indexOf(" ",iStart); iEndQuest = sRequest.indexOf("?",iStart); // are there parameters? if(iEndSpace>0) { if(iEndQuest>0) { // there are parameters sPath = sRequest.substring(iStart,iEndQuest); sParam = sRequest.substring(iEndQuest,iEndSpace); } else { // NO parameters sPath = sRequest.substring(iStart,iEndSpace); } } } /////////////////////////// // format the html response /////////////////////////// String sResponse,sResponse2,sHeader; ///////////////////////////////// // Update LCD with text from Web ///////////////////////////////// //_________________________________________________________________ // /ajax_inputs&L1=123456789&L2=abcdefghi&nocache=968337.7823963541 // 1-9 on Line 1 and a - i on line 2 //¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬ if (sPath.startsWith("/ajax_inputs&L1=")) { ulReqcount++; tmtxt1=""; tmtxt2=""; got_text = true; // print the received text to the LCD if found File in = SPIFFS.open("/temp.txt", "w"); if (in) { in.print(sPath); in.close(); } else { lcd.clear(); lcd.print("rOr Temp.TXT"); while(1); } in = SPIFFS.open("/temp.txt", "r"); in.setTimeout(0); String Dtmtxt = in.readStringUntil('='); tmtxt1 += in.readStringUntil('&'); Dtmtxt = in.readStringUntil('='); tmtxt2 += in.readStringUntil('&'); in.close(); tmtxt1.replace("%20", " "); tmtxt2.replace("%20", " "); lcd.clear(); lcd.setCursor(0, 0); lcd.print(tmtxt1); lcd.setCursor(0, 1); lcd.print(tmtxt2); } ////////////////////////////////// // format the html page for gauges ////////////////////////////////// if(sPath=="/monitor") { ulReqcount++; sResponse = F("\n\nEnvironment Monitor\n\n\n\n\n

Environment Monitor



Last Sample Taken "); sResponse += theDate; sResponse2 = F("GMT
\n
\n
\n
\n
\n
"); sResponse2 += F("
\n


Pressure Graph Page
Pressure Gauge Page
Sensor Graph Page
Sensor Datalog Page
Diagnostics Information Page
Monitor LCD Text Input Page

"); sResponse2 += MakeHTTPFooter().c_str(); // Send the response to the client client.print(MakeHTTPHeader(sResponse.length()+sResponse2.length()).c_str()); client.print(sResponse); client.print(sResponse2); } else if(sPath=="/") { ulReqcount++; sResponse = F("\n\nEnvironment Monitor Text to LCD\n\n\n

Environment Monitor
LCD Text Input

\n"); sResponse += F("
Pressure Graph Page
Pressure Gauge Page
Sensor Gauge Page
Sensor Graph Page
Sensor Datalog Page
Diagnostics Information Page
\n"); sResponse += F("\n

Enter text to send to ESP8266 LCD:

\n
\n

\n\n"); sResponse += F("
\n
\n\n\n"); sResponse2 = F("
LCD Text Input
\n"); sResponse2 += F("\n

"); sResponse2 += MakeHTTPFooter().c_str(); // Send the response to the client client.print(MakeHTTPHeader(sResponse.length()+sResponse2.length()).c_str()); client.print(sResponse); client.print(sResponse2); } else if(sPath=="/pressure") { ulReqcount++; sResponse = F("\n\nEnvironment Monitor\n\n\n\n\n

Environment Monitor



Last Sample Taken "); sResponse += theDate; sResponse2 = F("GMT
\n
\n"); sResponse2 += F("
\n


Pressure Graph Page
Sensor Gauge Page
Sensor Graph Page
Sensor Datalog Page
Diagnostics Information Page
Monitor LCD Text Input Page

"); sResponse2 += MakeHTTPFooter().c_str(); // Send the response to the client client.print(MakeHTTPHeader(sResponse.length()+sResponse2.length()).c_str()); client.print(sResponse); client.print(sResponse2); } else if(sPath=="/table") //////////////////////////////////// // format the html page for /tabelle //////////////////////////////////// { ulReqcount++; unsigned long ulSizeList = MakeTable(&client,false); // get size of table first sResponse = F("Environment Monitor"); sResponse += F(""); sResponse += F(""); sResponse += F("

Environment Monitor

"); sResponse += F("
Sensor Gauges Page
Pressure Graph Page
Pressure Gauge Page"); sResponse += F("
Sensor Graph Page
Diagnostics Information Page
Monitor LCD Text Input Page

Sample Interval 60 Seconds
"); // sResponse += ulMeasDelta_ms/1000; // sResponse += F(" Seconds
"); // here the big table will follow later - but let us prepare the end first // part 2 of response - after the big table sResponse2 = MakeHTTPFooter().c_str(); // Send the response to the client - delete strings after use to keep mem low client.print(MakeHTTPHeader(sResponse.length()+sResponse2.length()+ulSizeList).c_str()); client.print(sResponse); sResponse=""; MakeTable(&client,true); client.print(sResponse2); } else if(sPath=="/graphic") /////////////////////////////////// // format the html page for /grafik /////////////////////////////////// { ulReqcount++; unsigned long ulSizeList = MakeList(&client,false); // get size of list first sResponse = F("\n\nEnvironment Monitor\n\n"); sResponse += F("\n\n"); sResponse2 += F("\n

Environment Monitor


Pressure Graph Page
Pressure Gauge Page
Sensor Gauges Page
Sensor Datalog Page"); sResponse2 += F("
Diagnostics Information Page
Monitor LCD Text Input Page

\n
"); sResponse2 += MakeHTTPFooter().c_str(); // Send the response to the client - delete strings after use to keep mem low client.print(MakeHTTPHeader(sResponse.length()+sResponse2.length()+ulSizeList).c_str()); client.print(sResponse); sResponse=""; MakeList(&client,true); client.print(sResponse2); } else if(sPath=="/yfireset") { ulReqcount++; client.println("HTTP/1.1 200 OK"); client.println("Content-Type: text/html"); client.println("Connection: close"); client.println(); client.println(""); client.print("Environment Monitor"); client.print(""); client.print(""); client.print("

Environment Monitor
WiFi Reset Page


Pressure Graph Page
Pressure Gauge Page"); client.print("
Sensor Gauges Page
Sensor Graph Page
Sensor Datalog Page



Restarted WiFiConnections = "); client.print(ulReconncount); client.print("
environmental.monitor.log@gmail.com
ESP8266 With DHT11 & BMP180 Sensors
"); client.print("Compiled Using ver. 1.6.5-1160-gef26c5f, built on Sep 30, 2015
"); client.println(""); WiFiStart(); } else if(sPath=="/diag") { float servolt1 = ESP.getVcc(); long int spdcount = ESP.getCycleCount(); delay(1); long int spdcount1 = ESP.getCycleCount(); long int speedcnt = spdcount1-spdcount; FlashMode_t ideMode = ESP.getFlashChipMode(); ulReqcount++; File logF = SPIFFS.open("/humidlog.CSV", "r"); Dfsize = logF.size(); client.println("HTTP/1.1 200 OK"); client.println("Content-Type: text/html"); client.println("Connection: close"); client.println(); client.println(""); client.print("Environment Monitor"); client.print(""); client.print(""); client.print("

Environment Monitor
SDK Diagnostic Information


Pressure Graph Page
Pressure Gauge Page"); client.print("
Sensor Gauges Page
Sensor Graph Page
Sensor Datalog Page
Monitor LCD Text Input Page
Restarted WiFiConnections = "); String diagdat=""; diagdat+=ulReconncount; diagdat+="
Web Page Requests = "; diagdat+=ulReqcount; diagdat+="
WiFi Station Hostname = "; diagdat+=wifi_station_get_hostname(); diagdat+="
Free RAM = "; client.print(diagdat); client.print((uint32_t)system_get_free_heap_size()/1024); diagdat=" KBytes
Logged Sample Count = "; diagdat+=ulMeasCount; diagdat+="
Total Sample points in 24 Hours = 1440
Minimum Sample Logging Interval = 1 Minutes
SDK Version = "; diagdat+=ESP.getSdkVersion(); diagdat+="
Boot Version = "; diagdat+=ESP.getBootVersion(); diagdat+="
Free Sketch Space = "; diagdat+=ESP.getFreeSketchSpace()/1024; diagdat+=" KBytes
Sketch Size = "; diagdat+=ESP.getSketchSize()/1024; diagdat+=" KBytes
"; client.print(diagdat); client.printf(" Flash Chip id = %08X\n", ESP.getFlashChipId()); client.print("
"); client.printf(" Flash Chip Mode = %s\n", (ideMode == FM_QIO ? "QIO" : ideMode == FM_QOUT ? "QOUT" : ideMode == FM_DIO ? "DIO" : ideMode == FM_DOUT ? "DOUT" : "UNKNOWN")); diagdat="
Flash Size By ID = "; diagdat+=ESP.getFlashChipRealSize()/1024; diagdat+=" KBytes
Flash Size (IDE) = "; diagdat+=ESP.getFlashChipSize()/1024; diagdat+=" KBytes
Flash Speed = "; diagdat+=ESP.getFlashChipSpeed()/1000000; diagdat+=" MHz
ESP8266 CPU Speed = "; diagdat+=ESP.getCpuFreqMHz(); diagdat+=" MHz
"; client.print(diagdat); client.printf(" ESP8266 Chip id = %08X\n", ESP.getChipId()); diagdat="
System Instruction Cycles Per Second = "; diagdat+=speedcnt*1000; diagdat+="
Last System Restart Time = "; diagdat+=stheDate; diagdat+="
Last System Restart Reason = "; diagdat+=ESP.getResetInfo(); diagdat+="
System Time = "; diagdat+=emailtime; diagdat+=" (Last Recorded Sample Time)
System VCC = "; diagdat+=servolt1/1000, 3; diagdat+=" V
Datalog File Size in Bytes = "; diagdat+=Dfsize; client.print(diagdat); diagdat=""; client.print("
environmental.monitor.log@gmail.com
ESP8266 With DHT11 & BMP180 Sensors
Compiled Using ver. 1.6.5-1160-gef26c5f, built on Sep 30, 2015
"); client.println(""); } else if(sPath=="/srestart") { client.println("HTTP/1.1 200 OK"); client.println("Content-Type: text/html"); client.println("Connection: close"); client.println(); client.println(""); client.print("Environment Monitor"); client.print(""); client.print(""); client.print("

Environment Monitor
Please wait 10 Seconds......
System Reset Page !!!!


Pressure Graph Page
Pressure Gauge Page"); client.print("
Sensor Gauges Page
Sensor Graph Page
Sensor Datalog Page
Diagnostics Information Page
Monitor LCD Text Input Page



Restarted WiFiConnections = "); client.print(ulReconncount); client.print("


environmental.monitor.log@gmail.com
ESP8266 With DHT11 & BMP180 Sensors
"); client.print("Compiled Using ver. 1.6.5-1160-gef26c5f, built on Sep 30, 2015
"); client.println(""); client.stop(); wsysreset(); } else if(sPath=="/graphic2") ////////////////////////////////////// // format the html page for Barometer ////////////////////////////////////// { barom = true; ulReqcount++; unsigned long ulSizeList = MakeList(&client,false); // get size of list first sResponse = F("\n\nEnvironment Monitor\n\n"); sResponse += F("\n\n"); sResponse2 += F("\n

Environment Monitor


Pressure Gauge Page
Sensor Gauges Page
Sensor Graph Page"); sResponse2 += F("
Sensor Datalog Page
Diagnostics Information Page
Monitor LCD Text Input Page
\n
"); sResponse2 += MakeHTTPFooter().c_str(); // Send the response to the client - delete strings after use to keep mem low client.print(MakeHTTPHeader(sResponse.length()+sResponse2.length()+ulSizeList).c_str()); client.print(sResponse); sResponse=""; MakeList(&client,true); client.print(sResponse2); barom = false; } else //////////////////////////// // 404 for non-matching path //////////////////////////// { sResponse="404 Not Found

Not Found

The requested URL was not found on this server, What did you sk for?.

"; ulReqcount++; sHeader = F("HTTP/1.1 404 Not found\r\nContent-Length: "); sHeader += sResponse.length(); sHeader += F("\r\nContent-Type: text/html\r\nConnection: close\r\n\r\n"); // Send the response to the client client.print(sHeader); client.print(sResponse); } // and stop the client client.stop(); } byte sendEmail() { byte thisByte = 0; byte respCode; if(client.connect( popyahoo,port) == 1) { lcd.clear(); lcd.print(F("connectedsmtp2go")); } else { lcd.clear(); lcd.print(F("SMconnect failed")); return 0; } if(!eRcv()) {lcd.print("before ehlo");return 0 ;} lcd.clear(); lcd.print(F("Sending ehlo")); client.print("EHLO "); client.println(WiFi.localIP()); lcd.setCursor(0, 1); if(!eRcv()) {lcd.print("ehlo");return 0 ;} lcd.clear(); lcd.print(F("Sending auth login")); client.println("auth login"); lcd.setCursor(0, 1); if(!eRcv()) {lcd.print("auth");return 0 ;} lcd.print("Sending User"); // Change to your base64 encoded user client.println(b64Usernm);// if(!eRcv()) {lcd.print("user");return 0 ;} lcd.print(F("Sending Password")); // change to your base64 encoded password client.println(b64Passwd);// lcd.setCursor(0, 1); if(!eRcv()) {lcd.print("ehlo");return 0;} // change to your email address (sender) Send All Mail to Environment Monitor client.println(frmaddrs); lcd.setCursor(0, 1); if(!eRcv()) {lcd.print("email");return 0 ;} lcd.clear(); // change to recipient address Send All Mail to Environment Monitor lcd.print(F("Sending To")); client.println(toaddres); lcd.setCursor(0, 1); if(!eRcv()) {lcd.print("email");return 0 ;} lcd.clear(); lcd.print(F("Sending DATA")); client.println("DATA"); lcd.setCursor(0, 1); if(!eRcv()) {lcd.print("email");return 0 ;} lcd.clear(); lcd.print(F("Sending email")); // change to recipient address Send All Mail to Environment Monitor client.println("To: The Environment Monitor "); String sTable; // change to your address This is sensor ID client.print("From: Weather Station Development <"); client.print(wifi_station_get_hostname()); client.println(">"); client.println("Subject: ESP8266 Daily Environment Report\r\n"); client.println("This is Sent Directly from An ESP8266 Module every 24 Hours"); client.print("The Total Number Of Environment Samples Values Being Tranferred Are - "); client.println(ulMeasCount); client.println("_____________________________________________________________"); File logF = SPIFFS.open("/humidlog.CSV", "r"); if (!logF) { lcd.print("rOr humidlog.CSV"); while(1); } DsTable = logF.readStringUntil('['); while (logF.available()) { sTable = logF.readStringUntil(']'); sTable += (","); sTable += logF.readStringUntil(','); client.println(sTable); DsTable = logF.readStringUntil('['); sTable=""; } client.println(sTable); client.println("_________________End of Data_______________"); client.println("."); if(!eRcv()) {lcd.print("aftersending");return 0 ;} lcd.setCursor(0, 1); lcd.print("Sending QUIT"); client.println("QUIT"); lcd.clear(); if(!eRcv()) {lcd.print("afterQuit");return 0 ;} client.stop(); lcd.setCursor(0, 1); lcd.print("disconnected"); return 1; } byte eRcv() { byte respCode; byte thisByte; int loopCount = 0; while(!client.available()) { delay(1); loopCount++; // if nothing received for 10 seconds, timeout if(loopCount > 10000) { client.stop(); lcd.print("10 sec Timeout"); return 0; } } respCode = client.peek(); while(client.available()) { thisByte = client.read(); } if(respCode >= '4') { efail(); return 0; } return 1; } void efail() { byte thisByte = 0; int loopCount = 0; client.println("QUIT"); while(!client.available()) { delay(1); loopCount++; // if nothing received for 10 seconds, timeout if(loopCount > 10000) { client.stop(); lcd.print("efail Timeout"); return; } } while(client.available()) { thisByte = client.read(); } client.stop(); lcd.print("disconnected"); }