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.
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.
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.
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:
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.
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
"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.
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.
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!
@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!