Jump to content

Banner.jpg.b83b14cd4142fe10848741bb2a14c66b.jpg

Weather Station Ideas


Gina

Recommended Posts

Now have the BME 280 in the Stevenson screen and the latter mounted on the north wall of the obsy.  A 4 way ribbon cable goes into the scope room and into the ESP32 board which is mounted on the wall with a 3D printed bracket.  The twin cable has arrived but I haven't yet run it round the obsy so I have the ESP32 running off the bench PSU.  It's all working.  The display wants some tidying up but that's minor.

974694367_Screenshotfrom2020-08-0112-54-28.png.a85f52cb5b42484b9a9cf2a48b08beff.png

Edited by Gina
  • Like 2
Link to comment
Share on other sites

21 minutes ago, Gina said:

Anyone know how long the connection between DHT22 and ESP32 can be?  I guess it depends on the type of cable.

Between 12 and 30 m depending on which google result you use.  I've got one on a long lead of about 2m which I keep meaning to cut down now it's mounted to the side of the scope :) 

I never found them reliable in the weatherstation but the one that's been on the dew heater has just worked since day 1 so no conclusion there!

  • Thanks 1
Link to comment
Share on other sites

Been thinking about measuring the temperature and humidity in the scope room and initially thought of measuring it at the pier top - nearest imaging rig.  OTOH if the roof is open I doubt there would be much difference between the conditions at the pier head and outside in the Stevenson screen.  With the roof closed it may not matter where these conditions are measured - such as at mount height but near the north wall.  So I'm wondering if there is any point in measuring at the pier head with the extra messing about.

Link to comment
Share on other sites

1 minute ago, Gina said:

Been thinking about measuring the temperature and humidity in the scope room and initially thought of measuring it at the pier top - nearest imaging rig.  OTOH if the roof is open I doubt there would be much difference between the conditions at the pier head and outside in the Stevenson screen.  With the roof closed it may not matter where these conditions are measured - such as at mount height but near the north wall.  So I'm wondering if there is any point in measuring at the pier head with the extra messing about.

If it's not a pain to do you can add it and if it gives no value, then remove later.

  • Like 1
Link to comment
Share on other sites

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!

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Edited by Gina
Link to comment
Share on other sites

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.

Quote

Sketch 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.

 

Link to comment
Share on other sites

2 hours ago, Gina said:

I think I found with my RTC I also needed to run a software clock as there isn't an actual RTC exposed in the ESP (their version of an RTC is just a timer), this may have changed over time as the ESP libs improved within Arduino.

I sync the RTC with NTP on every boot which has an aggressive start then backs off to only sync every 'few' hours (you don't always get a NTP reply on the first attempt, few = log time but I forget how long lol )

I use the Adafruit RTCLib.h with a DS3231 which I think is the same as the example you've got.

  • Like 1
Link to comment
Share on other sites

Hi Gina, progressing I see. 

What's the purpose of the RTC over NTP ? Are you putting the device to deep sleep between measurements ?

If you have the bme280 working why use the distinctly clunky and unreliable dht22 ?

 

  • Like 1
Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

 

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.