Ejemplo n.º 1
0
        public async void InitializeApplicationAsync()
        {
            _connectionStatusLED.Fill = _greyColorBrush;
            _cameraHelper             = new CameraHelper(_captureElement);
            _blobStorageHepler        = new BlobStorageHelper();

            _iothubclient = new DeviceClientHelper(DeviceId, String.Format($"HostName=home-automation-iothub.azure-devices.net;DeviceId={DeviceId};SharedAccessKey=ekgleg2ZT7hICYSY5wJCCZzOgp3RhdnIPt0W35Kojw0="));
            _iothubclient._client.SetConnectionStatusChangesHandler(OnConnectionStatusChagned);

            await _iothubclient._client.SetMethodHandlerAsync("SetDeviceElementSwitchStatus", OnSetDeviceElementSwitchStatus, null);

            await _iothubclient._client.SetMethodHandlerAsync("SetDeviceElementValue", OnSetDeviceElementValue, null);

            await _iothubclient._client.SetMethodHandlerAsync("CaptureImage", OnImageCapture, null);

            await _iothubclient._client.SetMethodHandlerAsync("OnTemerature", OnReadTemperature, null);

            await _iothubclient._client.SetMethodHandlerAsync("OnHumidity", OnReadHumidity, null);

            await _iothubclient._client.SetMethodHandlerAsync("OnWeatherForecast", OnReadWeatherForecast, null);

            await _iothubclient._client.SetMethodHandlerAsync("OnDeviceStatus", OnDeviceStatusAsync, null);

            await _iothubclient.OpenConnectionAsync();

            await _cameraHelper.StartCameraPreviewAsync();

            _timer = new DispatcherTimer {
                Interval = new TimeSpan(0, 0, 5)
            };
            _timer.Tick += OnTimerTicked;
            _timer.Start();

            _cooler = new VirtualDeviceElement(300, ElementType.Cooler);
            _heater = new VirtualDeviceElement(1800, ElementType.Heater);
            _light  = new VirtualDeviceElement(100, ElementType.Light);

            _virtualElements = new List <VirtualDeviceElement>()
            {
                _cooler,
                _heater,
                _light,
            };
        }
Ejemplo n.º 2
0
        static void Main(string[] args)
        {
            // Configure cancel key press handler (to stop the app)
            Console.CancelKeyPress += new ConsoleCancelEventHandler(
                CancelKeyPressHandler);

            // Connect to the cloud
            var deviceClient = DeviceClientHelper.Init();

            // Telemetry generator produces random temperature
            // and humidity, and then sends them both to the cloud
            var telemetryGenerator = new Generator(
                deviceClient, cancellationTokenSource.Token);

            // Associate handler to update device properties according to cloud requests
            deviceClient.SetDesiredPropertyUpdateCallbackAsync(
                PropertyUpdateCallback, telemetryGenerator).Wait();

            // Start telemetry
            telemetryGenerator.Start().Wait();
        }