Example #1
0
 public MainPage()
 {
     //this.InitializeComponent();
     deviceClient = DeviceClient.Create(iotHubUri, new DeviceAuthenticationWithRegistrySymmetricKey("<Your Device Name>", deviceKey), TransportType.Mqtt);
     _sensor      = new BME280Sensor();
     DeviceToCloudMessage();
 }
Example #2
0
        // This method will be called by the application framework when the page is first loaded
        protected override async void OnNavigatedTo(NavigationEventArgs navArgs)
        {
            try
            {
                _BME280 = new BME280Sensor(_localSeaLevelPressure); // Create a new object for our sensor class
                await _BME280.InitializeDevice();                   // Initialize the sensor

                if (_BME280.init)
                {
                    // If all goes well, our BME280 is initialized and we can set up
                    // a timer which will take a reading and send data to the cloud
                    _weatherDataSender = new EventHubDataSender(_eventHubConnectionString);
                    _timer             = new DispatcherTimer
                    {
                        Interval = TimeSpan.FromMilliseconds(_timerInterval)
                    };
                    _timer.Tick += TakeReadingAsync; // Register this method to the dispatcher so that it is called every tick
                    _timer.Start();
                }
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex.Message);
            }
        }
Example #3
0
        public async Task InitializeAsync()
        {
            _bme280 = new BME280Sensor(BME280_I2C_ADDRESS);
            await _bme280.Initialize();

            IsInitialized = true;
        }
Example #4
0
        public async Task <Bme280Controller> Initialise()
        {
            _bme280 = new BME280Sensor();
            await _bme280.Initialize();

            return(this);
        }
Example #5
0
        private async Task InitializeBME280Sensor()
        {
            // Create sensor instance
            bme = new BME280Sensor();

            // Delay 1ms
            await Task.Delay(1);
        }
Example #6
0
        public MainPage()
        {
            this.InitializeComponent();

            // BME280 Sensörünü başlat
            bme = new BME280Sensor();

            // Ölçüm timer'ını yapılandır
            sensorTimer = new Timer(new TimerCallback(SensorTimerTick), null, 2000, 2000);
        }
Example #7
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();
        }
        protected override async void OnNavigatedTo(NavigationEventArgs e)
        {
            base.OnNavigatedTo(e);

            _bme280 = new BME280Sensor();
            await _bme280.Initialize();

            _timer          = new DispatcherTimer();
            _timer.Interval = TimeSpan.FromSeconds(1);
            _timer.Tick    += _timer_Tick;

            _timer.Start();
        }
        protected override async void OnNavigatedTo(NavigationEventArgs e)
        {
            base.OnNavigatedTo(e);

            _bme280 = new BuildAzure.IoT.Adafruit.BME280.BME280Sensor();
            await _bme280.Initialize();

            deviceClient = DeviceClient.Create(iotHubUri, new DeviceAuthenticationWithRegistrySymmetricKey(deviceId, deviceKey), TransportType.Mqtt);

            _timer          = new DispatcherTimer();
            _timer.Interval = TimeSpan.FromSeconds(60); //Para enviar al IoTHub 4 mensajes por minuto - 240 a la hora - 5.760 al día (el límite son 8.000)
            _timer.Tick    += _timer_Tick;

            _timer.Start();
        }
Example #10
0
        public MainPage()
        {
            this.InitializeComponent();

            // BME280 Sensörünü başlat
            bme = new BME280Sensor();

            // VEML6075 Sensörünü başlat
            veml = new VEML6075Sensor();

            // VEML6075 Sensörünü yapılandır
            veml.Config(VEML6075Sensor.IntegrationTime.IT_800ms, VEML6075Sensor.DynamicSetting.Normal, VEML6075Sensor.Trigger.NoActiveForceTrigger, VEML6075Sensor.ActiveForceMode.NormalMode, VEML6075Sensor.PowerMode.PowerOn);

            // Ölçüm timer'ını yapılandır
            sensorTimer = new Timer(new TimerCallback(SensorTimerTick), null, 2000, 2000);
        }
Example #11
0
        private async Task InitializeBME280()
        {
            // Create sensor instance
            bme = new BME280Sensor();

            // Optional advanced sensor configuration
            await bme.SetOversamplingsAndMode(
                BME280Sensor.HumidityOversampling.x04,
                BME280Sensor.TemperatureOversampling.x04,
                BME280Sensor.PressureOversampling.x04,
                BME280Sensor.SensorMode.Normal);

            // Optional advanced sensor configuration
            await bme.SetConfig(
                BME280Sensor.InactiveDuration.ms0500,
                BME280Sensor.FilterCoefficient.fc04);
        }
Example #12
0
 private void DeinitSensors()
 {
     if (bmp180 != null)
     {
         bmp180.Dispose();
         bmp180 = null;
     }
     if (bme280 != null)
     {
         bme280.Dispose();
         bme280 = null;
     }
     if (dhtSensor != null)
     {
         dhtSensor = null;
         dhtPin.Dispose();
         dhtPin = null;
     }
 }
Example #13
0
        public async void Run(IBackgroundTaskInstance taskInstance)
        {
            _deferral = taskInstance.GetDeferral();

            // Create a new object for our sensor class
            IBME280Sensor ibme280Sensor = new BME280Sensor();

            // Initialize the sensor
            await ibme280Sensor.Initialize();

            // Initialize them to 0.
            float temperature = 0;
            float pressure    = 0;
            float altitude    = 0;
            float humidity    = 0;
            // Create a constant for pressure at sea level.
            // This is based on your local sea level pressure (Unit: Hectopascal)
            const float seaLevelPressure = 1022.00f;

            // Read 10 samples of the data
            for (int i = 0; i < 10; i++)
            {
                temperature = await ibme280Sensor.ReadTemperature();

                //pressure = await BME280.ReadPreasure();
                //altitude = await BME280.ReadAltitude(seaLevelPressure);
                //humidity = await BME280.ReadHumidity();
                //Write the values to your debug console
                Debug.WriteLine($"Temperature: {temperature} deg C");
                //Debug.WriteLine("Humidity: " + humidity.ToString() + " %");
                //Debug.WriteLine("Pressure: " + pressure.ToString() + " Pa");
                //Debug.WriteLine("Altitude: " + altitude.ToString() + " m");
                Debug.WriteLine("");
            }

            taskInstance.Canceled += TaskInstanceOnCanceled;

            _deferral.Complete();
            //await AzureIoTHub.ReceiveCloudToDeviceMessageAsync();
        }
Example #14
0
        public MainPage()
        {
            this.InitializeComponent();

            // BME280 Sensörünü başlat
            bme = new BME280Sensor();

            // VEML6075 Sensörünü başlat
            veml = new VEML6075Sensor();

            // VEML6075 Sensörünü yapılandır
            veml.Config(VEML6075Sensor.IntegrationTime.IT_800ms, VEML6075Sensor.DynamicSetting.Normal, VEML6075Sensor.Trigger.NoActiveForceTrigger, VEML6075Sensor.ActiveForceMode.NormalMode, VEML6075Sensor.PowerMode.PowerOn);

            // Giriş / Çıkış Portunu başlat
            gc = new IOPort(false, false, false, false);

            // Röle Denetleyicisini başlat
            role = new RelayController();

            // Ölçüm timer'ını yapılandır
            sensorTimer = new Timer(new TimerCallback(SensorTimerTick), null, 2000, 10000);
        }
Example #15
0
        private async Task InitializeSensors()
        {
            // Create sensor instance: APDS9960
            // Ambient & RGB light: enabled, proximity: disabled, gesture: disabled
            apds = new APDS9960Sensor(true, false, false);

            // Create sensor instance: BME280
            bme = new BME280Sensor();

            // Delay 1ms
            await Task.Delay(1);

            // Create sensor instance: VEML6075Sensor
            veml = new VEML6075Sensor();

            // Advanced sensor configuration: VEML6075Sensor
            await veml.Config(
                VEML6075Sensor.IntegrationTime.IT_800ms,
                VEML6075Sensor.DynamicSetting.High,
                VEML6075Sensor.Trigger.NoActiveForceTrigger,
                VEML6075Sensor.ActiveForceMode.NormalMode,
                VEML6075Sensor.PowerMode.PowerOn
                );
        }
Example #16
0
        private async Task <bool> InitSensors()
        {
            Log.Info("Initializing sensors");
            OnStatusChanged("Initialising sensors");
            // Initialize the BMP180 Sensor
            try
            {
                OnStatusChanged("Initialising sensors..BMP180");
                bmp180 = new Bmp180Sensor();
                await bmp180.InitializeAsync();
            }
            catch (Exception ex)
            {
                Log.Info("BMP180 Init Error", ex);
                bmp180 = null;
            }

            try
            {
                OnStatusChanged("Initialising sensors..BME280");
                bme280 = new BME280Sensor();
                // Initialize BME280 Sensor
                await bme280.Initialize(0x76);

                if (bme280ForceMode)
                {
                    await bme280.SetSampling(SensorMode.MODE_FORCED,
                                             SensorSampling.SAMPLING_X1, // temperature
                                             SensorSampling.SAMPLING_X1, // pressure
                                             SensorSampling.SAMPLING_X1, // humidity
                                             SensorFilter.FILTER_OFF,
                                             StandbyDuration.STANDBY_MS_1000);
                }
            }
            catch (Exception ex)
            {
                Log.Info("BME280 Init Error", ex);
                bme280 = null;
            }

            try
            {
                OnStatusChanged("Initialising sensors..DHT22");
                GpioController controller = GpioController.GetDefault();
                dhtPin    = GpioController.GetDefault().OpenPin(DHT22_Pin, GpioSharingMode.Exclusive);
                dhtSensor = new Dht22(dhtPin, GpioPinDriveMode.InputPullUp);
            }
            catch (Exception ex)
            {
                Log.Info("DHT22 Init Error", ex);
                dhtSensor = null;
            }
            string status = "";

            if (bmp180 != null || bme280 != null || dhtSensor != null)
            {
                if (bmp180 != null)
                {
                    status += "BMP180";
                }
                if (bme280 != null)
                {
                    if (status.Length > 0)
                    {
                        status += ", ";
                    }
                    status += "BME280";
                }
                if (dhtSensor != null)
                {
                    if (status.Length > 0)
                    {
                        status += ", ";
                    }
                    status += "DHT22";
                }
                status = $"Found: {status} sensors";
            }
            else
            {
                status = "No sensor found";
            }
            OnStatusChanged(status);
            await Task.Delay(500);

            Log.Trace($"end");
            Log.Info(status);
            return(bmp180 != null || bme280 != null || dhtSensor != null);
        }