ESP8266 --Internet Weather Datalogger and Dynamic Web Server

Ported my Arduino Mega project, “SdBrowse_CC3000_HTTPServer.ino” over to ESP8266EX based, WeMOS D1 R2 Development Board (Arduino compatible, with the exception of some libraries.)

WeMOS D1 R2

During the porting of project martinayotte of the ESP8266 Community Forum converted two functions; listFiles and readFile functions. Along the way on the original projects there was help from Arduino.cc Forum, Adafruit Forum, Arduino Stack Exchange.

Project uses many reusable functions; logtoSD, lcdDisplay, listen, listFiles, readFile, ReadDS3231, getDateTime, getWeatherDate, updateDifference, newDay, and fileStore.

ESP8266 --Internet Weather Datalogger and Dynamic Web Server

March 30, 2017 Current Features of renamed project, “Oberservations_SPIFFS.ino”. SPIFFS is the Flash meory system built-in the WiFi module on weMOS board.

Requires WeMOS D1 R2 Development Board, Real time clock (DS3231) and Barometric Pressure, Humidity/Temperature sensor (BME280).

  1. Real Time Clock; used for 15 -minute time interval, date and time stamping and dayofWeek (every 0 day of the DS3231, log.txt file gets renamed to keep file size manageable. Every Saturday (0 day of week) log.txt gets renamed in the format “logxxyy” xx being the month and yy being the date; a new log.txt is created after every file renaming.

  2. Dynamic web page of current observations for Last update time and date, Humidity, dew point, temperature, heat index, barometric pressure (both inches of Mercury and millibars.)

  3. SPIFFS files are listed as web links; clicking link prompts for “Open with/Save as.” “System~1/”, “Favicon.ico”, and “Access” are listed; however, they are for internal use and cannot “Opened with/Save as,” result of clicking link produces “404 Page not found.”

  4. LOG.TXT file is appended every 15 -minutes with the latest update; storing data from Dynamic web page.

  5. ACCESS.TXT restricted file that logs client IP address.

  6. DIFFER.TXT stores the difference in Barometric Pressure for the last fifteen minutes. Only a difference of equal to or greater than .020 inches of Mercury are logged with difference, date and time.

  7. URL file names other than ones defined in the Sketch produce “404 Page not found.”

  8. Audible alert from Piezo electric buzzer when there is Barometric Pressure difference of .020 inches of Mercury. I am interested in sudden drop of Barometric Pressure in a 15-minute interval. Serve weather more likely with a sudden drop. Difference of .020 inches of Mercury point is set for my observations to log and sound audible alert; not based on any known value to be associated with serve weather.

  9. Two-line LCD Display of Barometric Pressure, in both inches of Mercury and millibars.
    Server is a WeMOS D1 R2, Model 2.1.0 Development Board – purchased on Ebay for ~ 9.00 and BME280 breakout board and DS3231 breakout board ~ 6.00; both are required for project. Sensor is located indoors, currently.

Experience with the WeMOS has been a very good; downloads are 15 times faster, WiFi connectivity is MUCH improved, reliability near 100% thanks to on-board watch dog timer (which, is enabled by default.), WiFi interference is a non factor --gone.

WiFi Client/Server Based --ESP8266

Domain Hosted, WiFi Client.Server Based --ESP8266

Check out the SPIFFS Files link; select a file and time the download!

Update: August 2, 2017

New update; RTC DS3231 replaced with NTP Time server and Timezones applied by “zoomx” of Arduino Forum.

William

Observations_SPIFFS.zip (8.83 KB)

NTP Observatons_SPPIFFS .zip (15.8 KB)

Update 4/25/2017

Function newDay was not correctly storing current week of Data. Made correction and tested; function newDay is correctly detecting Saturday and the time specified, and renaming file based on the month and date and creating a new LOG.TXT file for new week of Data.

Wemos D1 R2 Developement board continues to perform very well; much better reliability than what I experienced with the Adafruit CC3000 Shield.

William

Observations_SPIFFS.zip (8.83 KB)

Online since March 30, 2017; project has maintained availability and reliability. WEMOS D1 R2 Developement board continues to perform very well; much better reliability than what I experienced with the Adafruit CC3000 Shield with the Arduino Mega 2560. File system on the Wemos D1 is built-in to the Wifi module/processor. There is no SD card to deal with having to be reset.

WEMOS D1 development board has been a very good experience.

WiFi Client/Server Based --ESP8266

Domain Hosted, WiFi Client.Server Based --ESP8266

William

Observations_SPIFFS.zip (8.89 KB)

Added sending of “favicon.ico” updated 06/15/2017 @ 20:00 EST.

William

Observations_SPIFFS.zip (9.02 KB)

Wemos D1, Weather Observations project now with embedded Graphing of Temperature, Humidity, Barometric Pressure, and Dew Point. All previous feature are still included. Web link is provided to “Thingspeak.com” Channel; which provides the graphing, updated every fifteen minutes…

WiFi Client/Server Based --ESP8266

Domain Hosted, WiFi Client.Server Based --ESP8266

Some lines will require editing with your information. Lines requiring editing have been commented in the source code.

William

Observations_SPIFFS.zip (9.91 KB)

If you have space in flash you can use the WiFiManager library https://github.com/tzapu/WiFiManager thus avoiding to modify the source just to set the WiFi SSID and password. In this way the ESP8266 can use more than only one settings.

@ zoomx Thank you for the tip, appreciate your input.

Project updated; consolidated two web pages for graphs into one page with graphs configured in a two row by two column configuration.

Download, Observations_SPIFFS.ino has commented lines that require your editing to be useable.

William

Observations_SPIFFS.zip (10.2 KB)

Mybe I found a bug. This

if ((bme_temp <= 26.66) || (bme_humidity <= 40)) heat_index = bme_temp;

Must be changed in this

if ((bme_temp <= 26.66) || (bme_humidity <= 40)) heat_index = T;

because bme_temp is in Celsius and T is in Fahrenheit. I found it while changing the sketch to use Celsius.

Thank you zoomx. Does simplify and eliminate the conversion to Fahrenheit in the logtoSD and listen functions. Or do we want to leave it the way it was for readability?

WiFi Client/Server Based --ESP8266

Domain Hosted, WiFi Client.Server Based --ESP8266

William

The change suggested is useful only if you use Fahrenheit because when the if condition is met, bme_temp is assigned to heat_index but bme_temp is in Celsius. So you have to use T.

I will rewrite the changes I made using #IFDEF so it will be very simple to change from C to F using only one #define, then I will post here the sketch.

@ zoomx Like your coding...

Will be very good to have a single place to globally change from Fahrenheit to Celsius when changing temperature units. Thank you.

William

Maybe I found another bug

log.print((bme_pressure + 27.47), 2);  //Convert hPA to millibars

As far as I know 1mbar = 1hPa so you don't need any conversion.

Edit: found also this one

client.println(((bme_pressure) + 27.47), 1);   //Convert hPA to millbars

Ok, attached there is the modified sketch. TEST IT since I ave no ds3231 free.

I leaved the pressure difference still in hg inch because I need to recalculate the limits.

I am changing lib to RTClib. This way I can use a DS3231 or use a soft RTC (if it works?) and use NTP call to set the correct local time.

Observations_SPIFFS_CF.zip (10.1 KB)

@ zoomx

27.47 is a correction factor. When compared to a reference sensor on another project and nearby Weather U.underground Barometric Pressure reading in millibars, current sensor was reading low. Will add comment to about correction factor for my sensor. Over-sight in not commenting correction factor.

Function "listen" has same correction factor:

client.println(((bme_pressure) + 27.47), 1);   //Convert hPA to millibars

Will place the correction factors in the "getWeatherData" function like I did for "currentPressure," for consistency.

Will make the changes in next update.

William

Maybe better to use a const float (or a #define) at the beginning of the sketch so one can change it easily.

I have a BME280 and a BMP180 online but they differ of only 1mBar. The BME280 is attached to a nodeMCU and is this one that I will use with your sketch.

@ zoomx

Current BME280 on the project board in a China variant; maybe way out of tolerance. Have requested a replacement; hopefully better, from another source.

Tested “Observations_SPI_CF.zip” Works as you coded; see attached file."

I agree on the tolerance of the Bosch BME280. Unknown if China BME280 is the “real deal.”

William

Great! I don't have any reference barometer, maybe I can use the value provided by the nearby airport. My Bosh sensor came from China too.

software RTClib seems to work, I have to add NTP request.

Maybe you can change this

  //Write Data at 15 minute interval
    if ((((minute) == 0) ||
         ((minute) == 15) ||
         ((minute) == 30) ||
         ((minute) == 45))
        && ((second) == 0))
    {
      lastUpdate = dtStamp;   //store dtstamp for use on dynamic web page
      getWeatherData();
      updateDifference();  //Get Barometric Pressure difference
      logtoSD();   //Output to SD Card  --Log to SD on 15 minute interval.
      delay(10);  //Be sure there is enough SD write time
      speak();
      //lcdDisplay();      //   LCD 1602 Display function --used for 15 minute update
    }
    else
    {
      listen();  //Listen for web client
    }

with this

//Write Data at 15 minute interval  
if ((minute) % 15 == 0) {
    if (AcqDone == false) {
      lastUpdate = dtStamp;   //store dtstamp for use on dynamic web page
      getWeatherData();
      updateDifference();  //Get Barometric Pressure difference
      logtoSD();   //Output to SD Card  --Log to SD on 15 minute interval.
      delay(10);  //Be sure there is enough SD write time
      speak();

      AcqDone = true;
    }
  }
  else
  {
    AcqDone = false;
    listen();  //Listen for web client
  }

and add a

bool AcqDone = false;

at the beginning.

This way you can change the interval easily. The other advantage is that maybe if you get a GET request just few seconds before the acquisition you can skip the sending data to ThingSpeak since seconds will be not zero anymore. The AcqDone flag is used to avoid to send multiple data during the minute.

Update: Web site for project is down; maybe a few days.

Web site Down for maintenance

William

I tested successfully the software RTC with NTP but I am in search of a code to change automatically for DayLight Saving Time, USA and Europe.