1、通过通过IoT HubIoT Hub对设备进行全生命周期管理对设备进行全生命周期管理规划部署配置监控淘汰按照企业需求对设备进行分组通过身份验证确保设备安全考虑如何大规模部署为设备提供在线更新、远程更改配置参数等能力监控设备健康状况,及时发现潜在问题当设备出现故障或者超过服务周期以后,考虑对其进行更换IoT Hub 设备管理功能点Device Twin在IoT Hub和设备之间同步设备属性Queries查询Device Twin并返回设备状态及配置信息Direct Methods通过IoT Hub直接操作设备中定义的方法Jobs对设备进行大规模计划性的操作设备端App后端应用Device twi
2、nPropertiesDesiredReportedTags读,写读,写读读,接收变更通知读,写IoT Hub设备端AppBack endDevice twinPropertiesDesiredReportedTagsRead,writeRead,writeRead读,接收变更通知读,写IoT Hub场景:设备配置更新T1Device1 twinDesired StateDesired StateReported StateReported StateSendFrequency:-State:InitializingT2Device1 twinDesired StateDesired Stat
3、eSendFrequency:50005000Reported StateReported StateSendFrequency:-State:InitializingT3Device1 twinDesired StateSendFrequency:5000Reported StateID:Device1SendFrequency:50005000State:ActiveActiveDevice1Device1SendFrequency:-State:InitializingIoT HubIoT HubIoT HubDevice1Device1SendFrequency:-State:Init
4、ializingDevice1Device1SendFrequency:50005000State:Active后端 App12345678时间轴Device Twin Queries位于位于US且发送频率低于每分钟一次的设备且发送频率低于每分钟一次的设备SELECT*FROM devices WHERE tags.location.region=US AND properties.reported.telemetryConfig.sendFrequencyInSecs=60支持支持wifi 或有线网络连接的设备或有线网络连接的设备SELECT*FROM devices WHERE prope
5、rties.reported.connectivity IN wired,wifiReported properties 和和 desired properties 不一致的设备不一致的设备SELECT*FROM devices WHERE properties.reported.firmwareVersion properties.desired.firmwareVersion按照设备上报状态进行分组并统计总和按照设备上报状态进行分组并统计总和SELECT properties.reported.deviceStatus AS status,COUNT()AS numberOfDevices
6、 FROM devices GROUP BY properties.reported.deviceStatusDemo:Device Twin&Query物理设备IoT HubIoT Hub Direct Method后端应用Invoke MethodDevice method handlerRequestResponseResponse1 12 23 34 41.1.Http Post RequestHttp Post Request:Uri:iot hub/twins/device id/methods/Header:authorization,request id,content typ
7、e,content encodingBody:methodName:reboot,timeoutInSeconds:60,payload:input1:someInput“4.Http Response4.Http Response:HttpStatusCode:200,404,500Body:status:200,payload:.MQTT topicRequest2.Device Request2.Device Request:$iothub/methods/POST/method name/?$rid=request id3.Device ResponseDevice Response:
8、$iothub/methods/res/status/?$rid=request idIoT Hub Direct Method(未连接设备)物理设备IoT Hub后端应用Invoke MethodDevice method handlerDevice Device DisconnectedDisconnectedRequestResponse1 12 22.Http Response2.Http Response:HttpStatusCode:404Body:Demo:通过Direct Method远程重启设备后端 App设备端 AppIoT HubIoT Hub通过Device Twin和
9、Direct Methods管理设备C2DD2CDevice TwinDirect Methods传感器数据云端发起的C2D消息Properties云端发起Direct Methods调用并立即收到响应Properties由云端管理/设备可读由设备管理/云端可读由云端管理设备的元数据Methods读/写读读/写读/接收通知C2D 场景建议Direct methodsTwins Desired PropertiesC2D 消息消息场景需要立即收到确认的命令及时性要求不高的命令单向通知设备消息大小8KB requests/8KB responses.最大 8KB最大256KB频率高中低Jobs 创
10、建创建Jobs Http PUT:iot hub/jobs/v2/?api-version=2016-09-30-previewBody:type:scheduleDeviceMethod,methodName:,queryCondition:,maxExecutionTimeInSecondsor type:scheduleTwinUpdate,updateTwin:,queryCondition:,maxExecutionTimeInSeconds 跟踪进度跟踪进度(query)Http GET/jobs/v2/query?api-version=2016-09-30-preview&jo
11、bType=&jobStatus=&pageSize=&continuationToken=Job 的属性的属性 jobIdstartTime endTime typestatusdeviceJobStatisticsIoT Hub通过Job调度device twin更新后端应用ScheduleTwinUpdate JobId DeviceQueryCondition TwinPatch StartTime(TStart)MaxTimeExecution1 1Device twinDevice 1Properties.DesiredDataJobUpdateT0TStart2 2物理设备Dev
12、ice 1Twin changed handlerDevice Twin 更新事件(当设备处于连接状态时进行)3 3IoT Hub通过Job调用Direct methods后端应用ScheduleDeviceMethod JobId MethodType/Params DeviceQueryCondition StartTime(TStart)MaxTimeExecution1 1JobInvoke Device MethodT02 2物理设备Device 1Device method handlerTStart*时间点调用Device Method 3 3*设备必须处于正常连接状态,否则Io
13、T Hub会立即返回设备未连接Device Method 返回响应IoT Hub通过Jobs和Queries进行管理调度Device Twin/Methods物理设备Device Twin/MethodsDevice Twin/MethodsDevice Twin/MethodsDevice Twin/MethodsDevice Twin/MethodsDevice Twin/MethodsDevice Twin/MethodsDevice Twin/MethodsDevice Twin/MethodsDevice Twin/MethodsDevice Twin/MethodsDevice T
14、win/MethodsDevice Twin/MethodsDevice Twin/MethodsDevice Twin/MethodsJobs调度Device Twin的变更设定Desired Properties,Tags,并调用Direct MethodsQueries 类似SQL查询查询Device Twin状态满足不同业务逻辑,为设备管理提供报表设备端App后端应用场景:设备固件更新Device twinReportedIoT Hub发起FW UpdateFW Update HandlerDirect Method Request/Response12下载镜像&更新状态应用镜像&更新状态重启&重新连接查询并更新仪表盘4查询并更新仪表盘356DownloadingUpdatingReboot