public async Task <ActionResult> ChangeColor()
        {
            var azureIoTCommand = new AzureIoTCommand
            {
                MethodName = "CommandFromCloud",
                ResponseTimeoutInSeconds = 200,
                PlayLoad = new PlayLoad
                {
                    Command = IoTCommandTypeEnum.ChangeColor,
                    Name    = "",
                    Status  = "OK"
                }
            };

            var playLoad = await SendCommandToIotDevice(azureIoTCommand);

            return(View(playLoad));
        }
        public async Task <ActionResult> PostMyName(string myName)
        {
            var azureIoTCommand = new AzureIoTCommand
            {
                MethodName = "CommandFromCloud",
                ResponseTimeoutInSeconds = 200,
                PlayLoad = new PlayLoad
                {
                    Command = IoTCommandTypeEnum.ShowName,
                    Name    = myName,
                    Status  = "OK"
                }
            };

            var playLoad = await SendCommandToIotDevice(azureIoTCommand);

            return(View(playLoad));
        }
        public async Task <PlayLoad> SendCommandToIotDevice(AzureIoTCommand azureIoTCommand)
        {
            serviceClient = ServiceClient.CreateFromConnectionString(ConnectionString);

            var message          = JsonConvert.SerializeObject(azureIoTCommand);
            var methodInvocation = new CloudToDeviceMethod(azureIoTCommand.MethodName)
            {
                ResponseTimeout = TimeSpan.FromSeconds(30)
            };

            methodInvocation.SetPayloadJson(message);

            var response = await serviceClient.InvokeDeviceMethodAsync(deviceId, methodInvocation);

            string responseMessage = response.GetPayloadAsJson();
            var    playLoad        = JsonConvert.DeserializeObject <PlayLoad>(responseMessage);

            return(playLoad);
        }