ESP8266 --Internet Weather Datalogger and Dynamic Web Server

Message received, I have to check what happens if you don't get response from NTP or get an invalid response to avoid to set the RTC to a wrong time.
Looking at code, if no packet is received there is no update time. I have to add another check to the packet length, it must be 48.
In Wikipedia

I read that UDP packet has a checksum so I believe that the packet received should be correct. If packet is not correct it should be discarded and it's like not receiving any packet.
Maybe it can happen that the server is wrong or something happens. Long time ago it happened that GPS went wrong and an automatic GPS data collection didn't start because of this strange error.
If you vave frequent NTP errors it's better that you mantain the DS3231 RTC, as you can see it's only a line different.

Anyway Thingspeak uses it's time server and you can download data from it. In my opinion Thingspeak is great since you can build your own server using a PC or a little RaspberryPI so if they change idea (pachube, cosmic now Xively changed idea!) you can have your server.
Roberto

Thank you zoomx of Arduino.cc Forum for implementing NTP with Timezone for the project! Tested for two days; time intervals , logging and ThingSpeak are close to working correctly. Perhaps some small tweaking remains. Well done zoomx.

WiFi Client/Server Based --ESP8266

Domain Hosted, WiFi Client.Server Based --ESP8266

William

Thanks but I made only a small contriubution!
I thought to use NTP because I am lazy and I prefer a clock that regulate itself. Two time a year I have to regulate many clock when there is the switch to the Daylight Saving Time!

Two days of testing NTP with Timezones, I am convinced it is not redy for prime time. Not sure if it is a library or NTP, or a hardware issue. Server randomly losses track of NTP timing interval. I am reverting back to using a DS3231 RTC.

Wondering if it could be the ESP8266 going into a sleep mode and not getting NTP packets.

Returned to Real Time Clock version; attached file is current running the Wemos D1 server.

WiFi Client/Server Based --ESP8266

Domain Hosted, WiFi Client.Server Based --ESP8266

William

Observations_SPIFFS.zip (10 KB)

Testing. Data will be here

Since it is at work I cannot have a public access to the server. I will have it when I will move it to my home.
This is just a test for RTC and logging.

Good morning,

Re-visited zoomx's application of "NTP with Timezones and have a successful working sketch, "NTP_Observations_SPIFFS.ino"

Included in the attachment are the sketch, "LOG.TXT (portion actually logging during testing) and output of the Serial Monitor (during testing.)

Note: Time keeping is now accomplished with software using NTP time server.

William

NTP Observatons_SPPIFFS .zip (15.8 KB)

Server and sensor running "NTP_Observations_SPIFFS.ino" with No Real Time Clock!

Server has been online since 7/29/2017; all time keeping functions are handled by NTP time server.
Thank you "zoomx" for applying NTP and Timezones to project!

Check out thefour graphs from "ThingSpeak.com;" let mouse hover over data point on graph to reveal value and time of data entry:

WiFi Client/Server Based --ESP8266

Domain Hosted, WiFi Client.Server Based --ESP8266

William

zoomx:
I read that UDP packet has a checksum so I believe that the packet received should be correct. If packet is not correct it should be discarded and it's like not receiving any packet.

I am wrong and this assumption seems false.

In Serial output --modded file.tx

packet received, length=12
Seconds since Jan 1 1900 = 0
Unix time = 2085978496


Data written to log  02/07/2036 , 01:30:00

there was a packet that was long 12 bytes instead of 48.
So packet with lenght different from 48 must be discarded.

I apologize William, you wrote this already.

@ Zoomx

No need to apologize zoomx. Thank you for all your time, coding, and community participation.

Logging of Data now has priority after too many missed 15 -minute intervals.

This version has been tested over three days; much improved, over previous versions. All time keeping is NTP based; no Real Time Clock!

WiFi Client/Server Based --ESP8266

Domain Hosted, WiFi Client.Server Based --ESP8266

William

Serial Output --log priority --8-11-2017.txt (73.6 KB)

Testing --LOG.TXT (47.4 KB)

NTP_Observations_SPIFFS.zip (11.7 KB)

WiFi Client/Server Based --ESP8266

Domain Hosted, WiFi Client.Server Based --ESP8266
3 Minute Video of project

William

NTP_Observations_SPIFFS.zip (11.7 KB)

Current version has been online since 08/08/2017 @ 23:31 EST with little interruption. Developement board is a RobotDyn Wifi D1 R2 from Source of board

Project web page

Attached "NTP_Observations_SPIFFS.zip" is the 08/08/2017 @ 23:31 EST version.

NTP_Observations_SPIFFS.zip (11.7 KB)

October 2, 2017 Update:

"NTP_Observations_SPIFFS.ino" 08/08/2017 @ 23:31 EST continues to remain online. Last version change date was 08/08/2017 @ 23:31 EST.

Current version has performed above and beyond my expectations. Very good reliability. Fast downloads. Fast Watchdog resets on the rare occurrence when one happens.

William

NTP_Observations_SPIFFS.zip (11.7 KB)

Improved Wake time in response to page request.

Improvements to simplify editing page links.

List of line numbers requiring editing.

WiFi Client/Server Based --ESP8266

Domain Hosted, WiFi Client.Server Based --ESP8266

NTP_Observations_SPIFFS.zip (12.1 KB)

Update 11/23/2017

Added code for occasion when no NTP Packet is received, to request a new Packet to be sent.

Added SERVER.TXT file for date and time of Server starts.

Previous version of project code is: "Nov_23_2017__NTP_Observations_SPIFFS.ino."

Installed version of project code is: "Dec_9_2017__NTP_Observations_SPIFFS.ino."

William

Nov_23_2017__NTP_Observations_SPIFFS.zip (12.2 KB)

Dec_9_2017__NTP_Observations_SPIFFS.ino (50.2 KB)

Some how my device was blocked at my Gateway.

Apologies to anyone that tried to connect and was unable to connect.

No changes to software since the last update.

WiFi Client/Server Based --ESP8266

Domain Hosted, WiFi Client.Server Based --ESP8266

William

New feature: Hosted website gets updates every 15 minutes. Very little additional code to project by using ESP8266HTTPClient library.

Website is on ".000webhostapp.com" free, educational Domain:

Domain Hosted, WiFi Client.Server Based --ESP8266

Stephan Borsay's article on Hackster.io was the inspiration for this additional feature.

William

NTP_Web_Interface.zip (13.8 KB)

Thanks for the update William,
I will read the links you provided!

Completed design of Website for project. Driving element of web sit is the following code:

<?php

/*
  ESP8266: send data to your Domain 

  Uses POST command to send BME280 data to a designated website
  The circuit:
  * BME280
  * Post to Domain 
  
  Original version of this code by Stephan Borsay
  Modified with HTML and CSS by techno500 for use with BME280 along with Arduino/ESP8266 sketch:  
  "NTP_Web_Interface.ino."
  
*/

date_default_timezone_set("America/Indianapolis");
$TimeStamp = date("Y-m-d   h:i:sa");

   if( $_REQUEST["fahren"] ||  $_REQUEST["heat"] ||  $_REQUEST["hum"] ||  $_REQUEST["dewpt"]
       ||  $_REQUEST["cpressure"] ||  $_REQUEST["bars"] ) 
   {
      echo " The Temperature is: ". $_REQUEST['fahren']. "F. 
";
      echo " The Heat Index is: ". $_REQUEST['heat']. " Heat Index 
";
      echo " The Temperature is: ". $_REQUEST['hum']. " hum 
";
      echo " The Dew Point is: ". $_REQUEST['dewpt']. " Dew Point
";
      echo " The Barometric Pressure is: ". $_REQUEST['cpressure']. " in. HG. 
";
      echo " The Barometric Pressure is: ". $_REQUEST['bars']. " millibars 
";
      echo " The Altitude is: 824 Feet 
";
 
   }
  
 
$var1 = $_REQUEST['fahren']; 
$var2 = $_REQUEST['heat'];
$var3 = $_REQUEST['hum'];
$var4 = $_REQUEST['dewpt'];
$var5 = $_REQUEST['cpressure'];
$var6 = $_REQUEST['bars'];
//$var7 = $_REQUEST['altit'];

$WriteMyRequest=

"<html>".
"<head>".
"<body>".
"<style>". 
"body { background: #561C0E no-repeat fixed center;}".
"a,h2,h3 {color: #ffffff;}". 
"font-weight: bold;}".
"</style>". 
"<title>Observations</title>".
"<h2>".
"Observations".
"<p>Treyburn Lakes
".
"Indianapolis, IN
".
"46239</p></h2>
".
"<p><h3>Last update:   " . $TimeStamp . "</p>".
"<p> The Temperature is : "   . $var1 . " F. </p>".
"<p>And the Heat Index is : " . $var2 . " F. </p>".
"<p>And the Humidity : "       . $var3 . " % </p>".
"<p>And The Dew Point is : "   . $var4 . " F. </p>".
"<p>And The Barometric Pressure is : "  . $var5 . " in. HG. </p>".
"<p>And The Barometric Pressure is : "  . $var6 . " mb</p>".
"<p>And The Altitude is : 824 Feet </p>

".  // Altitude as read by GPS for project location
"<a href='https://pathToAbout.php'>About</h3></a>".
"</head>".
"</body>".
"</html>";

file_put_contents('display.html', $WriteMyRequest);

?>

This is the PHP code that creates the "Observations" menu option of the website.

Domain Hosted, WiFi Client.Server Based --ESP8266

PHP code above receives the POST from the "NTP_Web_Interface.ino" sketch. POST is developed with use of the "ESP8266HTTPClient" library. Project is unique in the fact that it does not use a Real Time Clock. Every 15 minutes; PHP code rewrites the "Observations" HTML page. Only the "ESP8266" development board and the BME280 are required making for a real low cost project! All timing requirements are provided by using Network Time Protocol and a time server to derive the time and date used in the sketch.

Over the time I have been developing this project; have had allot of help from members of the various forums. Without their help this project would have been impossible. To those that helped and the owners of the various forums; thank you, your help most appreciated!

Attached is the sketch and the php code.

William

Add screen capture

NTP_Web_Interface.zip (14 KB)

Nice project Techno!!!

That BME280 sensor is really nice! I noticed on your observations page the temp is off the scale:

Treyburn Lakes
Indianapolis, IN, US

Last update: 2018-02-06 05:30:02pm

The Temperature is : -230.62 F.

And the Heat Index is : -228.32 F.

And the Humidity : 100.00 %

And The Dew Point is : -230.62 F.

And The Barometric Pressure is : 35.13 in. HG.

And The Barometric Pressure is : 1189.80 mb

And The Altitude is : 824 Feet

@rxpc Thank you for bringing this to my attention; caused by faulty Dupont jumper on the BME280 sensor. I need to get this project off of breadboard and on to a printed circuit board. Have started "Eagle" class on "Udemy.com" for creating printed circuit boards. First project in "Eagle" will be to create a PCB for "NTP_Web_Interface.ino" project!

William