Jump to content

NLCbanner2024.jpg.2478be509670e60c2d6efd04834b8b47.jpg

Weather Station Ideas


Gina

Recommended Posts

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";

333473842_Screenshotfrom2020-08-0311-47-37.png.0f234ef82568317fb945d669ceb962de.png

Link to comment
Share on other sites

Found the problem - me!!  Left some code out!!! :iamwithstupid:

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);
}

 

Edited by Gina
Link to comment
Share on other sites

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");
}

241214904_Screenshotfrom2020-08-0313-17-22.png.7ab3a8930bdeef7aa22ddd13618c8c11.png

Anyone know what I'm doing wrong, please?

Link to comment
Share on other sites

I imagine that Serial.println is overloaded such that when you do:

Serial.println(&timeinfo, "%A, %B %d %Y %H:%M:%S");

then it knows what a "struct tm" is and how to extract the items from it to print them out meaningfully.

I could well be wrong for the Arduino or ESP32, but I don't imagine you can just assign that information to a character pointer or array and have it work.  Were I doing this in C I'd probably look at using sprintf to put the data into a character string.  Something like:

sprintf ( DateTime, "%d/%d/%d %02d:%02d:%02d", timeinfo.tm_mday, timeinfo.tm_mon + 1,
  timeinfo.tm_year + 1900, timeinfo.tm_hour, timeinfo.tm_min, timeinfo.tm_sec );

in the "else" block should work, I think, as long as DateTime is declared as a character array of at least twenty characters.

That won't include pretty stuff like the actual name of the day or month, but it's hopefully a start.

James

Edited by JamesF
  • Thanks 1
Link to comment
Share on other sites

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.

Edited by Gina
Link to comment
Share on other sites

1 hour ago, Gina said:

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");}
  }

 

 

Anyone know what I'm doing wrong, please?

Are you missing a strftime() call?

Link to comment
Share on other sites

49 minutes ago, Gina said:

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!!

Assuming the "String" type is something similar to the C++ std::string, the only way I know of to do that in C++ is quite cumbersome.

James

Link to comment
Share on other sites

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.

1379106509_Screenshotfrom2020-08-0315-25-52.png.a6fb2e05e033b4a413742645db2f0ac0.png

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;
      }
  }

 

Link to comment
Share on other sites

1 minute ago, Gina said:

Don't know but it works when typed as String.

Yep - it's a Object type in the rtclib - I'd avoid it incase you do decide to use an RTC later as it will clash :)

(it's sort of the same as type time_t within time.h iirc)

  • Thanks 1
Link to comment
Share on other sites

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 😁

Edited by Gina
Link to comment
Share on other sites

re: Software interrupt:

I just use millis and a variable to store them in, then compare with a fixed time and if try, do what's needed and reset the variable to the current millis() 

It's basically the foundation of my wxstn code, eg:

// 5 Second task interval
 if ( (millis() - count5sec) >= 5000)
    {
    Tasks5s();        
    count5sec = millis();
    }

(dont forget to init count5sec in the setup() and also define it, eg: unsigned long count5sec; )

Using these I have a 5s, 60s, 30m and 60m 'interrupt' in which I do things - I use a function to wrap them up and put them in a tab in the Arduino IDE to make it a bit more neater, but that's just personal preference...  :)

 

 

Edited by jiberjaber
  • Thanks 1
Link to comment
Share on other sites

Added a 5 minute period and compared pressure.  Taking 0.1hPa difference to trigger Rising or Falling but don't know if 5m is long enough.  Maybe an hour would be better.

I would like an up arrow and a down arrow symbol or character rather than words - any ideas anyone?  Please?

Edited by Gina
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • 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.