- 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();
推薦閱讀
- 演進(jìn)式架構(gòu)(原書第2版)
- Mobile Web Performance Optimization
- JavaScript修煉之道
- Python數(shù)據(jù)分析基礎(chǔ)
- 單片機(jī)C語言程序設(shè)計(jì)實(shí)訓(xùn)100例:基于STC8051+Proteus仿真與實(shí)戰(zhàn)
- 深入理解Java7:核心技術(shù)與最佳實(shí)踐
- 人臉識(shí)別原理及算法:動(dòng)態(tài)人臉識(shí)別系統(tǒng)研究
- Nexus規(guī)模化Scrum框架
- 運(yùn)用后端技術(shù)處理業(yè)務(wù)邏輯(藍(lán)橋杯軟件大賽培訓(xùn)教材-Java方向)
- 移動(dòng)互聯(lián)網(wǎng)軟件開發(fā)實(shí)驗(yàn)指導(dǎo)
- 智能搜索和推薦系統(tǒng):原理、算法與應(yīng)用
- Developing SSRS Reports for Dynamics AX
- 邊玩邊學(xué)Scratch3.0少兒趣味編程
- Mastering Leap Motion
- Unity 3D UI Essentials