Ejemplo n.º 1
0
        public MainPage()
        {
            this.InitializeComponent();

            // Initialize ConnectTheDots Helper
            CTD = new ConnectTheDots();

            // Restore local settings
            if (localSettings.Values.ContainsKey("DisplayName"))
            {
                CTD.DisplayName        = (string)localSettings.Values["DisplayName"];
                this.TBDeviceName.Text = CTD.DisplayName;
            }
            if (localSettings.Values.ContainsKey("ConnectionString"))
            {
                CTD.ConnectionString         = (string)localSettings.Values["ConnectionString"];
                this.TBConnectionString.Text = CTD.ConnectionString;
            }

            // Check configuration settings
            ConnectToggle.IsEnabled = checkConfig();
            CTD.DisplayName         = this.TBDeviceName.Text;
            CTD.ConnectionString    = this.TBConnectionString.Text;
            CTD.Organization        = "My Company";
            CTD.Location            = "Unknown";

            // Get user consent for accessing location
            Task.Run(async() =>
            {
                await CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Normal,
                                                                              async() =>
                {
                    this.LocationAccess = await Geolocator.RequestAccessAsync();
                });
            });

            // Add sensors to the ConnectTheDots object
            CTD.AddSensor("Temperature", "C");
            CTD.AddSensor("Humidity", "%");

            // Hook up a callback to display message received from Azure
            CTD.ReceivedMessage += (object sender, EventArgs e) => {
                // Received a new message, display it
                CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Normal,
                                                                        async() =>
                {
                    var dialogbox = new MessageDialog("Received message from Azure IoT Hub: \nName: " +
                                                      ((ConnectTheDots.ReceivedMessageEventArgs)e).Message.name +
                                                      "\nMessage: " +
                                                      ((ConnectTheDots.ReceivedMessageEventArgs)e).Message.message);
                    await dialogbox.ShowAsync();
                });
            };
        }
Ejemplo n.º 2
0
        public MainPage()
        {
            this.InitializeComponent();

            // Initialize QRCode Scanner
            Scanner            = new MobileBarcodeScanner(Dispatcher);
            Scanner.Dispatcher = Dispatcher;

            // Initialize ConnectTheDots Helper
            CTD = new ConnectTheDots();

            // Hook up a callback to display message received from Azure
            CTD.ReceivedMessage += CTD_ReceivedMessage;

            // Restore local settings
            if (localSettings.Values.ContainsKey("ConnectionString"))
            {
                CTD.ConnectionString         = (string)localSettings.Values["ConnectionString"];
                this.TBConnectionString.Text = CTD.ConnectionString;
            }

            if (localSettings.Values.ContainsKey("DisplayName"))
            {
                CTD.DisplayName        = (string)localSettings.Values["DisplayName"];
                this.TBDeviceName.Text = CTD.DisplayName;
            }

            // Check configuration settings
            ConnectToggle.IsEnabled = checkConfig();
            CTD.ConnectionString    = this.TBConnectionString.Text;
            CTD.DisplayName         = this.TBDeviceName.Text;
            CTD.Organization        = "My Company";
            CTD.Location            = "Unknown";

            // Get user consent for accessing location
            Task.Run(async() =>
            {
                await Dispatcher.RunAsync(CoreDispatcherPriority.Normal,
                                          async() =>
                {
                    this.LocationAccess = await Geolocator.RequestAccessAsync();
                    // Get device location
                    await updateLocation();
                });
            });

            // Add sensors to the ConnectTheDots object
            CTD.AddSensor("Temperature", "C");
            CTD.AddSensor("Humidity", "%");
        }
Ejemplo n.º 3
0
        private async void AddBandSensor <T>(IBandSensor <T> sensor,
                                             string measurename,
                                             string unitofmeasure,
                                             EventHandler <BandSensorReadingEventArgs <T> > ValueChangedEventHandler) where T : IBandSensorReading
        {
            // check current user consent for accessing Band sensor
            if (sensor.GetCurrentUserConsent() != UserConsent.Granted)
            {
                // user hasn’t consented, request consent
                await sensor.RequestUserConsentAsync();

                if (sensor.GetCurrentUserConsent() != UserConsent.Granted)
                {
                    return;
                }
            }
            // User granted consent
            // Add Sensor to ConnectTheDots Helper
            CTD.AddSensor(measurename, unitofmeasure);

            // hook up to the Sensor ReadingChanged event
            IEnumerable <TimeSpan> supportedHeartRateReportingIntervals = sensor.SupportedReportingIntervals;

            sensor.ReportingInterval = supportedHeartRateReportingIntervals.First <TimeSpan>();
            sensor.ReadingChanged   += ValueChangedEventHandler;

            // start reading from the sensor
            await sensor.StartReadingsAsync();
        }