Beispiel #1
0
        public async Task <string> GetSensorData()
        {
            HumiditySensor      hum  = new HumiditySensor();
            IRTemperatureSensor temp = new IRTemperatureSensor();

            //hum.SensorValueChanged += SensorValueChanged;
            //temp.SensorValueChanged += SensorValueChanged;

            await hum.Initialize();

            await hum.EnableSensor();

            //await hum.EnableNotifications();


            await temp.Initialize();

            await temp.EnableSensor();

            //await temp.EnableNotifications();



            hum.SensorValueChanged  += SensorValueChanged;
            temp.SensorValueChanged += SensorValueChanged;

            await hum.EnableNotifications();

            await temp.EnableNotifications();


            return("done");
        }
Beispiel #2
0
        public async Task <string> InitializeSensor()
        {
            await hum.Initialize();

            await hum.EnableSensor();

            await temp.Initialize();

            await temp.EnableSensor();


            hum.SensorValueChanged  += SensorValueChanged;
            temp.SensorValueChanged += SensorValueChanged;

            await hum.EnableNotifications();

            await temp.EnableNotifications();

            return("done");
        }
Beispiel #3
0
        private async void InitializeDevice()
        {
            Exception exc = null;

            try
            {
                tempSen = new IRTemperatureSensor();
                await tempSen.Initialize();

                await tempSen.EnableSensor();

                await tempSen.EnableNotifications();

                tempSen.SensorValueChanged += SensorValueChanged;

                humidSen = new HumiditySensor();
                await humidSen.Initialize();

                await humidSen.EnableSensor();

                await humidSen.EnableNotifications();

                humidSen.SensorValueChanged += SensorValueChanged;

                //await new MessageDialog("Device Connected").ShowAsync();
                //ReadDeviceData();
                ReadData.IsEnabled      = true;
                ConnectIoTHub.IsEnabled = true;
            }
            catch (Exception ex)
            {
                exc = ex;
                await new MessageDialog(exc.Message).ShowAsync();
            }

            if (exc != null)
            {
                await new MessageDialog(exc.Message).ShowAsync();
            }
        }
Beispiel #4
0
        private async void SetupSensors(bool serviceAsParameter)
        {
            pbar.Visibility = Windows.UI.Xaml.Visibility.Visible;
            ClearSensors();
            btnSetup.IsEnabled       = false;
            btnSetupParam.IsEnabled  = false;
            spTestButtons.Visibility = Windows.UI.Xaml.Visibility.Collapsed;

            Exception ex = null;

            try
            {
                if (serviceAsParameter)
                {
                    acc = new Accelerometer();
                    acc.SensorValueChanged += SensorValueChanged;
                    await acc.Initialize((await GattUtils.GetDevicesOfService(acc.SensorServiceUuid))[0]);

                    await acc.EnableSensor();

                    gyro = new Gyroscope();
                    gyro.SensorValueChanged += SensorValueChanged;
                    await gyro.Initialize((await GattUtils.GetDevicesOfService(gyro.SensorServiceUuid))[0]);

                    await gyro.EnableSensor();

                    hum = new HumiditySensor();
                    hum.SensorValueChanged += SensorValueChanged;
                    await hum.Initialize((await GattUtils.GetDevicesOfService(hum.SensorServiceUuid))[0]);

                    await hum.EnableSensor();

                    ks = new SimpleKeyService();
                    ks.SensorValueChanged += SensorValueChanged;
                    await ks.Initialize((await GattUtils.GetDevicesOfService(ks.SensorServiceUuid))[0]);

                    await ks.EnableSensor();

                    mg = new Magnetometer();
                    mg.SensorValueChanged += SensorValueChanged;
                    await mg.Initialize((await GattUtils.GetDevicesOfService(mg.SensorServiceUuid))[0]);

                    await mg.EnableSensor();

                    ps = new PressureSensor();
                    ps.SensorValueChanged += SensorValueChanged;
                    await ps.Initialize((await GattUtils.GetDevicesOfService(ps.SensorServiceUuid))[0]);

                    await ps.EnableSensor();

                    tempSen = new IRTemperatureSensor();
                    tempSen.SensorValueChanged += SensorValueChanged;
                    await tempSen.Initialize((await GattUtils.GetDevicesOfService(tempSen.SensorServiceUuid))[0]);

                    await tempSen.EnableSensor();

                    spTestButtons.Visibility = Windows.UI.Xaml.Visibility.Visible;
                }
                else
                {
                    acc = new Accelerometer();
                    acc.SensorValueChanged += SensorValueChanged;
                    await acc.Initialize();

                    await acc.EnableSensor();

                    gyro = new Gyroscope();
                    gyro.SensorValueChanged += SensorValueChanged;
                    await gyro.Initialize();

                    await gyro.EnableSensor();

                    hum = new HumiditySensor();
                    hum.SensorValueChanged += SensorValueChanged;
                    await hum.Initialize();

                    await hum.EnableSensor();

                    ks = new SimpleKeyService();
                    ks.SensorValueChanged += SensorValueChanged;
                    await ks.Initialize();

                    await ks.EnableSensor();

                    mg = new Magnetometer();
                    mg.SensorValueChanged += SensorValueChanged;
                    await mg.Initialize();

                    await mg.EnableSensor();

                    ps = new PressureSensor();
                    ps.SensorValueChanged += SensorValueChanged;
                    await ps.Initialize();

                    await ps.EnableSensor();

                    tempSen = new IRTemperatureSensor();
                    tempSen.SensorValueChanged += SensorValueChanged;
                    await tempSen.Initialize();

                    await tempSen.EnableSensor();

                    spTestButtons.Visibility = Windows.UI.Xaml.Visibility.Visible;
                }
            }
            catch (Exception exc)
            {
                ex = exc;
            }

            if (ex != null)
            {
                await new MessageDialog(ex.Message).ShowAsync();
            }

            pbar.Visibility         = Windows.UI.Xaml.Visibility.Collapsed;
            btnSetup.IsEnabled      = true;
            btnSetupParam.IsEnabled = true;
        }