Beispiel #1
0
        protected async override void OnNavigatedTo(NavigationEventArgs e)
        {
            base.OnNavigatedTo(e);
            await sensor.Init();

            dt.Tick += (s, ea) =>
            {
                var x = sensor.Temperature;
                TheTextBlock.Text = $"{x.ToString()}C";
                if (count == 0)
                {
                    History.Add((int)((x - 23) * 40));
                    if (History.Count > 10)
                    {
                        History.RemoveAt(0);
                    }
                    Graph.ItemsSource = null;
                    Graph.ItemsSource = History;
                    count             = 5;
                }
                else
                {
                    count--;
                }
            };
            dt.Start();
        }
        protected override async void OnNavigatedTo(NavigationEventArgs e)
        {
            base.OnNavigatedTo(e);
            await sensor.Init();

            EHub = new EventHubHelper();
            EHub.serviceNamespace       = "weathercenter-ns";
            EHub.hubName                = "weatherhub";
            EHub.deviceName             = "shwarspi";
            EHub.sharedAccessPolicyName = "all";
            EHub.sharedAccessKey        = "cFsp8GEvk/iRnjehSt/JBHjIyAV0lGVBWGJqAc9/IMw=";

            var timer = new DispatcherTimer
            {
                Interval = TimeSpan.FromSeconds(3)
            };

            timer.Tick += async(sender, o) =>
            {
                var temp = sensor.Temperature;
                Debug.WriteLine("Temperature = " + temp);
                TheTextBlock.Text = $"Temperature : {temp}°C";
                await EHub.SendMessage(
                    $"{{\"temperature\":\"{temp.ToString().Replace(',', '.')}\", \"source\":\"RPi2\", \"timewhen\":\"{DateTime.Now.ToString("o")}\"}}");
            };
            timer.Start();
        }
Beispiel #3
0
        protected async override void OnNavigatedTo(NavigationEventArgs e)
        {
            Sens = new BMP180();
            await Sens.Init();

            dt.Tick += ReMeasure;
            dt.Start();
        }
        protected async override void OnNavigatedTo(NavigationEventArgs e)
        {
            base.OnNavigatedTo(e);
            await sensor.Init();

            iothub = DeviceClient.CreateFromConnectionString(DeviceConnectionString);
            await iothub.OpenAsync();

            dt.Tick += SendTemperature;
            dt.Start();
        }