Example sketches for the new Arduino IDE for ESP8266

Moderator: igrr

User avatar
By GengusKahn
#33250 This is a use for an ESP with i2c to RTC and LCD displaying the Environment Sensed via DHT22, this host an Access Point and has a client connection to your router.
The LCD Text can be written to from the Hosted site. the data is displayed via a Table, Graphs and Charts with all data being stored in SPIFFS leaving most of the SRAM free....

The only file management here is to reboot but I have an SDCARD attached and this takes the backup before reboot this is a simpler version to allow the understanding of File IO.

For the Google services the device must be connected to router....

Look at the BBC in the UK for the Sample Output from a slightly larger setup........ESP8266 DDTMonitor.....

http://bbc.in/1LYbwUg

This is the Sketch But please note this is a collection of a lot of peoples efforts most of whom are members of this site and please consider a Donation to the ESP8266.COM Cause(found elsewhere on this site)........

Code: Select all/*---------------------------------------------------
                 _____
                </\|/\>
          _-_-_-_ *|* _-_-_-_
         -_-_-_-_-\@/-_-_-_-_-
         
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/                        Google Gauges
                /lcd                     Webpage to LCD Text Input
                /diag                    SDK Functionality
                /graphic                 Google Line Chart
                /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 512KByte Flash with 64KB SPIFFS can hold 1800 records of 30 bytes (1 temperature + 1 humidity reading + Timestamp) Approx. 54KB

This evolution is the product of the Environment Monitor......
environmental.monitor.log@gmail.com AKA Gengus Kahn.....

See a feed from 2 DHT11's on twitter at http://twitter.com/DDTMonitor

This will read various sensors  with the Data from the Sensors presented via Web Gauges, Graphs & Tables.....

Setup = DHT22 and an ESP8266 with 512KB Flash i2c LCD + RTC

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  2


__________________________________________________________________________________________________
......Use 5v to 3v Level Shifters as 5V devices like PIR and HC-SR04 can damage your device.......
--------------------------------------------------------------------------------------------------
 ___/'¬_         /\
{_-_ ^  \_______//
     /           \
     \ _  _____  /
     || ||     |||
     || ||     ||| 
---------------------------------------------------*/

#include <ESP8266WiFi.h>
#include "FS.h"
#include <Wire.h>
#include <Time.h>
#include <DS1307RTC.h>
#include <LiquidCrystal_I2C.h>
#include "DHT.h"
tmElements_t tm;
LiquidCrystal_I2C lcd(0x27,16,2);

extern "C"
{
#include "user_interface.h"
}
//////////////////////////////
// DHT21 / AMS2301 is at GPIO2
//////////////////////////////
#define DHTPIN 2

// Uncomment whatever type you're using!
//#define DHTTYPE DHT11   // DHT 11
#define DHTTYPE DHT22   // DHT 22  (AM2302)
//#define DHTTYPE DHT21   // DHT 21 (AM2301)
// init DHT11; 3rd parameter = 12 works for ESP8266@80MHz
DHT dht(DHTPIN, DHTTYPE,12);
const char* ssid = "YOUR SSID";  // Station to connect to Internet
const char* password = "YOUR PASSWORD";
String tmtxt1,tmtxt2,Dtmtxt;
String lastdata;
String logdata;
String sPath;
boolean got_text = false;
unsigned long ulReconncount;
unsigned long ulReqcount;
float tI;
float hI;
int scount = 0;
int count = 0;
int sinter = 56;
int Dfsize = 0;
char status;
IPAddress apIP(192, 168, 4, 1);
WiFiServer server(82);
WiFiClient client;
  time_t  prevEventTime ;
  time_t duration = 0;
void wsysreset()
{
    ESP.restart();
}
void WiFiStart()
{
  ulReconncount++;
  WiFi.mode(WIFI_AP_STA);
  WiFi.softAPConfig(apIP, apIP, IPAddress(255, 255, 255, 0));
  WiFi.softAP("DDTMonitor http://192.168.4.1");
  WiFi.begin(ssid, password);
  while (WiFi.status() != WL_CONNECTED)
  {
    delay(500);
  }
  server.begin();
}


void setup() {
//  Serial.begin(115200);   
  WiFiStart();
    setSyncProvider(RTC.get);
  lcd.init();
  lcd.backlight();
if (!SPIFFS.begin()) {
         lcd.print("SPIFFSinitFailed");
         delay(10000);
       }
      if (SPIFFS.exists("/humidlog.CSV")){ SPIFFS.remove("/humidlog.CSV");}
           lcd.clear();
  lcd.print("Environmental ");
  lcd.setCursor(0, 1);
  lcd.print("Monitor         ");
  delay(3000);
      hI = dht.readHumidity();
    tI = dht.readTemperature();
  lcd.clear(); 
  if (RTC.read(tm)) {
    lcd.print("Time:  ");
    print2digits(tm.Hour);
    lcd.print(':');
    print2digits(tm.Minute);
    lcd.print(':');
    print2digits(tm.Second);
    lcd.setCursor(0, 1);
    lcd.print("Date: ");
    print2digits(tm.Day);
    lcd.print('/');
    print2digits(tm.Month);
    lcd.print('/');
    lcd.print(tmYearToCalendar(tm.Year));
    delay(5000);
  } else {
    if (RTC.chipPresent()) {
      lcd.print("DS1307 stopped !");
    } else {
      lcd.print("DS1307 error!");
    }
    delay(10000);
  }
  server.begin();
}

void showDuration(time_t duration){
  if(duration >= SECS_PER_DAY){
     duration = duration % SECS_PER_DAY;     
  }
  if(duration >= SECS_PER_HOUR){
     duration = duration % SECS_PER_HOUR;     
  }
  if(duration >= SECS_PER_MIN){
     duration = duration % SECS_PER_MIN;     
  }
}


void loop() {
 count=count+1;
 ///////////////////

  time_t timeNow = now();
duration = duration = timeNow - prevEventTime;   
if (count == 10 || count == 20 || count == 30 || count == 40 || count == 50) {
  if (got_text == true)
    {
 if (tmtxt1!=""){     
        lcd.clear();
        lcd.setCursor(0, 0);
        lcd.print(tmtxt1);
        lcd.setCursor(0, 1);
        lcd.print(tmtxt2);
        delay(2000);
        }
        else{
        got_text == false;
        }
    }

}
  if (count < 30) {
  lcd.clear();
    lcd.print("Temp  = ");
    lcd.print(tI);
  lcd.setCursor(13, 0);
    lcd.print("C ");
  lcd.setCursor(0, 1);
    lcd.print("Humid = "); 
    lcd.print(hI);
  lcd.setCursor(13, 1);
    lcd.print("%");
    delay(1000);
    }
      if (duration > sinter){ 
    hI = dht.readHumidity();
    tI = dht.readTemperature();
 lastdata="";
    lastdata += tI;
    lastdata += ",hum=";
    lastdata += hI;
  logdata = "['";
if (tm.Hour <10){logdata += "0";}   
  logdata += tm.Hour;
  logdata += ":";
if (tm.Minute <10){logdata += "0";}
  logdata += tm.Minute;
  logdata += "-";
if (tm.Day <10){logdata += "0";}
  logdata += tm.Day;
  logdata += "/";
if (tm.Month <10){logdata += "0";}
  logdata += tm.Month;
  logdata += "',";
  logdata += tI;
  logdata += ",";
  logdata += hI; 
  logdata += "],"; 
File dataFile1 = SPIFFS.open("/humidlog.CSV", "a");     
  if (dataFile1) {
    dataFile1.println(logdata);
    Dfsize = dataFile1.size();
    dataFile1.close();
    delay(1);
      }
    else {
      lcd.clear();
      lcd.print("rOr humidlog.CSV");
      delay(10000);
    } 
     
        if (scount >1800) {
          ESP.restart();
      }
              scount=scount+1;
        time_t timeNow = now();
        prevEventTime = timeNow;
        showDuration(duration);
        RTC.read(tm);
    } 
if (count > 50) {
         if (WiFi.status() != WL_CONNECTED){WiFiStart();}
    lcd.clear();
  if (RTC.read(tm)) {
    lcd.print("Time:  ");
    print2digits(tm.Hour);
    lcd.print(':');
    print2digits(tm.Minute);
    lcd.print(':');
    print2digits(tm.Second);
    lcd.setCursor(0, 1);
    lcd.print("Date: ");
    print2digits(tm.Day);
    lcd.print('/');
    print2digits(tm.Month);
    lcd.print('/');
    lcd.print(tmYearToCalendar(tm.Year));
    delay(1000);
  } else {
    if (RTC.chipPresent()) {
      lcd.print("DS1307 stopped !");
    } else {
      lcd.print("DS1307 error!");
    }
    delay(10000);
  }
}
     if (count > 52){count=0;} 
 WiFiClient client = server.available();
  if (!client)
  {
    return;
  }
  unsigned long ultimeout = millis()+250;
  while(!client.available() && (millis()<ultimeout) )
  {
    delay(1);
  }
  if(millis()>ultimeout)
  {
    return;
  }
  String sRequest = client.readStringUntil('\r');
  client.flush();
  if(sRequest=="")
  {
    client.stop();
    return;
  }
  ulReqcount++;
  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);
    if(iEndSpace>0)
    {
      if(iEndQuest>0)
      {
        sPath  = sRequest.substring(iStart,iEndQuest);
        sParam = sRequest.substring(iEndQuest,iEndSpace);
/*      Serial.println("Returned Web Path  ");   // Use this to Verify the actions on returned data
        Serial.println(sPath);
        Serial.println("Returned Parameters");
        Serial.println(sParam);
*/
      }
      else
      {
        sPath  = sRequest.substring(iStart,iEndSpace);
  //      Serial.println("Returned Web Path  ");    // Use this to Verify the actions on returned data
    //    Serial.println(sPath);
      }
    }
  }
// /ajax_inputs&L1=123456789&L2=&nocache=968337.7823963541
   if (sPath.startsWith("/ajax_inputs&L1="))
   {
     tmtxt1="";
     tmtxt2="";
    got_text = true;                    // print the received text to the LCD if found
File temptext = SPIFFS.open("/temp.txt", "w");     
  if (temptext) {
    temptext.print(sPath);
    temptext.close();
    delay(1);
      }
    else {
      lcd.clear();
      lcd.print("rOr Temp.TXT");
      delay(10000);
    }
    File in = SPIFFS.open("/temp.txt", "r");
     in.setTimeout(0);
       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);
      delay(3000);
   }
  if(sPath=="/")
  {
          client.println("HTTP/1.1 200 OK");                                    // send web page
          client.println("Content-Type: text/html");
          client.println("Connection: close");
          client.println();
          client.println("<!DOCTYPE HTML>"); 

                       File webFile = SPIFFS.open("/gaugep01.htm", "r");        // open web page file
                         if (webFile) {
                            while(webFile.available()) {
                                client.print(webFile.readString()); // send web page to client
                            }
                            webFile.close();
                        }
                        client.print(lastdata);                        // send data from last sample
                       File webFile1 = SPIFFS.open("/gaugep02.htm", "r");        // open web page file
                       
                        if (webFile1) {
                            while(webFile1.available()) {
                                client.print(webFile1.readString()); // send web page to client
                            }
                            webFile1.close();
                        }
                      File webFile2 = SPIFFS.open("/gaugep03.htm", "r");        // open web page file
                       
                        if (webFile2) {
                            while(webFile2.available()) {
                                client.print(webFile2.readString()); // send web page to client
                                }
                            webFile2.close();
                            }
     delay(1);   
client.stop();
return;
        }
   else if(sPath=="/table")
  {
          client.println("HTTP/1.1 200 OK");
          client.println("Content-Type: text/html");
          client.println("Connection: close");
          client.println();
          client.println("<!DOCTYPE HTML>");
          client.print("<html><head><title>Environmental Data Logger</title></head><body>");
          client.print("<font color=\"#000000\"><body bgcolor=\"#d0d0f0\">");
          client.print("<meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0, user-scalable=yes\">");
          client.print("<h1>Environment Monitor<BR>Data Log </h1>");
          client.print("<FONT SIZE=+1><a href=\"/\">Sensor Gauges Page</a><BR><a href=\"/graph\">Sensor Graph Page</a><BR><a href=\"/diag\">Diagnostic Page</a><BR><a href=\"/lcd\">LCD TEXT Display Page</a><BR>Sample Interval  Approx. 60 Seconds<BR>");
  File logF = SPIFFS.open("/humidlog.CSV", "r");
    if (!logF) {
      lcd.clear();
      lcd.print("rOr humidlog.CSV");
    }
    String sTable;
    String DsTable;        //Discarded characters used to seperate the data into single readings
    sTable = "<table style=\"width:100%\"><tr><th>Time / GMT</th><th>Date   </th><th>IntT &deg;C</th><th>IntHum &#037;</th></tr>";
    sTable += "<style>table, th, td {border: 2px solid black; border-collapse: collapse;} th, td {padding: 5px;} th {text-align: left;}</style><tr><td>";
     DsTable = logF.readStringUntil('\'');
   logF.setTimeout(0);
   while(logF.available()) {
      sTable += logF.readStringUntil('-');
      sTable += "</td><td>";
      sTable += logF.readStringUntil('\'');
      sTable += "</td><td>";
     DsTable = logF.readStringUntil(',');
      sTable += logF.readStringUntil(',');
      sTable += "</td><td>";
      sTable += logF.readStringUntil(']');
      sTable+="</td></tr>";
      client.print(sTable);
     DsTable = logF.readStringUntil('\'');
      sTable = "<tr><td>";
  }
    logF.close();
    delay(1);
    client.print("<FONT SIZE=-1>environmental.monitor.log@gmail.com<BR><FONT SIZE=-2>ESP8266 With 1602 I2C LCD, DS1307 and DHT22 Peripherals Logging to SPIFFS<BR><FONT SIZE=-2>Compiled Using ver. 1.6.5-1160-gef26c5f, built on Sep 30, 2015");
    client.println("</body></html>");
    delay(10);   
client.stop();
return;
  }             

   else if(sPath=="/diag")
  {
     float   servolt1 = ESP.getVcc(); // Only use if Nothing connected to the ADC Pin !!!
     long int spdcount = ESP.getCycleCount();
     delay(1);
     long int spdcount1 = ESP.getCycleCount();
     long int speedcnt = spdcount1-spdcount;
     FlashMode_t ideMode = ESP.getFlashChipMode();
     File dlog = SPIFFS.open("/humidlog.CSV", "r");
     Dfsize=dlog.size();
     dlog.close();
     String duration1;
     int hr,mn,st;
     st = millis() / 1000;
     mn = st / 60;
     hr = st / 3600;
     st = st - mn * 60;
     mn = mn - hr * 60;
     if (hr<10) {duration1 += ("0");}
     duration1 += (hr);
     duration1 += (":");
     if (mn<10) {duration1 += ("0");}
     duration1 += (mn);
     duration1 += (":");
     if (st<10) {duration1 += ("0");}
     duration1 += (st);
                                client.println("HTTP/1.1 200 OK");                   
                                client.println("Content-Type: text/html");
                                client.println("Connection: close");
                                client.println();
                                client.println("<!DOCTYPE HTML>");
                                client.print("<html><head><title>Internal Diagnostic Page</title></head><body>");
                                client.print("<font color=\"#000000\"><body bgcolor=\"#d0d0f0\">");
                                client.print("<meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0, user-scalable=yes\">");
                                client.print("<h1>Diagnostic Information</h1>");
                                client.print("<a href=\"/graph\">Sensor Graph Page</a><BR><a href=\"/\">Sensor Gauges Page</a><BR><a href=\"/table\">Datalog Table Page</a><BR><a href=\"/lcd\">LCD TEXT Display Page</a><BR>Restarted WiFiConnections = ");
                                client.print(ulReconncount);
                                client.print("<BR>  Web Page Requests = ");
                                client.print(ulReqcount);
                                client.print("<BR>  Total Sample Count = ");
                                client.print(count);
                                client.print("<BR>  Logged Sample Count = ");
                                client.print(scount);
                                client.print("<BR>  Approx Sample points in 24 Hours = 1440");
                                client.print("<BR>  Minimum Sample Logging Interval = ");  // Minimum timing of Sensor Readings;
                                client.print(sinter);  // Interval used for datalogging
                                client.print(" Seconds<BR>  WiFi Station Hostname = ");
                                client.print(wifi_station_get_hostname());
                                client.print("<BR>  SDK Version = ");
                                client.print(ESP.getSdkVersion());
                                client.print("<BR>  Boot Version = ");
                                client.print(ESP.getBootVersion());
                                client.print("<BR>  Free RAM = ");
                                client.print((uint32_t)system_get_free_heap_size());
                                client.print("KB<BR>  Free Sketch Space  = ");
                                client.print(ESP.getFreeSketchSpace()/1024);
                                client.print("KB<BR>  Sketch Size  = ");
                                client.print(ESP.getSketchSize()/1024);
                                client.print("KB<BR>");
                                client.printf("  Flash Chip id = %08X\n", ESP.getFlashChipId());
                                client.print("<BR>");
                                client.printf("  Flash Chip Mode = %s\n", (ideMode == FM_QIO ? "QIO" : ideMode == FM_QOUT ? "QOUT" : ideMode == FM_DIO ? "DIO" : ideMode == FM_DOUT ? "DOUT" : "UNKNOWN"));
                                client.print("<BR>  Flash Size By ID = ");
                                client.print(ESP.getFlashChipRealSize()/1024);
                                client.print(" KBytes<BR>  Flash Size (IDE) = ");
                                client.print(ESP.getFlashChipSize()/1024);
                                client.print(" KBytes<BR>  Flash Speed = ");
                                client.print(ESP.getFlashChipSpeed()/1000000);
                                client.print("MHz<BR>  ESP8266 CPU Speed = ");
                                client.print(ESP.getCpuFreqMHz());
                                client.print("MHz<BR>");
                                client.printf("  ESP8266 Chip id = %08X\n", ESP.getChipId());
                                client.print("<BR>  System Instruction Cycles Per Second = ");
                                client.print(speedcnt*1000); 
                                client.print("<BR>  System - Last Restart Reason = ");
                                client.print(ESP.getResetInfo());
                                client.print("<BR>  System Uptime = ");
                                client.print(duration1);
                                client.print("<BR>  System Time = ");
                                RTC.read(tm);
                                if (tm.Hour <10){client.print("0");}   
                                client.print(tm.Hour);
                                client.print(':');
                                if (tm.Minute <10){client.print("0");}
                                client.print(tm.Minute);
                                client.print(':');
                                if (tm.Second <10){client.print("0");}
                                client.print(tm.Second);
                                client.print("<BR>  Datalog File Size = ");
                                client.print(Dfsize);
                                client.print("Bytes <BR>");
                                client.print("<BR><FONT SIZE=-1>environmental.monitor.log@gmail.com<BR><FONT SIZE=-2>ESP8266 With 1602 I2C LCD, DS1307 and DHT22 Peripherals Logging to SPIFFS<BR><FONT SIZE=-2>Compiled Using ver. 1.6.5-1160-gef26c5f, built on Sep 30, 2015<BR>");
                                client.println("<BR><IMG SRC=\"https://raw.githubusercontent.com/genguskahn/ESP8266-For-DUMMIES/master/SoC/DimmerDocs/organicw.gif\" WIDTH=\"250\" HEIGHT=\"151\" BORDER=\"1\"></body></html>");
  delay(1);   
  client.stop();
  return;
  }
     else if(sPath=="/graph")
  {                        // send web page
                                client.println("HTTP/1.1 200 OK");                   
                                client.println("Content-Type: text/html");
                                client.println("Connection: close");
                                client.println();
                                client.println("<!DOCTYPE HTML>");
                       File webFile1 = SPIFFS.open("/graphp01.htm", "r");        // open web page file
                       
                        if (webFile1) {
                            while(webFile1.available()) {
                                client.print(webFile1.readString()); // send web page to client
                            }
                            webFile1.close();
                        }
                       File in = SPIFFS.open("/humidlog.CSV", "r");
                        if (!in) {
                           lcd.clear();
                           lcd.print("rOr humidlog.CSV");
                           }
                         String sTable;            //Send Log as a String, formatting for webpage via ' ,  written into file
                         String DsTable;           //Discarded characters used to seperate the data into single records
                         sTable = "";
                         in.setTimeout(0);
                        while(in.available()) {
                                sTable += in.readStringUntil(']');
                                sTable += "],";
                                client.println(sTable);
                                DsTable = in.readStringUntil('[');
                                sTable="[";
                                }
                         in.close();
                       File webFile2 = SPIFFS.open("/graphp02.htm", "r");        // open web page file                       
                        if (webFile2) {
                            while(webFile2.available()) {
                                client.print(webFile2.readString()); // send web page to client
                                }
                            webFile2.close();
                            }
                             delay(10);   
client.stop();
return;
  }
       else if(sPath=="/lcd")
  {
                           // send rest of HTTP header
                        client.println("HTTP/1.1 200 OK");     
                        client.println("Content-Type: text/html");
                        client.println("Connection: keep-alive");
                        client.println();
                        // send web page
                      File webFile = SPIFFS.open("/index1.htm", "r");        // open web page file
                        if (webFile) {
                            while(webFile.available()) {
                                client.print(webFile.readString()); // send web page to client
                            }
                            webFile.close();
                        }
  } else if(sPath=="/yfireset")
  {
                                    client.println("HTTP/1.1 200 OK");
                                client.println("Content-Type: text/html");
                                client.println("Connection: close");
                                client.println();
                                client.println("<!DOCTYPE HTML>");
                                client.print("<html><head><title>Environment Monitor</title></head><body>");
                                client.print("<font color=\"#000000\"><body bgcolor=\"#d0d0f0\">");
                                client.print("<meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0, user-scalable=yes\">");
                                client.print("<h1>Environment Monitor<BR>WiFi Reset Page </h1>");
                                client.print("<BR><a href=\"/monitor\">Sensor Gauges Page</a><BR><a href=\"/graphic\">Sensor Graph Page</a><BR><a href=\"/table\">Sensor Datalog Page</a><BR><a href=\"/diag\">Diagnostics Page</a><BR><BR><BR>Restarted WiFiConnections = ");
                                client.print(ulReconncount);
                                client.print("<BR><FONT SIZE=-2>environmental.monitor.log@gmail.com<BR><FONT SIZE=-2>ESP8266-07 With DS18B20, DHT11 & BMP180 Sensors<BR>");
                                client.print("<FONT SIZE=-2>Compiled Using ver. 1.6.5-1160-gef26c5f, built on Sep 30, 2015<BR>");
                                client.println("<IMG SRC=\"https://raw.githubusercontent.com/genguskahn/ESP8266-For-DUMMIES/master/SoC/DimmerDocs/organicw.gif\" WIDTH=\"250\" HEIGHT=\"151\" BORDER=\"1\"></body></html>");

  WiFiStart();
  }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("<!DOCTYPE HTML>");
                                client.print("<html><head><title>Environment Monitor</title></head><body>");
                                client.print("<font color=\"#000000\"><body bgcolor=\"#d0d0f0\">");
                                client.print("<meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0, user-scalable=yes\">");
                                client.print("<h1>Environment Monitor<BR>Please wait 10 Seconds......<BR><FONT SIZE=+2>System Reset Page !!!! </h1>");
                                client.print("<BR><a href=\"/monitor\">Sensor Gauges Page</a><BR><a href=\"/graphic\">Sensor Graph Page</a><BR><a href=\"/table\">Sensor Datalog Page</a><BR><a href=\"/diag\">Diagnostics Page</a><BR><BR><BR>Restarted WiFiConnections = ");
                                client.print(ulReconncount);
                                client.print("<BR><BR><BR><FONT SIZE=-2>environmental.monitor.log@gmail.com<BR><FONT SIZE=-2>ESP8266-07 With DS18B20, DHT11 & BMP180 Sensors<BR>");
                                client.print("<FONT SIZE=-2>Compiled Using ver. 1.6.5-1160-gef26c5f, built on Sep 30, 2015<BR>");
                                client.println("<IMG SRC=\"https://raw.githubusercontent.com/genguskahn/ESP8266-For-DUMMIES/master/SoC/DimmerDocs/organicw.gif\" WIDTH=\"250\" HEIGHT=\"151\" BORDER=\"1\"></body></html>");
client.stop();
wsysreset();
  }
  else{
  delay(10);   
client.stop();
return;
  }
}


void print2digits(int number) {
  if (number >= 0 && number < 10) {
    lcd.print('0');
  }
  lcd.print(number);
}     


The Webpages, these must be uploaded to SPIFFS using the FS tool........

This is the LCD Input page save this as index1.htm
Code: Select all<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="utf-8">
        <title>Environment Monitor Text to LCD</title>
        <script>

        strLine1 = "";
        strLine2 = "";
       
        function SendText()
        {
            nocache = "&nocache=" + Math.random() * 1000000;
            var request = new XMLHttpRequest();
           
            strLine1 = "&L1=" + document.getElementById("txt_form").line1LCD.value;
            strLine2 = "&L2=" + document.getElementById("txt_form").line2LCD.value;
           
            request.open("GET", "ajax_inputs" + strLine1 + strLine2 + nocache, true);
            request.send(null);
        }
        </script>
  <body>
<h1>Environment Monitor<BR>LCD Text Input</h1>
<BR><a href="/graph">Sensor Graph Page</a><BR><a href="/">Sensor Gauges Page</a><BR><a href="/table">Datalog Table Page</a><BR><a href="/diag">Diagnostics Information Page</a><BR>
    <body onload="GetESP8266IO()">
       <h1><FONT SIZE=-1>Enter text to send to ESP8266 LCD:</h1>
        <form id="txt_form" name="frmText">
            <label>Line 1: <input type="text" name="line1LCD" size="16" maxlength="16" /></label><br /><br />
            <label>Line 2: <input type="text" name="line2LCD" size="16" maxlength="16" /></label>
        </form>
        <br />
        <input type="submit" value="Send Text" onclick="SendText()" />

<font color="#000000"><body bgcolor="#d0d0f0"><meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=yes"><BR>LCD Text Input<BR>
<div style="clear:both;"><FONT SIZE=-1>environmental.monitor.log@gmail.com<BR><FONT SIZE=-2>ESP8266 With 1602 I2C LCD, DS1307 and DHT22 Peripherals Logging to SPIFFS<BR>Compiled using ver. 1.6.5-1160-gef26c5f, built on Sep 30, 2015<BR></body></html>


This is the first of the Gauges files 1 page split into 2KB chunks to allow streaming the file.
This should be saved as gaugep01.htm
Code: Select all<html>
<head>
<title>Temperature and Humidity Logger</title>
<script type="text/javascript" src="https://www.google.com/jsapi?autoload={'modules':[{'name':'visualization','version':'1','packages':['gauge']}]}"></script>
<script type="text/javascript">
var temp=


This should be saved as gaugep02.htm
Code: Select all;google.load('visualization', '1', {packages: ['gauge']});google.setOnLoadCallback(drawgaugetemp);google.setOnLoadCallback(drawgaugehum);
var gaugetempOptions = {min: -10, max: 40, yellowFrom: -10, yellowTo: 16,redFrom: 28, redTo: 40, minorTicks: 10, majorTicks: ['-10','0','10','20','30','40']};
var gaugehumOptions = {min: 0, max: 100, yellowFrom: 0, yellowTo: 25, redFrom: 70, redTo: 100, minorTicks: 10, majorTicks: ['0','10','20','30','40','50','60','70','80','90','100']};
var gaugetemp,gaugehum;

function drawgaugetemp() {
gaugetempData = new google.visualization.DataTable();
gaugetempData.addColumn('number', 'Int °C');
gaugetempData.addRows(1);
gaugetempData.setCell(0, 0, temp);
gaugetemp = new google.visualization.Gauge(document.getElementById('gaugetemp_div'));
gaugetemp.draw(gaugetempData, gaugetempOptions);
}

function drawgaugehum() {
gaugehumData = new google.visualization.DataTable();
gaugehumData.addColumn('number', 'Ext %');
gaugehumData.addRows(1);
gaugehumData.setCell(0, 0, hum);
gaugehum = new google.visualization.Gauge(document.getElementById('gaugehum_div'));
gaugehum.draw(gaugehumData, gaugehumOptions);
}


This should be saved as gaugep03.htm
Code: Select all</script>
</head>
<body>
<font color="#000000"><body bgcolor="#d0d0f0"><meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=yes"><h1>Environment Monitor</h1><BR>
<div id="gaugetemp_div" style="float:left; width:160px; height: 160px;"></div>
<div id="gaugehum_div" style="float:left; width:160px; height: 160px;"></div>
<div style="clear:both;"></div><p> Temperature and Humidity Display<BR><a href="/table">Sensor Datalog Page</a><BR><a href="/graph">Sensor Graph Page</a><BR><a href="/diag">Diagnostic Page</a><BR><a href="/lcd">LCD TEXT Display Page</a><BR></p><FONT SIZE=-1>environmentalmonitor.log@gmail.com<BR>ESP8266 With 1602 I2C LCD, DS1307 and DHT22 Peripherals Logging to SPIFFS<BR>Compiled using ver. 1.6.5-1160-gef26c5f, built on Sep 30, 2015<BR></body></html>


This is the Charts...
This should be saved as graphp01.htm
Code: Select all<html>
<head>
<title>Environment Monitor</title>
<script type="text/javascript" src="https://www.google.com/jsapi?autoload={'modules':[{'name':'visualization','version':'1','packages':['corechart']}]}"></script>
<script type="text/javascript"> google.setOnLoadCallback(drawChart);
function drawChart() {var data = google.visualization.arrayToDataTable([
['Time / GMT', 'InTmp', 'InHum'],



Finally this should be saved as graphp02.htm
Code: Select all]);
var options = {title: 'Environment',vAxes:{0:{viewWindowMode:'explicit',gridlines:{color:'black'},format:"##.##°C"},1: {gridlines:{color:'transparent'},format:"##,##%"},},series:{0:{targetAxisIndex:0},1:{targetAxisIndex:1},},curveType:'function',legend:{ position: 'bottom'}};var chart = new google.visualization.LineChart(document.getElementById('curve_chart'));chart.draw(data, options);}
</script>
</head>
<body>
<font color="#000000"><body bgcolor="#d0d0f0"><meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=yes"><h1>Environment Monitor</h1><BR><a href="/">Sensor Gauges Page</a><BR><a href="/table">Sensor Datalog Page</a><BR><a href="/diag">Diagnostics Page</a><BR><a href="/lcd">LCD TEXT Display Page</a><BR><BR>
<div id="curve_chart" style="width: 800px; height: 600px"></div> <BR>environmental.monitor.log@gmail.com<BR><FONT SIZE=-2>ESP8266 With 1602 I2C LCD, DS1307 and DHT22 Peripherals Logging to SPIFFS<BR><FONT SIZE=-2>Compiled Using ver. 1.6.5-1160-gef26c5f, built on Sep 30, 2015</body></html>