- Azure IoT Development Cookbook
- Yatish Patil
- 77字
- 2021-07-02 20:50:37
How to do it...
The following steps will be taken to perform a direct method with an IoT device connected with IoT Hub:
- Invoke this method from the application:
public async Task<CloudToDeviceMethodResult> InvokeDirectMethodOnDevice(string deviceId, ServiceClient serviceClient)
{
var methodInvocation = new CloudToDeviceMethod("WriteToMessage") { ResponseTimeout = TimeSpan.FromSeconds(300) };
methodInvocation.SetPayloadJson("'1234567890'");
var response = await serviceClient.InvokeDeviceMethodAsync(deviceId, methodInvocation);
return response;
}
- Direct method execution on the IoT device:
deviceClient = DeviceClient.CreateFromConnectionString("", TransportType.Mqtt);
deviceClient.SetMethodHandlerAsync("WriteToMessage", new DeviceSimulator().WriteToMessage, null).Wait();
deviceClient.SetMethodHandlerAsync("GetDeviceName", new DeviceSimulator().GetDeviceName, new DeviceData("DeviceClientMethodMqttSample")).Wait();
推薦閱讀
- VMware View Security Essentials
- 移動UI設計(微課版)
- Node.js:來一打 C++ 擴展
- Kotlin開發教程(全2冊)
- Visual Basic程序設計全程指南
- 軟件工程與UML案例解析(第三版)
- 百萬在線:大型游戲服務端開發
- JavaEE架構與程序設計
- Microsoft Dynamics GP 2013 Cookbook
- C語言程序設計教程
- JBoss AS 7 Development
- 精益軟件開發管理之道
- Getting Started with RethinkDB
- Responsive Web Design with HTML5 and CSS3(Second Edition)
- Java Web開發系統項目教程