Пример #1
0
        private static void Main()
        {
            _sensor = new BME280(Hardware.SocketOne, BME280.I2CAddresses.Address0)
            {
                TemperatureUnit      = TemperatureUnits.Fahrenheit,
                PressureCompensation = PressureCompensationModes.SeaLevelCompensated
            };

            _sensor.SetRecommendedMode(BME280.RecommendedModes.WeatherMonitoring);

            while (true)
            {
                Debug.WriteLine("------Reading individual values-------");

                Debug.WriteLine($"Pressure.......: {_sensor.ReadPressure():F1} hPa");
                Debug.WriteLine($"Temperature....: {_sensor.ReadTemperature():F2} °F");
                Debug.WriteLine($"Humidity.......: {_sensor.ReadHumidity():F2} %RH");
                Debug.WriteLine($"Altitude.......: {_sensor.ReadAltitude():F0} meters\n");

                _sensor.ReadSensor(out Single pressure, out Single temperature, out Single humidity, out Single altitude);

                Debug.WriteLine("------Using the ReadSensor Method-------");
                Debug.WriteLine($"Pressure.......: {pressure:F1} hPa");
                Debug.WriteLine($"Temperature....: {temperature:F2} °F");
                Debug.WriteLine($"Humidity.......: {humidity:F2} %RH");
                Debug.WriteLine($"Altitude.......: {altitude:F0} meters\n");

                Thread.Sleep(5000);
            }
        }
        static void TelemetryLoop()
        {
            while (true)
            {
                TBTelemetry telemetry = new TBTelemetry();
                telemetry.Add("temperature", bme280Sensor.ReadTemperature());
                telemetry.Add("humidity", bme280Sensor.ReadHumidity());
                telemetry.Add("pressure", bme280Sensor.ReadPressure());

                thingsBoard.SendTelemetry(telemetry);

                Debug.WriteLine("Message sent: " + telemetry.ToJson());

                Thread.Sleep(60000);
            }
        }
Пример #3
0
        private void TimerCallback(object state)
        {
            var temp     = bme280.ReadTemperature();
            var press    = bme280.ReadPreasure() / 100;
            var humidity = bme280.ReadHumidity();
            var alt      = bme280.ReadAltitude(1013); // 1013hPa = pressure at 0m

            Debug.WriteLine("Temp:{0:F2}℃ Humidity:{1:F2}% Press:{2:F2}hPa Alt:{3:F0}m", temp, humidity, press, alt);

            var task = this.Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () =>
            {
                tempValue.Text  = temp.ToString("F2") + "℃";
                humValue.Text   = humidity.ToString("F2") + "%";
                pressValue.Text = press.ToString("F2") + "hPa";
            });
        }
Пример #4
0
        public static void Main()
        {
            //Setup I2C pins for ESP32 board
            Configuration.SetPinFunction(21, DeviceFunction.I2C1_DATA);
            Configuration.SetPinFunction(22, DeviceFunction.I2C1_CLOCK);

            BME280 bme280Sensor = new BME280(1, BME280.I2CAddresses.Address0);

            while (true)
            {
                Debug.WriteLine(bme280Sensor.ReadHumidity());
                Debug.WriteLine(bme280Sensor.ReadPressure());
                Debug.WriteLine(bme280Sensor.ReadTemperature());

                Thread.Sleep(10000);
            }
        }