Jump to content

Gina

Beyond the Event Horizon
  • Posts

    45,326
  • Joined

  • Last visited

  • Days Won

    120

Everything posted by Gina

  1. Getting there - in fits and starts 🤣
  2. Working now. Time for a cuppa I think...
  3. Groan - lost that showLocalTime(); line again so it isn't updating the time. Added it now.
  4. Replaced all instances of "DateTime" with "myDT".
  5. Next to get what amounts to a software interrupt working - getting it to build a log of the sensor readings complete with time code and check pressure over a longer period. I guess the current readings of temperature and humidity are all I need. I'll add dewpoint calculations though. Getting near the stage where I want to upload over WiFi too. Not that the exercise of popping in and out to the obsy isn't good for me 😁
  6. It works! 😀 Could do with being a bit bigger though - not a problem.
  7. Changed DateTime string to something simpler and better looking IMO. Now to try it in the obsy.
  8. Don't know but it works when typed as String.
  9. 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; } }
  10. Think I've worked it out.
  11. 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.
  12. 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?
  13. If lenses count as well as telescoped then I have oooooooooooooooooooooooooodles 🤣
  14. 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); }
  15. 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";
  16. Went out and pressed EN a couple of times and it now connects but it's not showing the date/time.
  17. 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 +="&deg;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 +="&deg;C</p>"; ptr +="<p>Humidity: "; ptr +=scopeH; ptr +="%</p>"; ptr +="</div>\n"; ptr +="</body>\n"; ptr +="</html>\n"; return ptr; }
  18. The example works 😀 Now to incorporate it into my sketch.
  19. 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.
  20. 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.
  21. Actually, the water surface can be pretty hard unless travelling very slowly.
  22. 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.
  23. ESP32 and DS3231 RTC example
  24. Working. I missed the % sign off the Scope Room humidity - doh...
  25. 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.
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue. By using this site, you agree to our Terms of Use.