private async void MeasureTimerTick(object sender, object e)
        {
            // read Temperature
            double temperature = await bme280Sensor.ReadTemperature();

            double humidity = await bme280Sensor.ReadHumidity();

            double pressure = await bme280Sensor.ReadPressure();

            float altitude = await bme280Sensor.ReadAltitude(seaLevelPressure);

            // convert to Fahrenheit
            //double fahrenheitTemperature = temperature * 1.8 + 32.0; // hhe

            // read Proximity
            //int proximity = vncl4010Sensor.ReadProximity(); //hhe

            //TemperatureStatus.Text = "The temperature is currently " + fahrenheitTemperature.ToString("n1") + "°F"; //hhe
            Location.Text   = webApiClient.device.Location;
            DeviceName.Text = webApiClient.device.Name;
            X.Text          = webApiClient.device.X;
            Y.Text          = webApiClient.device.Y;
            Z.Text          = webApiClient.device.Z;

            TemperatureStatus.Text = "The temperature is currently " + temperature.ToString("n1") + "°C";
            HumidityStatus.Text    = "The humidity is currently " + humidity.ToString("n1") + "%";
            PressureStatus.Text    = "The pressure is currently " + pressure.ToString("n1") + "";
            Altitude.Text          = "The altitude is currently " + altitude.ToString("n1") + " meters";

            await webApiClient.PutDevice(X.Text, Y.Text, Z.Text, temperature, humidity, pressure);
        }
Ejemplo n.º 2
0
        private async void TakeReadingAsync(object sender, object e)
        {
            // Create variables to store the sensor data: temperature, pressure, humidity and altitude.
            var temperatureReadings = new List <float>();
            var pressureReadings    = new List <float>();
            var altitudeReadings    = new List <float>();
            var humidityReadings    = new List <float>();

            // Read 10 samples of the data
            for (int i = 0; i < 10; i++)
            {
                temperatureReadings.Add(await _BME280.ReadTemperature());
                pressureReadings.Add(await _BME280.ReadPressure());
                altitudeReadings.Add(await _BME280.ReadAltitude());
                humidityReadings.Add(await _BME280.ReadHumidity());
            }

            // Create a WeatherData object which will hold the
            // average of the 10 samples for each attribute.
            WeatherData weatherReading = new WeatherData
            {
                RecordingTime = DateTime.Now.ToUniversalTime(),
                Temperature   = temperatureReadings.Average(),
                Humidity      = humidityReadings.Average(),
                Pressure      = pressureReadings.Average(),
                Altitude      = altitudeReadings.Average()
            };

            // Send to console for debugging purposes
            Debug.WriteLine(weatherReading.ToString());

            // Send the reading to the event hub
            await _weatherDataSender.SendDataJsonUtf8Async(weatherReading);
        }
Ejemplo n.º 3
0
 private static void SensorTimerTick(object state)
 {
     // Write sensor data to output / immediate window
     Debug.WriteLine("Temperature..: " + bme.ReadTemperature().ToString("00.0") + "C");
     Debug.WriteLine("Humidity.....: %" + bme.ReadHumidity().ToString("00.0" + "RH"));
     Debug.WriteLine("Pressure.....: " + bme.ReadPressure().ToString(".0") + "Pa");
     Debug.WriteLine("Altitude.....: " + bme.ReadAltitude(slp).ToString(".0") + "m");
     Debug.WriteLine("-----");
 }
        private void _timer_Tick(object sender, object e)
        {
            var temp     = _bme280.ReadTemperature();
            var humidity = _bme280.ReadHumidity();
            var pressure = _bme280.ReadPressure();
            var altitude = _bme280.ReadAltitude(seaLevelPressure);

            if (temp.Status == System.Threading.Tasks.TaskStatus.RanToCompletion)
            {
                Debug.WriteLine("Temp: {0} deg C", temp.Result);
                this.t_temp.Text = temp.Result.ToString();
                SendDeviceToCloudMessagesAsync(temp.Result, "Temp");
            }
            else
            {
                Debug.WriteLine("Temp: {0} deg C", temp.Status);
                this.t_temp.Text = temp.Status.ToString();
            }

            if (humidity.Status == System.Threading.Tasks.TaskStatus.RanToCompletion)
            {
                Debug.WriteLine("Humidity: {0} %", humidity.Result);
                this.t_hum.Text = humidity.Result.ToString();
                SendDeviceToCloudMessagesAsync(humidity.Result, "Humidity");
            }
            else
            {
                Debug.WriteLine("Humidity: {0} %", humidity.Status);
                this.t_hum.Text = humidity.Status.ToString();
            }

            if (pressure.Status == System.Threading.Tasks.TaskStatus.RanToCompletion)
            {
                Debug.WriteLine("Pressure: {0} Pa", pressure.Result);
                this.t_pres.Text = pressure.Result.ToString();
                SendDeviceToCloudMessagesAsync(pressure.Result, "Pressure");
            }
            else
            {
                Debug.WriteLine("Pressure: {0} Pa", pressure.Status);
                this.t_pres.Text = pressure.Status.ToString();
            }

            if (altitude.Status == System.Threading.Tasks.TaskStatus.RanToCompletion)
            {
                Debug.WriteLine("Altitude: {0} m", altitude.Result);
                this.t_alt.Text = altitude.Result.ToString();
                SendDeviceToCloudMessagesAsync(altitude.Result, "Altitude");
            }
            else
            {
                Debug.WriteLine("Altitude: {0} m", altitude.Status);
                this.t_alt.Text = altitude.Status.ToString();
            }
        }
Ejemplo n.º 5
0
        static void Main(string[] args)
        {
            MMALCamera cam = MMALCamera.Instance;

            // Create observable that will generate an incrementing number every second
            var observable = Observable.Generate(1, x => true, x => x + 1, x => x, x => TimeSpan.FromSeconds(1));

            var relay  = OutputPort.Create(17, OutputPort.InitialValue.Low).Result;
            var light1 = OutputPort.Create(27, OutputPort.InitialValue.Low).Result;
            var light2 = OutputPort.Create(22, OutputPort.InitialValue.Low).Result;
            var button = InputPort.Create(24, GpioEdge.Both).Result;

            // Write true whenever the number is even and odd when the number is odd
            using (var imgCaptureHandler = new ImageStreamCaptureHandler("/home/pi/images/", "jpg"))
                using (observable.Select(x => x % 2 == 0).Subscribe(relay))
                    using (observable.Select(x => x % 2 == 0).Subscribe(light1))
                        //using (observable.Select(x => x % 2 != 0).Subscribe(light2))
                        //using (button.Do(pressed => Console.WriteLine(pressed)).Subscribe())
                        using (button.Subscribe(light2))
                            using (var i2cBus = new I2CBusPI("/dev/i2c-1"))
                            {
                                var takePictureTask = cam.TakePicture(imgCaptureHandler, MMALEncoding.JPEG, MMALEncoding.I420);

                                var i2cDevice = new I2CDevicePI(i2cBus, Display.DefaultI2CAddress);

                                var sensor = new BME280Sensor(i2cBus, 1014);

                                var display = new SSD1306.Display(i2cDevice, 128, 64);
                                display.Init();

                                var dfont = new AdafruitSinglePageFont();

                                for (int i = 0; i < 100; i++)
                                {
                                    display.WriteLineBuff(dfont, $"Temperature: {sensor.ReadTemperature().Result} °C", $"Pressure: {sensor.ReadPressure().Result} Pa", $"Humidity: {sensor.ReadHumidity().Result} %", $"Altitude: {sensor.ReadAltitude().Result} m", "Line 5", "Line 6", "Line 7", "Line 8");
                                    display.DisplayUpdate();
                                }

                                //for (int i = 0; i < 100; i++)
                                //    display.DrawPixel(i, i);

                                takePictureTask.Wait();
                                display.ClearDisplay();
                            }
            // releasing relay
            relay.Write(true);
            // turning of light
            light1.Write(false);
            light2.Write(false);
            // Cleanup disposes all unmanaged resources and unloads Broadcom library. To be called when no more processing is to be done
            // on the camera.
            cam.Cleanup();
        }