Jump to content

Banner.jpg.b83b14cd4142fe10848741bb2a14c66b.jpg

Weather Station Ideas


Gina

Recommended Posts

Here is the speed and direction code.  The sketch compiles fine but can't be sure I've got the maths right.

void do3sJobs (){
  windSpeed = ++PulseCount;  //  Accumulate mean speed
  if (PulseCount > windGust) {windGust = PulseCount;};  // Get max speed for gust
  PulseCount = 0;
  ++bin[readDirection()]; // increment appropriate bin
}
void do1mJobs(){
  // wind speed mean and gust ring arrays and report
  meanArray[ringIndex] = windSpeed; // put windSpeed into new array index
  gustArray[ringIndex] = windGust;  // put windGust into new array index
//  windSpeed /=20;  // leave this for later
  for (int i = 0; i < 10; i++) {
    meanSpeed += meanArray[i];  // add all windSpeeds 
    if (gustArray[i] > gustSpeed){gustSpeed = gustArray[i];}; // find maximum gust speed
  }
  meanSpeed /=200;  // the first sum was over 20 values and then the second over 10 values
  sendSpeedMessages();
  windGust = 0;
  ringIndex = (ringIndex+1)%10; // move ringIndex on to next location in the ring array
}
void do3mJobs(){
  // wind direction calculations and report
  int sum[16];
  int S=0,I=0,W=0;
  bin[16] = bin[0];
  bin[17] = bin[1];
  bin[18] = bin[2];
  bin[19] = bin[3];
  for (int i = 0; i < 16; i++) {
    sum[i] = bin[i] + bin[i+1] + bin[i+2] + bin[i+3] + bin[i+4];
    // find the index with the highest sum and save sum and index
    if (sum[i] > S){S = sum[i]; I = i;}; 
  }
  W = (bin[I+1] + 2 * bin[I+2] + 3 * bin[I+3] + 4 * bin[I+4]) * 45 / S;
  sendDirectionMessage((I * 45 + W)%720 /2);
}
void loop() {
  if (!client.connected()) {
    reconnect();
  }
  client.loop();

  long now = millis();
  if(now - last3s > P3s) {do3sJobs; last3s = now;}
  if(now - last1m > P1m) {do1mJobs; last1m = now;}
  if(now - last3m > P3m) {do3mJobs; last3m = now;}
}

May be able to test it tomorrow.  That's it for tonight.

Link to comment
Share on other sites

Surprise, surprise - it doesn't work!!  Guess I'm going to have to put debug messages in to see what's happening.

Have it set up on the living room table.

MQTT Explorer is not showing any of the 5 wind messages.

Edited by Gina
Link to comment
Share on other sites

First test - sending the instantaneous wind direct every 3 seconds.

void do3sJobs (){
  sendDirectionMessage(readDirection()); // send instantaneous direction

Later...  NOT working - nothing!!!

Have to try something simpler!

Edited by Gina
Link to comment
Share on other sites

Wrong

void loop() {
  if (!client.connected()) {
    reconnect();
  }
  client.loop();

  long now = millis();
  if(now - last3s > P3s) {do3sJobs; last3s = now;}
  if(now - last1m > P1m) {do1mJobs; last1m = now;}
  if(now - last3m > P3m) {do3mJobs; last3m = now;}
}

Right - missed out the () in the doxxJobs calls.  Doh!!

void loop() {
  if (!client.connected()) {
    reconnect();
  }
  client.loop();

  long now = millis();
  if(now - last3s > P3s) {do3sJobs(); last3s = now;}
  if(now - last1m > P1m) {do1mJobs(); last1m = now;}
  if(now - last3m > P3m) {do3mJobs(); last3m = now;}
}

 

Link to comment
Share on other sites

Actually, none of it is working correctly!!  I've turned the fan off so the speed is zero.  The direction is now something like 180° different and this hasn't shown up.  I can see this is going to take a lot of debugging.  And it's not as if I can put breakpoints in the code and debug it in the normal way.  I shall have send messages to the MQTT network at strategic points in the calculations.

Link to comment
Share on other sites

Checking mean and gust speeds at the 1m point.

void do3sJobs (){
  windSpeed = ++PulseCount;  //  Accumulate mean speed
  if (PulseCount > windGust) {windGust = PulseCount;};  // Get max speed for gust
  PulseCount = 0;
  ++bin[readDirection()]; // increment appropriate bin
}
void do1mJobs(){
  // debugging - send current mean and gust speeds
  meanSpeed = windSpeed;  gustSpeed = windGust;
  sendSpeedMessages();

The results are wrong.  All speeds are showing 1 rather than 0 with no fan running.  Gust speed looks reasonable looking at the anemometer revs though 1 higher than it should be.  The Mean speed should show around 20 times the real value as the value is the sum of 20 counts and hasn't been divided.

It points to this line

  windSpeed = ++PulseCount;  //  Accumulate mean speed

From Arduino reference

Example Code

x = 2;
y = ++x;  // x now contains 3, y contains 3
y = x++;  // x contains 4, but y still contains 3

I can see what's wrong.

Got the wrong operator, should be

x += y; // equivalent to the expression x = x + y;

Corrected

  windSpeed += PulseCount;  //  Accumulate mean speed

 

Link to comment
Share on other sites

About to run this code

void do3sJobs (){
//  sendDirectionMessage(readDirection()); // send instantaneous direction
  windSpeed += PulseCount;  //  Accumulate mean speed
  if (PulseCount > windGust) {windGust = PulseCount;};  // Get max speed for gust
  PulseCount = 0;
  ++bin[readDirection()]; // increment appropriate bin
}
void do1mJobs(){
  // debugging - send current mean and gust speeds
  meanSpeed = windSpeed/20;  gustSpeed = windGust;
  windSpeed = 0;
  sendSpeedMessages();

 

Link to comment
Share on other sites

I think the wind direction may be correct.  The instantaneous direction is varying between WSW and W - 11 & 12 points or 247.5° and 270°.  The mean direction is reading 261° which agrees (it is between 247.5 and 270).

The wind mean speed is a different matter!!  It isn't working!   This is the averaging in the ring array.  OTOH the Gust speed does seem to be working.

1147838686_Screenshotfrom2020-08-2917-18-15.png.dd8b2097c5f72d11d2d43a77e4ca6174.png

Link to comment
Share on other sites

For debugging I have added a number display in the Wind tab.  Currently showing the ringIndex and that is correct - starting at 0, increasing up to 9 and then back to 0.  The mean and gust displays are increasing with every change in index though so I have another error (or two).  Clearly not zeroing the values before forming sum and maximum.

Edited by Gina
Link to comment
Share on other sites

Corrected that error and the gust speed is reading correctly but the mean speed is still increasing.  So still an error!!  Somewhere in this section of code.

void do1mJobs(){
  // wind speed mean and gust ring arrays and report
  meanArray[ringIndex] = windSpeed; // put windSpeed into new array index
  gustArray[ringIndex] = windGust;  // put windGust into new array index
//  windSpeed /=13;  // /20 and *1.5 -- leave this for later
  meanSpeed = 0; gustSpeed = 0;
  for (int i = 0; i < 10; i++) {
    meanSpeed += meanArray[i];  // add all windSpeeds 
    if (gustArray[i] > gustSpeed){gustSpeed = gustArray[i];}; // find maximum gust speed
  }
  meanSpeed /=133;  // the first sum was over 20 values and then the second over 10 values
  gustSpeed *= 1.5;  // Speed count over 3s rather than 4.5s
  sendSpeedMessages();  // HOLD temporarily for debugging
  windGust = 0;
  sendNumberMessage(ringIndex);  //  send ringIndex for debugging
  ringIndex = (ringIndex+1)%10; // move ringIndex on to next location in the ring array
}

 

Link to comment
Share on other sites

I'll just confirm that all compass points for the wind vane give sensible results then look to installing the wind sensors and mast.

Later...  Should have guessed it was too good to be true.  OK yes the speed processing seems fine but the direction isn't!  I had posted the sketch but now removed it as it isn't right.

Switched the fan off and let the anemometer slow down and stop then moved the vane to the 0 position.  I have given the Consensus Averaging time to work and for the wind speed to decay from the ring arrays.  This is the result.

819904904_Screenshotfrom2020-08-2921-32-24.png.70bae79fde267f5935fe5a7eefcd4ae4.png

Yes!!  It's a long way off right!!  So now I have more debugging to do!  Though not tonight I don't think.

Edited by Gina
Link to comment
Share on other sites

Seems as if the mean direction is bearing no relationship to the actual wind vane direction.  The instantaneous direction is correct so the encoder is working fine - it's the Consensus Averaging calculations that are wrong.  Somewhere in all that code!!

1793581683_Screenshotfrom2020-08-2921-54-54.png.c2088c8019ae9ef814e35cd261928122.png

Edited by Gina
Link to comment
Share on other sites

Found the problem.  Forgot to empty the bins after counting the hits ready for the next lot.  Added this line and it seems to be working correctly.

  for (int i = 0; i < 16; i++) {bin[i] = 0;};

505325677_Screenshotfrom2020-08-3009-12-36.png.7e2b4c725d89cdd815bd3d88616ec29b.png

Link to comment
Share on other sites

Next I need to adjust the direction to suit the orientation of the wind instruments.  This could be done when reading the encoder or when displaying the results.  I guess the former is easiest.

Think this should do it.

    dirn = (dirn - 1) %16; // correct encoder for North

688800911_Screenshotfrom2020-08-3010-42-51.png.8d56b2e535f0207b9348d29a2c35a126.png

Edited by Gina
Link to comment
Share on other sites

Having thoroughly tested the wind sensors indoors and found everything seemingly correct I've installed them outside on the observatory and powered up.  BUT things are NOT right!!

1208073658_Screenshotfrom2020-08-3018-27-55.png.7b94f1e4b19d682c77199eb673cf6e40.png

Link to comment
Share on other sites

The wind is very light and variable with anemometer rotating at around 1rps or less so not every 3s period getting a pulse.  This could be the reason, I guess, though how the instantaneous direction could be over 15 when there's a modulo 16, I don't know!

Sometimes the display seems right.

655545608_Screenshotfrom2020-08-3018-45-00.png.ae0f268f514877f48ac80403248f7970.png

Edited by Gina
Link to comment
Share on other sites

The anemometer is very sensitive and turns smoothly at well under 1 mph so the mean speed could be displayed in tenths but I guess there's really no point (no pun intended).

The Beaufort scale for wind force is a good indicator but really I would like more points.

Edited by Gina
Link to comment
Share on other sites

I'm copying a post here as I don't know the best place for it.

1 minute ago, Gina said:

I'm getting a strange problem with the wind speed.  Whether this is anything to do with MQTT or just the sketch in the wind ESP32 I don't know.  Until today the speed calculations have been fine but now the mean speed keeps resetting then building up again to the correct value.  These are enlargements of the mean speed history in the dashboard and the MQTT Explorer.   I'm wondering if the stronger breeze today could be anything to do with it. 

Unfortunately, to upload a new sketch to the ESP32 in the wind client means taking the wind sensor mast and unit down and connecting the ESP32 to the Mint box USB.  I seem to remember reading something about uploading a new Arduino sketch over WiFi but can't find it now.

1793347282_Screenshotfrom2020-09-0218-58-34.png.914361683966b2b9ce5245748f918fec.png  377560496_Screenshotfrom2020-09-0218-59-26.png.030fb1b9913a6c30b97b9da267f09107.png

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.