public override void ViewDidLoad() { base.ViewDidLoad(); // Initialize IoT Hub client Device = new MyClass(); // Add the telemetry data Device.AddTelemetry(new TelemetryFormat { Name = "Temperature", DisplayName = "Temp (C)", Type = "Double" }, (double)0); Device.AddTelemetry(new TelemetryFormat { Name = "Humidity", DisplayName = "Hmdt (%)", Type = "Double" }, (double)0); // If you are developing and want to avoid having to enter the full connection string on the device, // you can temporarily hard code it here. Comment this when done! //Device.DeviceId = "[DeviceId]"; //Device.HostName = "[HostName]"; //Device.DeviceKey = "[DeviceKey]"; // Prepare UI elements buttonConnect.AccessibilityIdentifier = "buttonConnect"; buttonConnect.Enabled = false; buttonConnect.SetTitle("Press to connect", UIControlState.Normal); buttonConnect.TouchUpInside += ButtonConnect_TouchUpInside; buttonSend.AccessibilityIdentifier = "buttonSend"; buttonSend.Enabled = false; buttonSend.SetTitle("Press to send telemetry data", UIControlState.Normal); buttonSend.TouchUpInside += ButtonSend_TouchUpInside; textDeviceId.AccessibilityIdentifier = "textDeviceId"; textDeviceId.EditingChanged += TextDeviceId_EditingChanged; textDeviceId.Text = Device.DeviceId; textHostName.AccessibilityIdentifier = "textHostName"; textHostName.EditingChanged += TextHostName_EditingChanged;; textHostName.Text = Device.HostName; textDeviceKey.AccessibilityIdentifier = "textDeviceKey"; textDeviceKey.EditingChanged += TextDeviceKey_EditingChanged; textDeviceKey.Text = Device.DeviceKey; sliderTemperature.AccessibilityIdentifier = "sliderTemperature"; sliderTemperature.ValueChanged += SliderTemperature_ValueChanged; sliderTemperature.MinValue = 0; sliderTemperature.MaxValue = 100; sliderTemperature.Value = 50; sliderHumidity.AccessibilityIdentifier = "sliderHumidity"; sliderHumidity.ValueChanged += SliderHumidity_ValueChanged; sliderHumidity.MinValue = 0; sliderHumidity.MaxValue = 100; sliderHumidity.Value = 50; // Check configuration and enable connect button if it looks ok buttonConnect.Enabled = Device.checkConfig(); }
public MainPage() { this.InitializeComponent(); this.NavigationCacheMode = NavigationCacheMode.Required; // Initialize IoT Hub client Device = new MyClass(); // Add the telemetry data Device.AddTelemetry(new TelemetryFormat { Name = "Temperature", DisplayName = "Temp (C)", Type = "Double" }, (double)0); Device.AddTelemetry(new TelemetryFormat { Name = "Humidity", DisplayName = "Hmdt (%)", Type = "Double" }, (double)0); this.buttonConnect.IsEnabled = false; this.buttonConnect.Content = "Press to Connect"; this.buttonConnect.Click += ButtonConnect_Click; this.buttonSend.IsEnabled = false; this.buttonSend.Content = "Press to send telemetry data"; this.buttonSend.Click += ButtonSend_Click; this.textDeviceId.TextChanged += TextDeviceId_TextChanged; this.textDeviceId.Text = Device.DeviceId; this.textDeviceKey.TextChanged += TextDeviceKey_TextChanged; this.textDeviceKey.Text = Device.DeviceKey; this.textHostName.TextChanged += TextHostName_TextChanged; this.textHostName.Text = Device.HostName; this.sliderTemperature.ValueChanged += SliderTemperature_ValueChanged; this.sliderTemperature.Value = 50; this.sliderHumidity.ValueChanged += SliderHumidity_ValueChanged; this.sliderHumidity.Value = 50; // Set focus to the connect button buttonConnect.IsEnabled = Device.checkConfig(); }
protected override void OnCreate(Bundle bundle) { base.OnCreate(bundle); // Set our view from the "main" layout resource SetContentView(Resource.Layout.Main); // Initialize IoT Hub client Device = new MyClass(); // Add the telemetry data Device.AddTelemetry(new TelemetryFormat { Name = "Temperature", DisplayName = "Temp (C)", Type = "Double" }, (double)0); Device.AddTelemetry(new TelemetryFormat { Name = "Humidity", DisplayName = "Hmdt (%)", Type = "Double" }, (double)0); // If you are developing and want to avoid having to enter the full connection string on the device, // you can temporarily hard code it here. Comment this when done! //Device.DeviceId = "[DeviceId]"; //Device.HostName = "[HostName]"; //Device.DeviceKey = "[DeviceKey]"; // Prepare UI elements buttonConnect = FindViewById <Button>(Resource.Id.buttonConnect); buttonConnect.Enabled = false; buttonConnect.Text = "Press to Connect"; buttonConnect.Click += ButtonConnect_Click; buttonSend = FindViewById <Button>(Resource.Id.buttonSend); buttonSend.Enabled = false; buttonSend.Text = "Press to send telemetry data"; buttonSend.Click += ButtonSend_Click; textDeviceId = FindViewById <TextView>(Resource.Id.textDeviceId); textDeviceId.TextChanged += TextDeviceId_TextChanged; textDeviceId.Text = Device.DeviceId; textDeviceKey = FindViewById <TextView>(Resource.Id.textDeviceKey); textDeviceKey.TextChanged += TextDeviceKey_TextChanged; textDeviceKey.Text = Device.DeviceKey; textHostName = FindViewById <TextView>(Resource.Id.textHostName); textHostName.TextChanged += TextHostName_TextChanged; textHostName.Text = Device.HostName; textTemperature = FindViewById <TextView>(Resource.Id.textTemperature); SeekBar seekBarTemperature = FindViewById <SeekBar>(Resource.Id.seekBarTemperature); seekBarTemperature.ProgressChanged += SeekBarTemperature_ProgressChanged; seekBarTemperature.Progress = 50; textHumidity = FindViewById <TextView>(Resource.Id.textHumidity); SeekBar seekBarHumidity = FindViewById <SeekBar>(Resource.Id.seekBarHumidity); seekBarHumidity.ProgressChanged += SeekBarHumidity_ProgressChanged; seekBarHumidity.Progress = 50; // Set focus to the connect button buttonConnect.RequestFocus(); buttonConnect.Enabled = Device.checkConfig(); }