Example #1
0
        private static void Pressure_Lcd(LcdController lcd, PressureTemperatureHumiditySensor sensor)
        {
            using (sensor)
            {
                sensor.SeaLevelPressureInHectopascals = 1013.25f;
                bool ok = sensor.Begin();

                if (!ok)
                {
                    Console.WriteLine($"Error initializing sensor");
                    return;
                }

                for (var i = 0; i < 3; ++i)
                {
                    sensor.ReadSensor();

                    Console.WriteLine($"Pressure:    {sensor.PressureInHectopascals:0.00} hPa");
                    Console.WriteLine($"Humdity:     {sensor.Humidity:0.00} %");
                    Console.WriteLine($"Temperature: {sensor.TemperatureInCelsius:0.00} C, {sensor.TemperatureInFahrenheit:0.00} F");
                    Console.WriteLine($"Altitude:    {sensor.AltitudeInMeters:0.00} m, {sensor.AltitudInFeet:0.00} ft");
                    Console.WriteLine();

                    ShowInfo(lcd, "Pressure", $"{sensor.PressureInHectopascals:0.00} hPa/mb");
                    ShowInfo(lcd, "Humdity", $"{sensor.Humidity:0.00} %");
                    ShowInfo(lcd, "Temperature", $"{sensor.TemperatureInCelsius:0.00} C, {sensor.TemperatureInFahrenheit:0.00} F");
                    ShowInfo(lcd, "Altitude", $"{sensor.AltitudeInMeters:0.00} m, {sensor.AltitudInFeet:0.00} ft");
                }
            }
        }
Example #2
0
        private static void Pressure(PressureTemperatureHumiditySensor sensor)
        {
            using (sensor)
            {
                sensor.SeaLevelPressureInHectopascals = 1013.25f;
                bool ok = sensor.Begin();

                if (!ok)
                {
                    Console.WriteLine($"Error initializing sensor");
                    return;
                }

                for (var i = 0; i < 5; ++i)
                {
                    sensor.ReadSensor();

                    Console.WriteLine($"Pressure:    {sensor.PressureInHectopascals:0.00} hPa");
                    Console.WriteLine($"Humdity:     {sensor.Humidity:0.00} %");
                    Console.WriteLine($"Temperature: {sensor.TemperatureInCelsius:0.00} C, {sensor.TemperatureInFahrenheit:0.00} F");
                    Console.WriteLine($"Altitude:    {sensor.AltitudeInMeters:0.00} m, {sensor.AltitudInFeet:0.00} ft");
                    Console.WriteLine();

                    Thread.Sleep(TimeSpan.FromSeconds(1));
                }
            }
        }
Example #3
0
        public void StartSendingData()
        {
            EventHubClient eventHubClient = CreateEventHubClient("DataEventHubConnectionString");
            Stopwatch      watch          = Stopwatch.StartNew();

            var pressureSettings = new I2cConnectionSettings(Program.I2cBusId, PressureTemperatureHumiditySensor.DefaultI2cAddress);
            var colorSettings    = new I2cConnectionSettings(Program.I2cBusId, RgbColorSensor.DefaultI2cAddress);

            using (var pressureSensor = new PressureTemperatureHumiditySensor(pressureSettings))
                using (var colorSensor = new RgbColorSensor(colorSettings))
                {
                    pressureSensor.SeaLevelPressureInHectopascals = 1013.25f;
                    bool ok = pressureSensor.Begin();

                    if (!ok)
                    {
                        Console.WriteLine($"Error initializing pressure sensor");
                        return;
                    }

                    ok = colorSensor.Begin();

                    if (!ok)
                    {
                        Console.WriteLine($"Error initializing color sensor");
                        return;
                    }

                    while (watch.Elapsed.TotalDays < 1)
                    {
                        pressureSensor.ReadSensor();
                        colorSensor.ReadSensor();

                        Console.WriteLine($"Pressure:    {pressureSensor.PressureInHectopascals:0.00} hPa");
                        Console.WriteLine($"Humdity:     {pressureSensor.Humidity:0.00} %");
                        Console.WriteLine($"Temperature: {pressureSensor.TemperatureInCelsius:0.00} C, {pressureSensor.TemperatureInFahrenheit:0.00} F");
                        Console.WriteLine($"Altitude:    {pressureSensor.AltitudeInMeters:0.00} m, {pressureSensor.AltitudInFeet:0.00} ft");
                        Console.WriteLine();

                        Console.WriteLine($"Color:       {Program.ToRgbString(colorSensor.Color)}");
                        Console.WriteLine($"Temperature: {colorSensor.Temperature:0.00} K");
                        Console.WriteLine($"Luminosity:  {colorSensor.Luminosity:0.00} lux");
                        Console.WriteLine();

                        Console.WriteLine("Sending sensors data to Azure IoT Hub...");
                        Console.WriteLine();

                        CreateMessage(pressureSensor, colorSensor, out Message message);
                        SendMessage(eventHubClient, ref message);

                        Thread.Sleep(TimeSpan.FromSeconds(1));
                    }
                }
        }