Go Down

Topic: NTP --ESP8266 Time-Synced, Data Logging and Web Server (Read 703 times) previous topic - next topic

Techno500

Apr 24, 2018, 04:03 pm Last Edit: May 05, 2018, 12:20 pm by Techno500 Reason: Updated current project file 05/05/2018.
04/24/2018  

"NTP_Time_synced_Web_Interface.ino" has obtained faster performance using "ESP8266 sys/time.h" and "ESP8266 time.h" libraries suggested by schufti of the ESP8266 Forum.   Schufti provided example code for using the two libraries.   Removed some code related to earlier libraries and three functions related to NTP, UDP, and and the old Time keeping code.  Everything is complete:   time related functions, web pages, file listing, file downloading, and graphing!  ESP8266 server website is averaging less than one second response times from client connect, serving the webpage, and client closes!  Response time can be monitored with Serial Monitor from time stamping.  

More than a Data Logger; also allows fast, remote downloading of files, stored onboard in the SPIFFS memory.  Files are listed and selectable for download.  Both ESP8266, local server and hosted, web server receives uploaded data from the same sketch.  Commented out are two features; a LCD display function and an experimental, audio beep function to alert for a predetermined difference in a 15-minute interval of barometric pressure.  Have read of past references of serve weather associated with a sudden drop in barometric pressure.

RobotDyn WiFi D1 board that is online has been used for development of project coding; therefore, there may be gaps in the data logs!  The 15-minute interval has been "spot on" every 15 minutes; awesome, since project has no RTC module!   All time related requirements are provided by NTP time server; even has a second time server coded!

ESP8266 hosted, website and Domain, hosted website One sketch dynamically, updating data to both websites.  

Restrictions of free, domain hosting service is why there is no file browser or file downloading on the domain hosted website..  Graphing of four, weather parameters is available on both websites.

Thank you, "Arduino,cc Forum," "ESP8266 Community Forum," and "Adafruit Forum" for all the help received with this Open-Source project!  

05/05/2018 updated with current project file.

William

Techno500

05/07/2018

Video discussing "Arduino IDE" multiple tabbed compiling.  

Technique allows better management of complex, long project code with less scrolling when re-writing , adding, or changing code.

Unzip attached file to a folder; in this folder double click "NTP_Time-synced_Web_Interface.ino" to open the "Arduino IDE" with tabs.  First tab will be always be includes, declarations, globals, setup, and loop.  Rest of the tabs are functions.

William

Techno500

#2
May 27, 2018, 02:29 pm Last Edit: Jun 22, 2018, 01:59 am by Techno500 Reason: Add Serial Monitor output.
Current Features "NTP_Time-Synced_Web_Interface.ino".

1. NTP Server; used for 15 minute time interval, date-time stamping, and dayofweek (every 6th
day, "LOG.TXT" file gets renamed to keep file size manageable. Every Saturday "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. Server files are listed as web links; clicking link prompts for "Open with/Save as."
"FAVICON.ICO", and "ACCESS.TXT" 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." Methods
other than "GET," produce "405" message and exits current request.

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.

10. Tempature, Humidity, Barometric Pressure, and Dew Point have four embedded "ThinkSpeak.com"
graphs on one web page. Graphs are created from Iframes provided by "ThingSpeak.com"

11. ThingSpeak.com is used for graphing four weather parameters. iFrames are obtained from
ThingSpeak..com.

12. Free, "000webhost powered by HOSTINGER" is used for second website.

Two websites,one sketch: "NTP_Time-Synced_Web_Interface.ino."

ESP8266 Server--Desktop server (port forwarded) --this one has a file browser, selected file can be downloaded.

Domain Hosted website  --no file browser due to hosted domain server restrictions (free hosting service). Hosted server "sleeps" one hour every 24
hours.
-----------------------------------------------------------------------------------
Note this is a project is in development; maybe offline or log files may be affected.
Server is online 24/7; except during periods of testing.

Server is a "RobotDyn WiFi D1 R2" with 32 MiB Flash Memory. Development Board, purchased from
"RobotDyn.com" and GY-BME280 breakout board, purchased from "Ebay.com" ; both are required for
project. Sensor is located indoors, currently.

Developement board is Arduino friendly; can be programed using the Arduino IDE.
Under $15.00 with shipping, is the project cost for Development Board --$4.29 and one,
GY-BME280 breakout board, sensor for Barometric Pressure, Humidity, and Temperature --cost $4.77.

Short, Serial Monitor Output:

=~=~=~=~=~=~=~=~=~=~=~= PuTTY log 2018.05.22 00:27:35 =~=~=~=~=~=~=~

Client connected:  Tue , 05/22/2018 , 00:25:05 EDT
Client IP:  10.0.0.146
Processing request
Action: GET
Path: /Weather
Client closed:  Tue , 05/22/2018 , 00:25:06 EDT


Client connected:  Tue , 05/22/2018 , 00:25:10 EDT
Client IP:  10.0.0.146
Processing request
Action: GET
Path: /SdBrowse
Client closed:  Tue , 05/22/2018 , 00:25:11 EDT


Client connected:  Tue , 05/22/2018 , 00:25:14 EDT
Client IP:  10.0.0.146
Processing request
Action: GET
Path: /LOG.TXT
File:  /LOG.TXT
Client closed:  Tue , 05/22/2018 , 00:25:25 EDT


Client connected:  Tue , 05/22/2018 , 00:25:57 EDT
Client IP:  10.0.0.146
Processing request
Action: GET
Path: /README.TXT
File:  /README.TXT
Client closed:  Tue , 05/22/2018 , 00:25:58 EDT


Client connected:  Tue , 05/22/2018 , 00:26:27 EDT
Client IP:  10.0.0.146
Processing request
Action: GET
Path: /Graphs
Client closed:  Tue , 05/22/2018 , 00:26:28 EDT


Client connected:  Tue , 05/22/2018 , 00:26:38 EDT
Client IP:  10.0.0.146
Processing request
Action: GET
Path: /Graphs
Client closed:  Tue , 05/22/2018 , 00:26:39 EDT


Client connected:  Tue , 05/22/2018 , 00:26:42 EDT
Client IP:  10.0.0.146
Processing request
Action: GET
Path: /Graphs
Client closed:  Tue , 05/22/2018 , 00:26:43 EDT


Attached is the current tabbed, Arduino IDE version of the project

Techno500

Due to circumstances beyond my control; project has been offline since 05/29/2018.  Online operation was restored 06/06/2018 at 01:30 EDT.  ISP changed from Gateway -based firmware to Gateway cloud -based firmware; there were issues with port forward not working.  Gateway was swapped out for a new one in the troubleshoot process and a new public IP was attached nullifying previous links to the ESP8266 Server web site.

I apologize for any inconvenience experienced by this change.

Active project websites:

ESP8266 Server website --new link

Domain, hosted website --unchanged

William

Techno500

Experienced sensor failure; awaiting replacement sensor.  Both websites are affected; updated data is invalid!

Affected websites: 

ESP8266 Server

Domain, hosted website


William

Techno500

#5
Jul 10, 2018, 06:04 am Last Edit: Jul 10, 2018, 06:08 am by Techno500 Reason: Correct text.
Update 7/9/2018

Added WiFiStart call to restart WiFi if there is a WiFi disconnect; to listen function.  New function wifiStart is used in setup and listen functions.

Code added to log WiFi reconnects and date/time stamp each occurrence; to listen function:

Code: [Select]
if(WiFi.status() != WL_CONNECTED)
  {
      wifiStart();

      delay(1000 * 10);   //wait 10 seconds before writing

     //Open a "WIFI.TXT" for appended writing.   Client access ip address logged.
     File logFile = SPIFFS.open("/WIFI.TXT", "a");

     if (!logFile)
     {
          Serial.println("File failed to open");
     }
     else
     {
          logFile.print("Reconnected WiFi:  ");
          logFile.println(dtStamp);
     }

  
  }


wifiStart function:

Code: [Select]
void wifiStart()
{  
  
  WiFi.mode(WIFI_STA);

  Serial.println("");
  Serial.print("MAC: ");
  Serial.println(WiFi.macAddress());

  // We start by connecting to a WiFi network
  Serial.print("Connecting to ");
  Serial.println(ssid);
  

  //setting the addresses  
  IPAddress ip(10,0,0,13);
  IPAddress gateway(10,0,0,1);
  IPAddress subnet(255,255,255,0);
  IPAddress dns(75,75,75,75);

  WiFi.begin(ssid, password);

  WiFi.config(ip, gateway, subnet, dns);
  
  while (WiFi.status() != WL_CONNECTED)
  {
    delay(100);
    Serial.print(".");
  }

  WiFi.waitForConnectResult();

  Serial.printf("Connection result: %d\n", WiFi.waitForConnectResult());

}


Over rode "Auto Modem Sleep" default sleep mode; power no issue, using AC to DC adapter.

Code: [Select]
wifi_set_sleep_type(NONE_SLEEP_T);

Default "Auto Modem Sleep" I believe is too slow "waking," causing Browser request to occasionally timeout.   Continuing to observe this solution.

William



Techno500

July 15, 2018

Moved block of code responsible for every 15 minute data updates, logging, sending data to ThingSpeak and the Hosted, domain website moved from loop to inside of listen function. Listen function has priority except for 10 seconds at 14 min 50 sec., 30 min. 50 sec., 45 min. 50 sec., and 59 min 50 sec.; then the moved code block has priority. Result of this move has proved to be better responses to Client requests and improved reliability!

ESP8266 Server web site

Hosted, Domain web site


William

Go Up