-
Posts
45,326 -
Joined
-
Last visited
-
Days Won
120
Content Type
Profiles
Forums
Gallery
Events
Blogs
Posts posted by Gina
-
-
Don't know but it works when typed as String.
-
To save keep going in and out to upload and test, I've arranged the code to work with the Serial Monitor but not needing the Serial Monitor.
This is the result :- First line is from the Serial.println, the second shows the String DateTime.
This is the code :-
int year, month, day, hour, minute;
void showLocalTime() { struct tm timeinfo; if(!getLocalTime(&timeinfo)){ DateTime = "Failed to obtain time"; return;} else { year = timeinfo.tm_year + 1900; month = timeinfo.tm_mon + 1; day = timeinfo.tm_mday; hour = timeinfo.tm_hour; minute = timeinfo.tm_min; DateTime = "Date & Time is "; DateTime += year; DateTime += "-"; if (month < 10) {DateTime += "0";} DateTime += month; DateTime += "-"; if (day < 10) {DateTime += "0";} DateTime += day; DateTime += " "; if (hour < 10) {DateTime += "0";} DateTime += hour; DateTime += ":"; if (minute < 10) {DateTime += "0";} DateTime += minute; } }
-
Think I've worked it out.
-
Hmm... that uses an array of chars rather than a String type. DateTime is declared as a String type. This is not a simple as first thought!!
I don't need any of the date/time in words - something like "2020-08-03 14:24" would be fine. Or maybe "14:24 03/08/2020" I use the first format in filenames and data logging.
-
Still not right! Seems there's something wrong with this code:-
void showLocalTime() { struct tm timeinfo; if(!getLocalTime(&timeinfo)){ DateTime = "Failed to obtain time"; return;} else {DateTime = (&timeinfo, "%A, %B %d %Y %H:%M:%S");} }
And yet this works with the Serial Monitor :-
void printLocalTime() { struct tm timeinfo; if(!getLocalTime(&timeinfo)){ Serial.println("Failed to obtain time"); return; } Serial.println(&timeinfo, "%A, %B %d %Y %H:%M:%S"); }
Anyone know what I'm doing wrong, please?
-
If lenses count as well as telescoped then I have oooooooooooooooooooooooooodles 🤣
-
3
-
-
Found the problem - me!! Left some code out!!!
void loop() { server.handleClient(); showLocalTime(); // <------------------------- Left this line out!! temperatureThen = temperatureNow; humidityThen = humidityNow; pressureThen = pressureNow; ReadBME(); if (pressureNow > (pressureThen + 0.1)) {pressureDir = "Rising";} else if (pressureNow < (pressureThen - 0.1)) {pressureDir = "Falling";} else {pressureDir = "No Change";} scopeH = dht.readHumidity(); scopeT = dht.readTemperature(); delay(2000); }
-
Keeping WiFi open fixed the EN problem but I'm still not getting the Date/Time - string is empty.
Added HTML code for paragraph and title of the data in case the HTML was causing the problem and which I should have done anyway but it wasn't that. Now I can see where the DateTime string should be but it isn't there.
ptr +="<h1>Gina's ESP32 Weather Station</h1>\n"; ptr +="<p>Date/Time: "; ptr +=DateTime; ptr +="</p>"; ptr +="<h1>Outside Conditions</h1>\n";
-
Went out and pressed EN a couple of times and it now connects but it's not showing the date/time.
-
The sketch compiles and after upload works with the Serial Display but needed EN twice. When installed in the obsy the WiFi wouldn't connect. I have WiFi disconnecting after NTP then reconnecting - I think this may be the problem and don't think it's needed.
Here's the code with SSID and PW removed.
#include <DHT.h> #include <WiFi.h> #include <WebServer.h> #include <Wire.h> #include <Adafruit_Sensor.h> #include <Adafruit_BME280.h> #include "DHT.h" #include "time.h" const char* ntpServer = "pool.ntp.org"; const long gmtOffset_sec = 0; const int daylightOffset_sec = 3600; #define SEALEVELPRESSURE_HPA (1013.25) #define DHTPIN 4 // Digital pin connected to the DHT sensor #define DHTTYPE DHT22 // DHT 22 (AM2302), AM2321 void printLocalTime() { struct tm timeinfo; if(!getLocalTime(&timeinfo)){ Serial.println("Failed to obtain time"); return; } Serial.println(&timeinfo, "%A, %B %d %Y %H:%M:%S"); } Adafruit_BME280 bme; float temperature, humidity, pressure, altitude, temperatureNow, humidityNow, pressureNow, temperatureThen, humidityThen, pressureThen, scopeT, scopeH; String pressureDir, DateTime; /*Put your SSID & Password*/ const char* ssid = "--------"; // Enter SSID here const char* password = "--------"; //Enter Password here void showLocalTime() { struct tm timeinfo; if(!getLocalTime(&timeinfo)){ Serial.println("Failed to obtain time"); return; } DateTime = (&timeinfo, "%A, %B %d %Y %H:%M:%S"); } WebServer server(80); DHT dht(DHTPIN, DHTTYPE); void setup() { Serial.begin(115200); delay(100); //connect to WiFi for NTP Serial.printf("Connecting to %s ", ssid); WiFi.begin(ssid, password); while (WiFi.status() != WL_CONNECTED) { delay(500); Serial.print("."); } Serial.println(" CONNECTED"); //init and get the time configTime(gmtOffset_sec, daylightOffset_sec, ntpServer); printLocalTime(); //disconnect WiFi as it's no longer needed WiFi.disconnect(true); WiFi.mode(WIFI_OFF); // End of NTP setup bme.begin(0x76); Serial.println("Connecting to "); Serial.println(ssid); //connect to your local wi-fi network WiFi.begin(ssid, password); //check wi-fi is connected to wi-fi network while (WiFi.status() != WL_CONNECTED) { delay(1000); Serial.print("."); } Serial.println(""); Serial.println("WiFi connected..!"); Serial.print("Got IP: "); Serial.println(WiFi.localIP()); server.on("/", handle_OnConnect); server.onNotFound(handle_NotFound); server.begin(); Serial.println("HTTP server started"); dht.begin(); } void loop() { server.handleClient(); temperatureThen = temperatureNow; humidityThen = humidityNow; pressureThen = pressureNow; ReadBME(); if (pressureNow > (pressureThen + 0.1)) {pressureDir = "Rising";} else if (pressureNow < (pressureThen - 0.1)) {pressureDir = "Falling";} else {pressureDir = "No Change";} scopeH = dht.readHumidity(); scopeT = dht.readTemperature(); delay(2000); } void ReadBME() { temperatureNow = bme.readTemperature(); humidityNow = bme.readHumidity(); pressureNow = bme.readPressure() / 100.0F; } void handle_OnConnect() { temperature = temperatureNow; humidity = humidityNow; pressure = pressureNow; server.send(200, "text/html", SendHTML(temperature,humidity,pressure,altitude)); } void handle_NotFound(){ server.send(404, "text/plain", "Not found"); } String SendHTML(float temperature,float humidity,float pressure,float altitude){ String ptr = "<!DOCTYPE html> <html>\n"; ptr +="<head><meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0, user-scalable=no\">\n"; ptr +="<title>Gina's ESP32 Weather Station</title>\n"; ptr +="<style>html { font-family: Helvetica; display: inline-block; margin: 0px auto; text-align: center;}\n"; ptr +="body{margin-top: 50px;} h1 {color: #444444;margin: 50px auto 30px;}\n"; ptr +="p {font-size: 24px;color: #444444;margin-bottom: 10px;}\n"; ptr +="</style>\n"; ptr +="</head>\n"; ptr +="<body>\n"; ptr +="<div id=\"webpage\">\n"; ptr +="<h1>Gina's ESP32 Weather Station</h1>\n"; ptr +=DateTime; ptr +="<h1>Outside Conditions</h1>\n"; ptr +="<p>Temperature: "; ptr +=temperature; ptr +="°C</p>"; ptr +="<p>Humidity: "; ptr +=humidity; ptr +="%</p>"; ptr +="<p>Pressure: "; ptr +=pressure; ptr +="hPa</p>"; ptr +="<p>Trend: "; ptr +=pressureDir; // ptr +="m</p>"; ptr +="<h1>Scope Room</h1>\n"; ptr +="<p>Temperature: "; ptr +=scopeT; ptr +="°C</p>"; ptr +="<p>Humidity: "; ptr +=scopeH; ptr +="%</p>"; ptr +="</div>\n"; ptr +="</body>\n"; ptr +="</html>\n"; return ptr; }
-
The example works 😀 Now to incorporate it into my sketch.
-
1
-
-
Going to try this :- Getting Date & Time From NTP Server With ESP32
If it does what I want it will save using a hardware RTC.
-
I was planning to use the RTC for two things, getting date and time and displaying it and to interrupt the ESP32 every minute (or 5) to read sensors and store the results from which pressure trends could be derived and maybe provide a log. For the wind sensors there would be more processing - computing mean and gust wind speed and average wind direction. I don't know how this could be done by reading NTP every few hours. I guess the current date and time could be computed from the elapsed loop time interval count but this seems a complicated method.
-
Actually, the water surface can be pretty hard unless travelling very slowly.
-
I don't know about NTP - I'll look for information.
I have a BME280 outside in Stevenson screen with a 250mm ribbon cable from the ESP32 inside and the DHT22 inside (scope room). I don't need two pressure readings. Are you saying you would recommend using two BME280s for better reliability? I take it then that there's no problem distinguishing which is which.
-
-
Working. I missed the % sign off the Scope Room humidity - doh...
-
1
-
-
Added the DHT22 code to the current sketch for the outside sensors to read conditions in the scope room. Seem to be using up program storage space rather fast and this is only a small sketch!! I'm rather worried that I may not have room for the more complicated time coded data processing with the RTC mocule. Time will tell.
QuoteSketch uses 732250 bytes (55%) of program storage space. Maximum is 1310720 bytes.
Global variables use 40352 bytes (12%) of dynamic memory, leaving 287328 bytes for local variables. Maximum is 327680 bytes. -
-
Found another web server sketch example HERE. Don't know if it's any better than Wim's sketch. I'll stick with what I know works for now.
-
DHT22 and the RTC modules have arrived but not doing much today - need a rest.
-
I'm still wondering if magnet and reed switches is the best for sensing wind direction. I'm having a problem getting the magnet to give the right response from the reed switches. viz. to get a suitable overlap and not get 3 reed switches on at the same time. For the Consensus Averaging to work properly I think the overlap representing 8 of the 16 directions needs to be about the same as the "one on" directions. I'm going do do some more thinking about optical sensing.
-
When I was looking for other things I came across several DHT22s but now I want one they've all gone into hiding!! Ordered another, due to arrive tomorrow. Of course, I don't know if the ones lying about would be any good - they're donkey's years old!
-
Set up a buck converter and connected to the ASC main supply for the moment, until I get the 5v power distribution done.
-
1
-
Weather Station Ideas
in DIY Astronomer
Posted
Changed DateTime string to something simpler and better looking IMO.
Now to try it in the obsy.