示例#1
0
        /// <inheritdoc/>
        public override ISensorSample TakeReading(WeatherObservation observation)
        {
            this.LogTakeReadingStart();
            var sensorResult = new SensorSample(this.SensorName);

            var result = this.sensor.Read();

            if (result.Humidity.HasValue && result.Pressure.HasValue && result.Temperature.HasValue)
            {
                var pressure           = result.Pressure.Value;
                var temperature        = new Temperature(result.Temperature.Value.DegreesCelsius + this.calibrationOffset, UnitsNet.Units.TemperatureUnit.DegreeCelsius);
                var rawTemperature     = result.Temperature.Value;
                var humidity           = result.Humidity.Value;
                var actualAltitude     = new Length(this.altitudeInMeters, UnitsNet.Units.LengthUnit.Meter);
                var calculatedAltitude = WeatherHelper.CalculateAltitude(pressure, WeatherHelper.MeanSeaLevel, rawTemperature);

                double absHumidity             = WeatherHelper.CalculateAbsoluteHumidity(temperature, humidity).GramsPerCubicMeter;
                double dewPoint                = WeatherHelper.CalculateDewPoint(temperature, humidity).DegreesCelsius;
                double heatIndex               = WeatherHelper.CalculateHeatIndex(temperature, humidity).DegreesCelsius;
                double vapourPressure          = WeatherHelper.CalculateActualVaporPressure(temperature, humidity).Hectopascals;
                double barometricPressure      = WeatherHelper.CalculateBarometricPressure(pressure, temperature, actualAltitude, humidity).Hectopascals;
                double vapourPressureOverIce   = WeatherHelper.CalculateSaturatedVaporPressureOverIce(temperature).Hectopascals;
                double vapourPressureOverWater = WeatherHelper.CalculateSaturatedVaporPressureOverWater(temperature).Hectopascals;
                double seaLevelPressure        = WeatherHelper.CalculateSeaLevelPressure(pressure, actualAltitude, temperature).Hectopascals;

                sensorResult.AddFinalObservation(temperature.DegreesCelsius, "TEMPERATURE", ObservationUnits.DegreesCelcius);
                sensorResult.AddFinalObservation(pressure.Hectopascals, "PRESSURE", ObservationUnits.HectoPascal);
                sensorResult.AddFinalObservation(barometricPressure, "BAROMETRIC PRESSURE", ObservationUnits.HectoPascal);
                sensorResult.AddFinalObservation(seaLevelPressure, "SEA LEVEL PRESSURE", ObservationUnits.HectoPascal);
                sensorResult.AddFinalObservation(vapourPressureOverIce, "OVER ICE PRESSURE", ObservationUnits.HectoPascal);
                sensorResult.AddFinalObservation(vapourPressureOverWater, "OVER WATER PRESSURE", ObservationUnits.HectoPascal);
                sensorResult.AddFinalObservation(humidity.Percent, "RELATIVE HUMIDITY", ObservationUnits.Percentage);
                sensorResult.AddFinalObservation(absHumidity, "ABSOLUTE HUMIDITY", ObservationUnits.GramsPerCubicMeter);
                sensorResult.AddFinalObservation(vapourPressure, "VAPOUR PRESSURE", ObservationUnits.HectoPascal);
                sensorResult.AddFinalObservation(calculatedAltitude.Meters, "CALCULATED ALTITUDE", ObservationUnits.Meters);
                sensorResult.AddFinalObservation(actualAltitude.Meters, "ACTUAL ALTITUDE", ObservationUnits.Meters);
                sensorResult.AddFinalObservation(heatIndex, "HEAT INDEX", ObservationUnits.DegreesCelcius);
                sensorResult.AddFinalObservation(dewPoint, "DEW POINT", ObservationUnits.DegreesCelcius);

                observation.Temperature1       = temperature.DegreesCelsius;
                observation.Pressure           = pressure.Hectopascals;
                observation.BarometricPressure = barometricPressure;
                observation.SealevelPressure   = seaLevelPressure;
                observation.OverIcePressure    = vapourPressureOverIce;
                observation.OverWaterPressure  = vapourPressureOverWater;
                observation.RelativeHumidity   = humidity.Percent;
                observation.AbsoluteHumidity   = absHumidity;
                observation.ActualAltitude     = actualAltitude.Meters;
                observation.CalculatedAltitude = calculatedAltitude.Meters;
                observation.HeatIndex          = heatIndex;
                observation.DewPoint           = dewPoint;
            }

            this.LogTakeReadingComplete();
            return(sensorResult);
        }
        public static void Run()
        {
            // set this to the current sea level pressure in the area for correct altitude readings
            var defaultSeaLevelPressure = WeatherHelper.MeanSeaLevel;

            using SenseHatPressureAndTemperature pt = new ();
            while (true)
            {
                var tempValue = pt.Temperature;
                var preValue  = pt.Pressure;
                var altValue  = WeatherHelper.CalculateAltitude(preValue, defaultSeaLevelPressure, tempValue);

                Console.WriteLine($"Temperature: {tempValue.DegreesCelsius:0.#}\u00B0C");
                Console.WriteLine($"Pressure: {preValue.Hectopascals:0.##}hPa");
                Console.WriteLine($"Altitude: {altValue:0.##}m");
                Thread.Sleep(1000);
            }
        }
示例#3
0
        public static void Main(string[] args)
        {
            // set this to the current sea level pressure in the area for correct altitude readings
            var defaultSeaLevelPressure = WeatherHelper.MeanSeaLevel;

            using (var th = new Lps25h(CreateI2cDevice()))
            {
                while (true)
                {
                    var tempValue = th.Temperature;
                    var preValue  = th.Pressure;
                    var altValue  = WeatherHelper.CalculateAltitude(preValue, defaultSeaLevelPressure, tempValue);

                    Console.WriteLine($"Temperature: {tempValue.DegreesCelsius:0.#}\u00B0C");
                    Console.WriteLine($"Pressure: {preValue.Hectopascals:0.##}hPa");
                    Console.WriteLine($"Altitude: {altValue:0.##}m");
                    Thread.Sleep(1000);
                }
            }
        }
示例#4
0
        GetBmp280TemperatureAndPressure()
        {
            // bus id on the raspberry pi 3 and 4
            const int busId = 1;
            // set this to the current sea level pressure in the area for correct altitude readings
            var defaultSeaLevelPressure = WeatherHelper.MeanSeaLevel;

            I2cConnectionSettings i2CSettings = new(busId, Bmx280Base.DefaultI2cAddress);
            var i2CDevice = I2cDevice.Create(i2CSettings);

            using var i2CBmp280 = new Bmp280(i2CDevice)
                  {
                      TemperatureSampling = Sampling.HighResolution,
                      PressureSampling    = Sampling.HighResolution
                  };

            // Perform a synchronous measurement
            var readResult = await i2CBmp280.ReadAsync();

            var temperature = readResult.Temperature;

            Console.WriteLine($"Temperature: {Green($"{readResult.Temperature?.DegreesFahrenheit:0.#}\u00B0F")}");

            var pressure = readResult.Pressure;

            Console.WriteLine($"Pressure: {Green($"{readResult.Pressure?.Millibars:0.##}mb")}");

            if (temperature == null || pressure == null)
            {
                return(readResult.Temperature?.DegreesFahrenheit, readResult.Pressure?.Millibars);
            }

            var altitude =
                WeatherHelper.CalculateAltitude(pressure.Value, defaultSeaLevelPressure, temperature.Value);

            Console.WriteLine($"Calculated Altitude: {Green($"{altitude.Feet:0,000}")}");

            return(readResult.Temperature?.DegreesFahrenheit, readResult.Pressure?.Millibars);
        }
示例#5
0
 /// <summary>
 ///  Calculates the altitude in meters from the specified sea-level pressure.
 /// </summary>
 /// <param name="seaLevelPressure">
 ///  Sea-level pressure
 /// </param>
 /// <returns>
 ///  Height above sea level
 /// </returns>
 public Length ReadAltitude(Pressure seaLevelPressure)
 {
     return(WeatherHelper.CalculateAltitude(ReadPressure(), seaLevelPressure, ReadTemperature()));
 }
示例#6
0
        /// <summary>
        /// Main entry point for the program.
        /// </summary>
        public static void Main()
        {
            Console.WriteLine("Hello BME680!");

            // The I2C bus ID on the Raspberry Pi 3.
            const int busId = 1;
            // set this to the current sea level pressure in the area for correct altitude readings
            var defaultSeaLevelPressure = WeatherHelper.MeanSeaLevel;

            var i2cSettings = new I2cConnectionSettings(busId, Bme680.DefaultI2cAddress);
            var i2cDevice   = I2cDevice.Create(i2cSettings);

            using (var bme680 = new Bme680(i2cDevice))
            {
                while (true)
                {
                    // get the time a measurement will take with the current settings
                    var measurementDuration = bme680.GetMeasurementDuration(bme680.HeaterProfile);

                    // 10 consecutive measurement with default settings
                    for (var i = 0; i < 10; i++)
                    {
                        // This instructs the sensor to take a measurement.
                        bme680.SetPowerMode(Bme680PowerMode.Forced);

                        // wait while measurement is being taken
                        Thread.Sleep(measurementDuration);

                        // Print out the measured data
                        bme680.TryReadTemperature(out var tempValue);
                        bme680.TryReadPressure(out var preValue);
                        bme680.TryReadHumidity(out var humValue);
                        bme680.TryReadGasResistance(out var gasResistance);
                        var altValue = WeatherHelper.CalculateAltitude(preValue, defaultSeaLevelPressure, tempValue);

                        Console.WriteLine($"Gas resistance: {gasResistance:0.##}Ohm");
                        Console.WriteLine($"Temperature: {tempValue.DegreesCelsius:0.#}\u00B0C");
                        Console.WriteLine($"Pressure: {preValue.Hectopascals:0.##}hPa");
                        Console.WriteLine($"Altitude: {altValue:0.##}m");
                        Console.WriteLine($"Relative humidity: {humValue:0.#}%");

                        // WeatherHelper supports more calculations, such as saturated vapor pressure, actual vapor pressure and absolute humidity.
                        Console.WriteLine($"Heat index: {WeatherHelper.CalculateHeatIndex(tempValue, humValue).DegreesCelsius:0.#}\u00B0C");
                        Console.WriteLine($"Dew point: {WeatherHelper.CalculateDewPoint(tempValue, humValue).DegreesCelsius:0.#}\u00B0C");

                        // when measuring the gas resistance on each cycle it is important to wait a certain interval
                        // because a heating plate is activated which will heat up the sensor without sleep, this can
                        // falsify all readings coming from the sensor
                        Thread.Sleep(1000);
                    }

                    // change the settings
                    bme680.TemperatureSampling = Sampling.HighResolution;
                    bme680.HumiditySampling    = Sampling.UltraHighResolution;
                    bme680.PressureSampling    = Sampling.Skipped;

                    bme680.ConfigureHeatingProfile(Bme680HeaterProfile.Profile2, 280, 80, 24);
                    bme680.HeaterProfile = Bme680HeaterProfile.Profile2;

                    measurementDuration = bme680.GetMeasurementDuration(bme680.HeaterProfile);

                    // 10 consecutive measurements with custom settings
                    for (int i = 0; i < 10; i++)
                    {
                        // perform the measurement
                        bme680.SetPowerMode(Bme680PowerMode.Forced);
                        Thread.Sleep(measurementDuration);

                        // Print out the measured data
                        bme680.TryReadTemperature(out var tempValue);
                        bme680.TryReadPressure(out var preValue);
                        bme680.TryReadHumidity(out var humValue);
                        bme680.TryReadGasResistance(out var gasResistance);
                        var altValue = WeatherHelper.CalculateAltitude(preValue, defaultSeaLevelPressure, tempValue);

                        Console.WriteLine($"Gas resistance: {gasResistance:0.##}Ohm");
                        Console.WriteLine($"Temperature: {tempValue.DegreesCelsius:0.#}\u00B0C");
                        Console.WriteLine($"Pressure: {preValue.Hectopascals:0.##}hPa");
                        Console.WriteLine($"Altitude: {altValue:0.##}m");
                        Console.WriteLine($"Relative humidity: {humValue:0.#}%");

                        // WeatherHelper supports more calculations, such as saturated vapor pressure, actual vapor pressure and absolute humidity.
                        Console.WriteLine($"Heat index: {WeatherHelper.CalculateHeatIndex(tempValue, humValue).DegreesCelsius:0.#}\u00B0C");
                        Console.WriteLine($"Dew point: {WeatherHelper.CalculateDewPoint(tempValue, humValue).DegreesCelsius:0.#}\u00B0C");
                        Thread.Sleep(1000);
                    }

                    // reset will change settings back to default
                    bme680.Reset();
                }
            }
        }
示例#7
0
文件: WeatherTests.cs 项目: z-eh/iot
        public void AltitudeIsCalculatedCorrectlyAtMslpAndDefaultTemp(double expected, double hpa)
        {
            var altitude = WeatherHelper.CalculateAltitude(Pressure.FromHectopascals(hpa));

            Assert.Equal(expected, Math.Round(altitude.Meters, 2));
        }
示例#8
0
文件: WeatherTests.cs 项目: z-eh/iot
        public void AltitudeIsCalculatedCorrectly(double expected, double hpa, double seaLevelHpa, double celsius)
        {
            var altitude = WeatherHelper.CalculateAltitude(Pressure.FromHectopascals(hpa), Pressure.FromHectopascals(seaLevelHpa), Temperature.FromDegreesCelsius(celsius));

            Assert.Equal(expected, Math.Round(altitude.Meters, 2));
        }
示例#9
0
        /// <inheritdoc/>
        public override void Initialize()
        {
            this.LogStartInitialization();
            this.i2cDevice = this.Controller.GetI2CConnection(this.DeviceId);
            this.sensor    = new Bme280(this.i2cDevice)
            {
                TemperatureSampling = Sampling.LowPower,
                PressureSampling    = Sampling.UltraHighResolution,
                HumiditySampling    = Sampling.Standard,
            };

            var readResult = this.sensor.ReadStatus();

            this.LogMessage($"BME280 status {readResult}");
            var result = this.sensor.Read();

            if (result.Humidity.HasValue && result.Pressure.HasValue && result.Temperature.HasValue)
            {
                var pressure    = result.Pressure.Value;
                var temperature = new Temperature(result.Temperature.Value.DegreesCelsius - this.calibrationOffset, UnitsNet.Units.TemperatureUnit.DegreeCelsius);
                var humidity    = result.Humidity.Value;

                var actualAltitude     = new Length(this.altitudeInMeters, UnitsNet.Units.LengthUnit.Meter);
                var calculatedAltitude = WeatherHelper.CalculateAltitude(pressure, WeatherHelper.MeanSeaLevel, temperature);

                double absHumidity             = WeatherHelper.CalculateAbsoluteHumidity(temperature, humidity).GramsPerCubicMeter;
                double dewPoint                = WeatherHelper.CalculateDewPoint(temperature, humidity).DegreesCelsius;
                double heatIndex               = WeatherHelper.CalculateHeatIndex(temperature, humidity).DegreesCelsius;
                double vapourPressure          = WeatherHelper.CalculateActualVaporPressure(temperature, humidity).Hectopascals;
                double barometricPressure      = WeatherHelper.CalculateBarometricPressure(pressure, temperature, actualAltitude, humidity).Hectopascals;
                double vapourPressureOverIce   = WeatherHelper.CalculateSaturatedVaporPressureOverIce(temperature).Hectopascals;
                double vapourPressureOverWater = WeatherHelper.CalculateSaturatedVaporPressureOverWater(temperature).Hectopascals;
                double seaLevelPressure        = WeatherHelper.CalculateSeaLevelPressure(pressure, actualAltitude, temperature).Hectopascals;

                this.LogMessage($"Temperature: {temperature.DegreesCelsius:0.#}\u00B0C");
                this.LogMessage($"Pressure: {pressure.Hectopascals:0.##}hPa");
                this.LogMessage($"Barometric Pressure: {barometricPressure:0.##}hPa");
                this.LogMessage($"Sea level Pressure: {seaLevelPressure:0.##}hPa");
                this.LogMessage($"Over ice Pressure: {vapourPressureOverIce:0.##}hPa");
                this.LogMessage($"Over water Pressure: {vapourPressureOverWater:0.##}hPa");
                this.LogMessage($"Relative humidity: {humidity.Percent:0.#}%");
                this.LogMessage($"Absolute humidity: {absHumidity:0.#}g/m3");
                this.LogMessage($"Vapour pressure: {vapourPressure:0.#}hPa");
                this.LogMessage($"Calculate altitude: {calculatedAltitude.Meters:0.##}m");
                this.LogMessage($"Actual altitude: {actualAltitude.Meters:0.##}m");
                this.LogMessage($"Heat index: {heatIndex:0.#}\u00B0C");
                this.LogMessage($"Dew point: {dewPoint:0.#}\u00B0C");

                Thread.Sleep(1000);

                // set sane defaults
                this.sensor.TemperatureSampling = Sampling.UltraLowPower;
                this.sensor.PressureSampling    = Sampling.UltraLowPower;
                this.sensor.HumiditySampling    = Sampling.UltraLowPower;
                this.sensor.FilterMode          = Bmx280FilteringMode.Off;
                this.sensor.SetPowerMode(Iot.Device.Bmxx80.PowerMode.Bmx280PowerMode.Forced);

                this.IsInitialized = true;
                this.LogStartSuccess();
            }

            this.LogError("Couldn't read from BME280");
        }
示例#10
0
        /// <summary>
        /// Entry point for example program
        /// </summary>
        /// <param name="args">Command line arguments</param>
        public static void StartBmp(string[] args)
        {
            Console.WriteLine("Hello Bmp280!");

            Length stationHeight = Length.FromMeters(640); // Elevation of the sensor

            // bus id on the raspberry pi 3 and 4
            const int busId = 1;
            // set this to the current sea level pressure in the area for correct altitude readings
            var defaultSeaLevelPressure = WeatherHelper.MeanSeaLevel;

            var i2cSettings = new I2cConnectionSettings(busId, Bmp280.DefaultI2cAddress);
            var i2cDevice   = I2cDevice.Create(i2cSettings);
            var i2CBmp280   = new Bmp280(i2cDevice);

            using (i2CBmp280)
            {
                while (true)
                {
                    // set higher sampling
                    i2CBmp280.TemperatureSampling = Sampling.LowPower;
                    i2CBmp280.PressureSampling    = Sampling.UltraHighResolution;

                    // set mode forced so device sleeps after read
                    i2CBmp280.SetPowerMode(Bmx280PowerMode.Forced);

                    // wait for measurement to be performed
                    var measurementTime = i2CBmp280.GetMeasurementDuration();
                    Thread.Sleep(measurementTime);

                    // read values
                    i2CBmp280.TryReadTemperature(out var tempValue);
                    Console.WriteLine($"Temperature: {tempValue.DegreesCelsius} \u00B0C");
                    i2CBmp280.TryReadPressure(out var preValue);
                    Console.WriteLine($"Pressure: {preValue.Hectopascals} hPa");

                    // Note that if you already have the pressure value and the temperature, you could also calculate altitude by using
                    // double altValue = WeatherHelper.CalculateAltitude(preValue, defaultSeaLevelPressure, tempValue) which would be more performant.
                    i2CBmp280.TryReadAltitude(out var altValue);

                    Console.WriteLine($"Calculated Altitude: {altValue} m");
                    Thread.Sleep(1000);

                    // change sampling rate
                    i2CBmp280.TemperatureSampling = Sampling.UltraHighResolution;
                    i2CBmp280.PressureSampling    = Sampling.UltraLowPower;
                    i2CBmp280.FilterMode          = Bmx280FilteringMode.X4;

                    // set mode forced and read again
                    i2CBmp280.SetPowerMode(Bmx280PowerMode.Forced);

                    // wait for measurement to be performed
                    measurementTime = i2CBmp280.GetMeasurementDuration();
                    Thread.Sleep(measurementTime);

                    // read values
                    i2CBmp280.TryReadTemperature(out tempValue);
                    Console.WriteLine($"Temperature: {tempValue.DegreesCelsius} \u00B0C");
                    i2CBmp280.TryReadPressure(out preValue);
                    Console.WriteLine($"Pressure: {preValue.Hectopascals} hPa");

                    // This time use altitude calculation
                    altValue = WeatherHelper.CalculateAltitude(preValue, defaultSeaLevelPressure, tempValue);

                    Console.WriteLine($"Calculated Altitude: {altValue} m");

                    // Calculate the barometric (corrected) pressure for the local position.
                    // Change the stationHeight value above to get a correct reading, but do not be tempted to insert
                    // the value obtained from the formula above. Since that estimates the altitude based on pressure,
                    // using that altitude to correct the pressure won't work.
                    var correctedPressure = WeatherHelper.CalculateBarometricPressure(preValue, tempValue, stationHeight);

                    Console.WriteLine($"Pressure corrected for altitude {stationHeight.Meters} m (with average humidity): {correctedPressure.Hectopascals} hPa");

                    Thread.Sleep(5000);
                }
            }
        }
示例#11
0
文件: WeatherTests.cs 项目: gLes/iot
        public void AltitudeIsCalculatedCorrectlyAtDefaultTemp(double expected, double hpa, double seaLevelHpa)
        {
            var altitude = WeatherHelper.CalculateAltitude(Pressure.FromHectopascal(hpa), Pressure.FromHectopascal(seaLevelHpa));

            Assert.Equal(expected, Math.Round(altitude, 2));
        }
示例#12
0
        /// <inheritdoc/>
        public override ISensorSample TakeReading(WeatherObservation observation)
        {
            this.LogTakeReadingStart();
            var sensorResult = new SensorSample(this.SensorName);

            // Initialize for reading
            this.Device.Write(new byte[] { REGCONTROLHUM, OVERSAMPLEHUM });
            var control = GetControlCode();

            this.Device.Write(new byte[] { REGCONTROL, (byte)control });

            // Read calibaration data
            var cal1 = this.ReadBytes(0x88, 24);
            var cal2 = this.ReadBytes(0xA1, 1);
            var cal3 = this.ReadBytes(0xE1, 7);

            sensorResult.AddDiagnostic("Calibration data (1/2/3)");
            sensorResult.AddDiagnostic(ByteOperations.PrintByteArray(cal1));
            sensorResult.AddDiagnostic(ByteOperations.PrintByteArray(cal2));
            sensorResult.AddDiagnostic(ByteOperations.PrintByteArray(cal3));

            var calibrationData = ExtractcalibrationData(cal1, cal2, cal3);

            // Pause per spec
            var wait_time = GetWaitTime();

            Thread.Sleep((int)wait_time / 1000);

            // Read raw data
            var data = this.ReadBytes(REGDATA, 8);

            sensorResult.AddDiagnostic("Raw data");
            sensorResult.AddDiagnostic(ByteOperations.PrintByteArray(data));

            var    rawTemp        = (data[3] << 12) | (data[4] << 4) | (data[5] >> 4);
            double rawTemperature = CalculateTemperature(sensorResult, calibrationData, rawTemp, out double tFine);

            // Refine pressure and adjust for temperature
            var    rawPressure   = (data[0] << 12) | (data[1] << 4) | (data[2] >> 4);
            double pressureValue = CalculatePressure(sensorResult, calibrationData, rawPressure, tFine);

            // Refine humidity
            var    rawHumidity   = (data[6] << 8) | data[7];
            double humidityValue = CalculateHumidity(sensorResult, calibrationData, rawHumidity, tFine);

            sensorResult.AddFinalObservation(rawTemperature + this.calibrationOffset, "TEMPERATURE", ObservationUnits.DegreesCelcius);
            sensorResult.AddFinalObservation(pressureValue, "PRESSURE", ObservationUnits.HectoPascal);
            sensorResult.AddFinalObservation(humidityValue, "HUMIDITY", ObservationUnits.Percentage);

            var pressure    = new Pressure(pressureValue, UnitsNet.Units.PressureUnit.Hectopascal);
            var humidity    = new RelativeHumidity(humidityValue, UnitsNet.Units.RelativeHumidityUnit.Percent);
            var temperature = new Temperature(rawTemperature, UnitsNet.Units.TemperatureUnit.DegreeCelsius);

            var actualAltitude     = new Length(this.altitudeInMeters, UnitsNet.Units.LengthUnit.Meter);
            var altitudeCalculated = WeatherHelper.CalculateAltitude(pressure);

            double absHumidity             = WeatherHelper.CalculateAbsoluteHumidity(temperature, humidity).GramsPerCubicMeter;
            double dewPoint                = WeatherHelper.CalculateDewPoint(temperature, humidity).DegreesCelsius;
            double heatIndex               = WeatherHelper.CalculateHeatIndex(temperature, humidity).DegreesCelsius;
            double vapourPressure          = WeatherHelper.CalculateActualVaporPressure(temperature, humidity).Hectopascals;
            double barometricPressure      = WeatherHelper.CalculateBarometricPressure(pressure, temperature, actualAltitude, humidity).Hectopascals;
            double vapourPressureOverIce   = WeatherHelper.CalculateSaturatedVaporPressureOverIce(temperature).Hectopascals;
            double vapourPressureOverWater = WeatherHelper.CalculateSaturatedVaporPressureOverWater(temperature).Hectopascals;
            double seaLevelPressure        = WeatherHelper.CalculateSeaLevelPressure(pressure, actualAltitude, temperature).Hectopascals;

            sensorResult.AddFinalObservation(temperature.DegreesCelsius + this.calibrationOffset, "TEMPERATURE", ObservationUnits.DegreesCelcius);
            sensorResult.AddFinalObservation(pressure.Hectopascals, "PRESSURE", ObservationUnits.HectoPascal);
            sensorResult.AddFinalObservation(barometricPressure, "BAROMETRIC PRESSURE", ObservationUnits.HectoPascal);
            sensorResult.AddFinalObservation(seaLevelPressure, "SEA LEVEL PRESSURE", ObservationUnits.HectoPascal);
            sensorResult.AddFinalObservation(vapourPressureOverIce, "OVER ICE PRESSURE", ObservationUnits.HectoPascal);
            sensorResult.AddFinalObservation(vapourPressureOverWater, "OVER WATER PRESSURE", ObservationUnits.HectoPascal);
            sensorResult.AddFinalObservation(humidity.Percent, "RELATIVE HUMIDITY", ObservationUnits.Percentage);
            sensorResult.AddFinalObservation(absHumidity, "ABSOLUTE HUMIDITY", ObservationUnits.GramsPerCubicMeter);
            sensorResult.AddFinalObservation(vapourPressure, "VAPOUR PRESSURE", ObservationUnits.Percentage);
            sensorResult.AddFinalObservation(altitudeCalculated.Meters, "CALCULATED ALTITUDE", ObservationUnits.Meters);
            sensorResult.AddFinalObservation(actualAltitude.Meters, "ACTUAL ALTITUDE", ObservationUnits.Meters);
            sensorResult.AddFinalObservation(heatIndex, "HEAT INDEX", ObservationUnits.DegreesCelcius);
            sensorResult.AddFinalObservation(dewPoint, "DEW POINT", ObservationUnits.DegreesCelcius);

            observation.Temperature1       = temperature.DegreesCelsius + this.calibrationOffset;
            observation.Pressure           = pressure.Hectopascals;
            observation.BarometricPressure = barometricPressure;
            observation.SealevelPressure   = seaLevelPressure;
            observation.OverIcePressure    = vapourPressureOverIce;
            observation.OverWaterPressure  = vapourPressureOverWater;
            observation.RelativeHumidity   = humidity.Percent;
            observation.AbsoluteHumidity   = absHumidity;
            observation.ActualAltitude     = actualAltitude.Meters;
            observation.CalculatedAltitude = altitudeCalculated.Meters;
            observation.HeatIndex          = heatIndex;
            observation.DewPoint           = dewPoint;

            this.LogTakeReadingComplete();

            return(sensorResult);
        }
示例#13
0
        public static void Main(string[] args)
        {
            // Sample for each device separately
            // LedMatrix.Run();
            // Joystick.Run();
            // AccelerometerAndGyroscope.Run();
            // Magnetometer.Run();
            // TemperatureAndHumidity.Run();
            // PressureAndTemperature.Run();

            // set this to the current sea level pressure in the area for correct altitude readings
            var defaultSeaLevelPressure = Pressure.MeanSeaLevel;

            using (var sh = new SenseHat())
            {
                int n = 0;
                int x = 3, y = 3;

                while (true)
                {
                    Console.Clear();

                    (int dx, int dy, bool holding) = JoystickState(sh);

                    if (holding)
                    {
                        n++;
                    }

                    x = (x + 8 + dx) % 8;
                    y = (y + 8 + dy) % 8;

                    sh.Fill(n % 2 == 0 ? Color.DarkBlue : Color.DarkRed);
                    sh.SetPixel(x, y, Color.Yellow);

                    var tempValue  = sh.Temperature;
                    var temp2Value = sh.Temperature2;
                    var preValue   = sh.Pressure;
                    var humValue   = sh.Humidity;
                    var accValue   = sh.Acceleration;
                    var angValue   = sh.AngularRate;
                    var magValue   = sh.MagneticInduction;
                    var altValue   = WeatherHelper.CalculateAltitude(preValue, defaultSeaLevelPressure, tempValue);

                    Console.WriteLine($"Temperature Sensor 1: {tempValue.Celsius:0.#}\u00B0C");
                    Console.WriteLine($"Temperature Sensor 2: {temp2Value.Celsius:0.#}\u00B0C");
                    Console.WriteLine($"Pressure: {preValue:0.##}hPa");
                    Console.WriteLine($"Altitude: {altValue:0.##}m");
                    Console.WriteLine($"Acceleration: {sh.Acceleration}g");
                    Console.WriteLine($"Angular rate: {sh.AngularRate}DPS");
                    Console.WriteLine($"Magnetic induction: {sh.MagneticInduction}gauss");
                    Console.WriteLine($"Relative humidity: {humValue:0.#}%");

                    // WeatherHelper supports more calculations, such as saturated vapor pressure, actual vapor pressure and absolute humidity.
                    Console.WriteLine($"Heat index: {WeatherHelper.CalculateHeatIndex(tempValue, humValue).Celsius:0.#}\u00B0C");
                    Console.WriteLine($"Dew point: {WeatherHelper.CalculateDewPoint(tempValue, humValue).Celsius:0.#}\u00B0C");

                    Thread.Sleep(1000);
                }
            }
        }