上线设备
为了启动设备与 MindSphere 之间的通信,必须将设备上线到 MindSphere。Open Edge Device Kit 作为一个代理连接设备到 MindSphere。该部分描述建立到 MindSphere 连接的必要步骤。
在 MindSphere 中注册设备
- 使用Asset Management Service或者Asset Manager为设备将要上载的数据创建一个 aspect 类型。
- 使用前面定义的 aspect 类型 创建 asset type,并使用 Asset Management Service 或 Asset Manager 实例化 asset。
- 使用Device Management Service创建设备类型并将它链接到前面定义的 asset type。
- 使用 Device Management Service 创建设备并将其链接到前面定义的 asset。
-
使用 Asset Manager 下载上线配置文件。该文件包含必要的安全授权值,以便将其上线到设备上。
上线配置模板
{ "header": { "version": "0.1", "generationTimeServer": "<server_time>" }, "device": { "deviceIdentifier": "<device_id>" }, "agent": { "name": "<agent_name>", "proxy": { "proxyType": "FIXED", "host": "<proxy_host>:<proxy_port>", "protocol": "HTTP", "authenticationType": "BASIC", "user": "", "password": "" }, "agentId": "<agent_id>", "security": { "iat": "<Iat_value>", "baseUrl": "<mdsp_base_url>", "clientCredentialProfile": ["RSA_3072"], "tenant": "<mdsp_tenant_name>", "clientId": "<client_id>" } } }
使用 Open Edge Device Kit 上线设备
Open Edge Device Kit 包含一个内置的运算以上线设备。这个运算是通过使用以下主题通过 MQTT 发布上线配置开始的:
agentruntime/controlling/command/init
代码示例
-
建立到 MQTT 代理的连接,其中
<mqtt_host>
是主机名称,<mqt_port>
是端口:String broker = String.format("tcp://%s:%d", <mqtt_host>, <mqt_port>); MqttClient mqttClient = new MqttClient(broker, "MQTTClientID"); mqttClient.connect();
-
发布上线配置文件到 Open Edge Device Kit:
String topic = "agentruntime/controlling/command/init"; mqttClient.publish(topic, initFileJsonContent.getBytes(StandardCharsets.ISO_8859_1));
上线日志消息
下面的日志消息显示了使用 Open Edge Device Kit 成功进行上线操作的日志:
2019-02-22 11:09:14,584 [DIAG] HandlerThread_11 | c.s.m.a.d.DiagnosticService | Agent onboarded successfully.
2019-02-22 11:09:14,584 [IN] HandlerThread_11 | c.s.m.a.d.DiagnosticService | inform() : DiagnosticEventMessage = <{"value":1,"state":"Onboarded"}>
2019-02-22 11:09:14,584 [IN] HandlerThread_11 | c.s.m.a.s.h.MessageHandlerBase | Publishing a message to MQTT Broker for topic <agentruntime/monitoring/diagnostic/onboarding>
2019-02-22 11:09:14,584 [IN] HandlerThread_11 | c.s.m.a.s.h.MessageHandlerBase | Message being published is <{"value":1,"state":"Onboarded"}>
2019-02-22 11:09:14,584 [IN] HandlerThread_11 | c.s.m.a.s.c.MqttBrokerClient | Publishing a message to MQTT broker for topic = <agentruntime/monitoring/diagnostic/onboarding>
信息
上线成功之后,Asset Manager 中设备的指示器状态应该是绿色。
时间同步
在上线之前,用户负责将设备的系统时间与 MindSphere 匹配。这可以使用上线配置中的 generationTimeServer
字段来完成。这陈述了上线配置的 MindSphere 创建时间,并且为 Zulu 时间格式(例如:2018-09-18T10:09:36Z
):
{
"header": {
"version": "0.1",
"generationTimeServer": "<server_time>"
},
...
}
还有问题?
除非另行声明,该网站内容遵循MindSphere开发许可协议.
Last update: June 26, 2019