コード例 #1
0
        private async void SendTemperature(TemperatureRecord temperatureRecord)
        {
            try
            {
                var runtime    = GetRuntime();
                var dataPoints = new
                {
                    deviceId = _deviceId,
                    tempC    = temperatureRecord.Celsius,
                    tempF    = temperatureRecord.Fahrenheit,
                    runtime
                };

                var messageString = JsonConvert.SerializeObject(dataPoints);
                var message       = new Message(Encoding.ASCII.GetBytes(messageString));

                Debug.WriteLine($">> Sending current temperature to Iot Hub... {messageString}");

                var deviceClient = InitializeDeviceClient();

                await deviceClient.SendEventAsync(message);

                deviceClient.Dispose();
            }
            catch (Exception ex)
            {
                Debug.WriteLine("FAILED to send temperature to Iot Hub.");
                Debug.WriteLine(ex);
            }
        }
コード例 #2
0
        private void UpdateCircuit(TemperatureRecord temperatureRecord)
        {
            var redValue = (temperatureRecord.Fahrenheit > _avgTemperature) ? GpioPinValue.Low : GpioPinValue.High;

            _redLedPin.Write(redValue);

            var yellowValue = (temperatureRecord.Fahrenheit <= _avgTemperature) ? GpioPinValue.Low : GpioPinValue.High;

            _yellowLedPin.Write(yellowValue);
        }
コード例 #3
0
        private void UpdateThermometerControls(TemperatureRecord temperatureRecord)
        {
            var thermometerHeight = ThermometerScale.Height * (temperatureRecord.Fahrenheit / 100);
            var topMargin         = 100.0 + (ThermometerScale.Height - thermometerHeight);

            var margin = ThermometerValue.Margin;

            margin.Top = topMargin;

            ThermometerValue.Margin = margin;
            ThermometerValue.Height = thermometerHeight;
        }
コード例 #4
0
        private void UpdateTemperatureControls(TemperatureRecord temperatureRecord)
        {
            try
            {
                ThermometerValue.Visibility = Visibility.Visible;

                if (temperatureRecord.Fahrenheit < 0)
                {
                    ErrorTextBox.Text       = string.Format("An error was detected with the circuit.");
                    ErrorTextBox.Visibility = Visibility.Visible;
                    ErrorIcon.Visibility    = Visibility.Visible;
                }
                else
                {
                    ErrorTextBox.Visibility = Visibility.Collapsed;
                    ErrorIcon.Visibility    = Visibility.Collapsed;
                }

                CurrentTempFTextBox.Text = string.Format("The current\r\ntemperature\r\nis {0} °F.", Math.Round(temperatureRecord.Fahrenheit, 2));


                if (_avgTemperature > 0.0)
                {
                    AverageTempFTextBox.Text       = string.Format("The average\r\ntemperature\r\nis {0} °F.", Math.Round(_avgTemperature, 2));
                    AverageTempFTextBox.Visibility = Visibility.Visible;
                }
                else
                {
                    AverageTempFTextBox.Visibility = Visibility.Collapsed;
                }

                UpdateThermometerControls(temperatureRecord);
            }
            catch
            {
                // ignored
            }
        }