private static void createAsyncCommand(IoTDAClient client) { CreateAsyncCommandRequest req = new CreateAsyncCommandRequest { InstanceId = "1a7ffc5c-d89c-44dd-8265-b1653d951ce0", DeviceId = "5eeb1fefbc61700402bc35f9_1211211", Body = new AsyncDeviceCommandRequest() { SendStrategy = "immediately", CommandName = "ON_OFF", Paras = JObject.Parse("{\"value\":\"ON\"}") } }; try { var resp = client.CreateAsyncCommand(req); Console.WriteLine(resp); } catch (RequestTimeoutException requestTimeoutException) { Console.WriteLine(requestTimeoutException.ErrorMessage); } catch (ServiceResponseException clientRequestException) { Console.WriteLine(clientRequestException.HttpStatusCode); Console.WriteLine(clientRequestException.ErrorCode); Console.WriteLine(clientRequestException.ErrorMsg); } catch (ConnectionException connectionException) { Console.WriteLine(connectionException.ErrorMessage); } }
/// <summary> /// 下发异步设备命令 /// </summary> public async Task <CreateAsyncCommandResponse> CreateAsyncCommandAsync(CreateAsyncCommandRequest createAsyncCommandRequest) { Dictionary <string, string> urlParam = new Dictionary <string, string>(); urlParam.Add("device_id", createAsyncCommandRequest.DeviceId.ToString()); string urlPath = HttpUtils.AddUrlPath("/v5/iot/{project_id}/devices/{device_id}/async-commands", urlParam); SdkRequest request = HttpUtils.InitSdkRequest(urlPath, "application/json", createAsyncCommandRequest); HttpResponseMessage response = await DoHttpRequestAsync("POST", request); return(JsonUtils.DeSerialize <CreateAsyncCommandResponse>(response)); }