Go Down

Topic: ESP8266 --Internet Weather Datalogger and Dynamic Web Server (Read 28171 times) previous topic - next topic


Mar 30, 2017, 08:49 pm Last Edit: Aug 02, 2017, 09:12 pm by Techno500 Reason: Add attachment
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.)


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.

Temporary project web site

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.



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.



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.

Project web page --Weather Data observations



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



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..

Wemos D1, Weather Observations project

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



If you have space in flash you can use the WiFiManager library
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.


Jun 26, 2017, 12:11 pm Last Edit: Jun 26, 2017, 12:17 pm by Techno500 Reason: Removed attempt to post inline image image
@ 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.



Mybe I found a bug. This
Code: [Select]
if ((bme_temp <= 26.66) || (bme_humidity <= 40)) heat_index = bme_temp;
Must be changed in this
Code: [Select]
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? 

Project web page.  Now with Graphed Weather Observations



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.



Maybe I found another bug
Code: [Select]
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
Code: [Select]
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.


@ 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:

Code: [Select]
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.



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.

Go Up