主要思路是通过小程序与设备之间蓝牙的连接来对设备进行注册配置。
主要流程如下
1、新设备注册流程
2、数据流转流程
前提:微信小程序做为设备后订阅/user/get
Topic
此设备为机载设备,所以需要包含所有需要上报的信息。
我定义的设备功能如下,物模型代码见附录。
因为微信作为设备时理论上不需要任何功能,所以我选择留空。
按照官方描述的SQL数据格式和数据流转过程系统Topic数据结构会被重构,所以这里在写SQL语句的时候需要注意一下。
最终我决定的SQL语句为
items.FatherDevice.value as TargetDevice,
items.GeoLocation.value as GeoLocation,
items.BatteryPercentage.value as BatteryPercentage,
items.CurrentVoltage.value as CurrentVoltage,
items.Attitude.value as Attitude,
items.Speed.value as Speed
FROM "/sys/${pk1}/+thing/event/property/post"
WHERE
最左边的终端为虚拟的小程序端,中间和右边为虚拟的机载模块,采用python API实现。
可以看到小程序端可以同时收到两个设备的信息且不用向物联网云平台发送信息。
{
"properties": [
{
"identifier": "GeoLocation",
"dataType": {
"specs": [
{
"identifier": "Longitude",
"dataType": {
"type": "double"
}
},
{
"identifier": "Latitude",
"dataType": {
"type": "double"
}
},
{
"identifier": "Altitude",
"dataType": {
"type": "double"
}
},
{
"identifier": "CoordinateSystem",
"dataType": {
"type": "enum"
}
}
],
"type": "struct"
}
},
{
"identifier": "BatteryPercentage",
"dataType": {
"type": "double"
}
},
{
"identifier": "Attitude",
"dataType": {
"specs": [
{
"identifier": "Yaw",
"dataType": {
"type": "double"
}
},
{
"identifier": "Roll",
"dataType": {
"type": "double"
}
},
{
"identifier": "Pitch",
"dataType": {
"type": "double"
}
}
],
"type": "struct"
}
},
{
"identifier": "Speed",
"dataType": {
"type": "float"
}
},
{
"identifier": "CurrentVoltage",
"dataType": {
"type": "double"
}
},
{
"identifier": "FatherDevice",
"dataType": {
"type": "text"
}
}
],
"events": [
{
"outputData": [
{
"identifier": "ErrorCode",
"dataType": {
"type": "enum"
}
}
],
"identifier": "Error",
"type": "error"
}
]
}