Jump to content

SkySurveyBanner.jpg.21855908fce40597655603b6c9af720d.jpg

tekkydave

Members
  • Posts

    1,798
  • Joined

  • Last visited

Posts posted by tekkydave

  1. 19 minutes ago, Gina said:

    I'm not using a database yet.  Also, I'm not familiar with Java and using C++ (Arduion IDE).  I like a compiled language.

    I think I shall keep direction and speed data and functions separate as this aids debugging.

    The class I posted is part of the aggregation functions in my system. I have a separate logger that just puts raw values into the db with minimal processing for speed. The aggregation functions read from the db and write back things like wind speed & direction concensus that depend on values over a set period. Also I have hourly, daily, monthly, yearly aggregation of temperature, rainfall and wind speed going on in the background. My database is at 1.5Gb already with data going back to 2016. Daily backups happen automatically :)

     

    • Like 1
  2. If you read Java this is my class

    package piweather4jv2;
    
    import java.util.ArrayList;
    import java.util.Date;
    import java.util.Iterator;
    import java.util.List;
    
    // Class constructed using instructions at: http://www.beals5.com/wx/faqs.htm
    
    public class WindConcensus {
        
        public void readWindConcensus(Database db, int dbSensorId, FileManager fm) {
            List<Double> windDirectionResults;
            List<Double> windSpeedResults;
            List<Double> windGustResults;
            double windSpeed = 0;
            double windGust = 0;
            int[] bin = new int[20];
            boolean validConcensus = true;
            Date endDate = new Date();    // endDate of readings = now
            
            windDirectionResults = db.getRecentReadings(1, endDate, 900L, "NONE");       // Get all the values from last 15mins
            windSpeedResults     = db.getRecentReadings(16, endDate, 900L, "AVG");       // Get the Average of the values in lat 15mins
            windGustResults      = db.getRecentReadings(16, endDate, 120L, "MAX");       // Get the Maximum of the values in last 2 mins
            
            if ((windDirectionResults.size() >= 1) && (windSpeedResults.size() == 1) && (windGustResults.size() == 1)) {
                
                // Put windDirectionResults in bins
                Iterator dirIterator = windDirectionResults.iterator();
                while (dirIterator.hasNext()) {
                    double degrees = (double)dirIterator.next();
                    int sector = ((int) ((degrees + 11.25)/22.5))%16;
                    bin[sector] += 1;
                    //System.out.println("WindConcensus: " + String.valueOf(degrees) + " in sector " + String.valueOf(sector));  
                }
                // bins 16 to 19 are same as bins 0 to 3
                bin[16] = bin[0];
                bin[17] = bin[1];
                bin[18] = bin[2];
                bin[19] = bin[3];
    
                // Process bin outcome
                int I = 0;
                int S = 0;
                int Smax = 0;
                for (int i = 0; i < 16; i++) {
                    S = bin[i] + bin[i+1] + bin[i+2] + bin[i+3] + bin[i+4];
                    if (S > Smax) {
                        I = i;
                        Smax = S;
                    }
                    //System.out.println("bin " + i + " = " + bin[i] + " , sum = " + S);
                }
                //System.out.println("I = " + I + ", S = " + Smax);
                
                double W = ( bin[I+1] + (2 * bin[I+2]) + (3 * bin[I+3]) + (4 * bin[I+4]) ) * 45.0D / Smax;
                double D = (((I * 45.0D) + W) % 720)/2;
                
                //System.out.println("W = " + W + " , D = " + D);
    
                // get windSpeedResults value
                windSpeed = (double)windSpeedResults.get(0);
                //System.out.println("WindConcensus: Average Speed = " + String.valueOf(windSpeed));  
    
                // get windGustResults value
                windGust = (double)windGustResults.get(0);
                //System.out.println("WindConcensus: Gust Speed = " + String.valueOf(windGust));  
                
                // Check Validity of Wind Direction and Speed
                if ((D < 0.0D) || (D >= 360.0D) || (windSpeed < 0.0D) || (windSpeed >= 100.0D) || (windGust < 0.0D) || (windGust >= 100.0D)) {
                    validConcensus = false;
                }
                
                Reading3 windDataReading = new Reading3(new Date(), D, windSpeed, windGust, validConcensus);  
    
                windDataReading.print("Wind Direction Concensus (" + windDirectionResults.size() + " readings)","Wind Speed","Wind Gust");
    
                if (windDataReading.isValid()) {
                    windDataReading.saveDB(db, dbSensorId);
                    windDataReading.saveFile(fm, dbSensorId);
                }
                
            } else {
                System.out.println("WindConcensus: No results to process.");
            }
            
        }
    }

     

    • Thanks 1
  3. The very first 1-wire wind-vane I had contained 8 reed switches. It selectively shorted out resistors in a chain to give a 4-bit analogue reading. This was read by a 4-bit 1-wire AtoD chip and the software then used the values to calculate 1 of 16 compass directions. I'll see if I can find the original circuit.

    Edit: found it! 

    This is  pdf so d/l then open up

    CalculatingWindSpeedAndDirection.PDF

  4. Have you considered storing your readings in a database. Then you can split the system into 2 parts;

    1. A part based on the ESP32 that simply takes readings & logs raw data to the database 

    2. A front-end based on a pi or pc that displays the data. This can be more powerful for the processing required. Having the data in a db also allows you to keep a history of your readings. I now have readings going back to 2016 in my weather db.

  5. 10 hours ago, jiberjaber said:

    My experience with the ESP8266 was the web service and dealing with interrupts for the wind and rain didn't mix.  Might be OK with the '32 but this is why I went for MQTT

    I think MQTT is definitely worth considering. All you need is a server/broker (RPi?) which is easy to set up. Then you can send messages (data etc) between clients easily. The ESP32 should have an MQTT library and there will be one for whatever language you go with on the indoor side. There are also free sites on the web that you can use as your broker - see CloudMQTT. I have used it just for testing so you can play with the client ends without needing to build the broker.

    So it might look like this:

                         (WiFi)                       (WiFi/Eth)
    Weather Station <------------------> Broker <------------------> Client (RPi or PC?)
     (ESP32) |                      (RPi or CloudMQTT)                      |
             |                                                              |
          Sensors                                                         Dials

    Some instruction on building a pi based broker: here

    I would probably go the MQTT route if I started my WS from scratch. I have an RPi in my WS outside as all my sensors are 1-wire and some were quite expensive (rain gauge & wind vane/gauge). I use oww server to make the 1-wire devices connected to the RPi in the WS appear as local devices on the indoor RPi. Then the rest is coded in Java (backend logging to MySQL db) and a PHP/javascript web front-end also on the indoor Pi.

     

    • Like 1
    • Thanks 1
  6. 3 minutes ago, Gina said:

    Yes.  I thought the ESP8266 was just a WiFi adapter hadn't thought of it as a microprocessor as well.  I will want one digital and 4 analogue inputs or maybe 9 digital inputs depending on how I implement the wind vane sensor.  OTOH that encoder chip only needs 3 data lines (SPI or I2C forget which).

    ESP8266 only has one analogue input - you need the ESP32 I think :)

    The ESP chips can be programmed via the Arduino IDE as if they were arduinos with the addition of a few extensions.

     

    • Thanks 1
  7. The ESP32 seems endowed enough for a weather station:

    • 18 Analog-to-Digital Converter (ADC) channels
    • 10 Capacitive sensing GPIOs
    • 3 UART interfaces
    • 3 SPI interfaces
    • 2 I2C interfaces
    • 16 PWM output channels
    • 2 Digital-to-Analog Converters (DAC)
    • 2 I2S interfaces
    • Thanks 1
  8. 1 minute ago, Gina said:

    Thanks Dave.  Interesting but a) I don't want to spend that much money and b) prefer to make my own.

    Appreciate that but I thought those sensor chips look interesting to have a play with 😮

     

    • Like 1
  9. I have had one of these inspeed eVane wind vanes for many years now. Claims to use a Hall effect sensor but I'm not sure how they get the analogue output as a proportion of the input voltage. It works great with 1-wire AtoD to give a very accurate reading to less than 1 degree resolution. It's a sealed unit so I'm in the dark about how it works internally.

    • Like 1
×
×
  • 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.