"用户自定义topic"

This commit is contained in:
h7ml 2022-05-16 14:50:02 +08:00
parent 090692b88a
commit 4bfaee3ae3
2 changed files with 136 additions and 23 deletions

View File

@ -33,7 +33,7 @@ put('before', #{<<"id">> := DeviceId, <<"profile">> := Profile} = _Device) ->
{ok, #{<<"devaddr">> := Devaddr, <<"productid">> := ProductId}} ->
ProfileTopic =
case dgiot_product:lookup_prod(ProductId) of
{ok, #{<<"topics">> := #{<<"profile">> := ToipcTempl}}} ->
{ok, #{<<"topics">> := #{<<"device_profile">> := ToipcTempl}}} ->
Topic = re:replace(ToipcTempl, <<"{productId}">>, ProductId, [{return, binary}]),
re:replace(Topic, <<"{deviceAddr}">>, Devaddr, [{return, binary}]);
_ ->
@ -44,6 +44,7 @@ put('before', #{<<"id">> := DeviceId, <<"profile">> := Profile} = _Device) ->
pass
end;
put('after', #{<<"id">> := DeviceId, <<"profile">> := Profile}) ->
%% io:format("~s ~p DeviceId ~p Profile = ~p.~n", [?FILE, ?LINE, DeviceId, Profile]),
dgiot_data:insert(?DEVICE_PROFILE, DeviceId, Profile);
@ -66,4 +67,4 @@ publish(ProductId, DeviceAddr, Profile, Delay) ->
pass;
ChannelId ->
dgiot_channelx:do_message(ChannelId, {sync_profile, self(), ProductId, DeviceAddr, Profile, Delay})
end.
end.

View File

@ -1,34 +1,146 @@
{
"basic": [
{
"category": "OTA 升级",
"desc": "设备属性上报",
"category": "配置下发",
"desc": "配置下发",
"id": "device_profile",
"isdef": true,
"topic": "$dg/user/${deviceid}/post",
"subscribe": "设备",
"publisher": "平台",
"topic": "$dg/device/{productId}/{deviceAddr}/profile",
"type": "sub"
},
{
"category": "OTA 升级",
"desc": "消息下发",
"category": "属性上报",
"desc": "设备属性上报",
"id": "device_property_report",
"isdef": true,
"topic": "$dg/thing/${deviceid}/",
"type": "pub"
"subscribe": "平台",
"publisher": "设备",
"topic": "$dg/thing/{productId}/{deviceAddr}/properties/report",
"type": "sub"
},
{
"category": "告警上报",
"desc": "告警上报",
"id": "device_alarm_report",
"isdef": true,
"subscribe": "用户",
"publisher": "平台",
"topic": "$dg/alarm/{productId}/{deviceId}/properties/report",
"type": "sub"
},
{
"category": "组态消息",
"desc": "组态消息",
"id": "device_konva_report",
"isdef": true,
"subscribe": "用户",
"publisher": "平台",
"topic": "$dg/user/{DeviceId}/konva/report",
"type": "sub"
},
{
"category": "卡片消息",
"desc": "卡片消息",
"id": "device_realtimecard_report",
"isdef": true,
"subscribe": "用户",
"publisher": "平台",
"topic": "$dg/user/{DeviceId}/realtimecard/report",
"type": "sub"
},
{
"category": "子属性上报",
"desc": "子属性上报",
"id": "thing_sub_devices_report",
"isdef": true,
"subscribe": "平台",
"publisher": "设备",
"topic": "$dg/thing/{productId}/{deviceAddr}/gateway/sub_devices/properties/report",
"type": "sub"
},
{
"category": "子属性上报",
"desc": "子属性上报",
"id": "user_sub_devices_report",
"isdef": true,
"subscribe": "用户",
"publisher": "平台",
"topic": "$dg/user/{deviceId}/gateway/sub_devices/properties/report",
"type": "sub"
},
{
"category": "属性设置",
"desc": "属性设置",
"id": "thing_properties_set",
"isdef": true,
"subscribe": "平台",
"publisher": "用户",
"topic": "$dg/thing/{deviceId}/properties/set/request_id={request_id}",
"type": "sub"
},
{
"category": "属性设置",
"desc": "属性设置",
"id": "device_properties_set",
"isdef": true,
"publisher": "平台",
"subscribe": "设备",
"topic": "$dg/device/{productId}/{deviceAddr}/properties/set/request_id={request_id}",
"type": "sub"
},
{
"category": "属性设置",
"desc": "属性设置",
"id": "thing_properties_set",
"isdef": true,
"publisher": "设备",
"subscribe": "平台",
"topic": "$dg/thing/{productId}/{deviceAddr}/properties/set/request_id={request_id}",
"type": "sub"
},
{
"category": "属性设置",
"desc": "属性设置",
"id": "user_properties_set",
"isdef": true,
"publisher": "平台",
"subscribe": "用户",
"topic": "$dg/user/{deviceId}/properties/set/request_id={request_id}",
"type": "sub"
},
{
"category": "属性获取",
"desc": "属性获取",
"id": "thing_properties_get",
"isdef": true,
"publisher": "用户",
"subscribe": "平台",
"topic": "$dg/thing/{deviceId}/properties/get/request_id={request_id}",
"type": "sub"
},
{
"category": "属性获取",
"desc": "属性获取",
"id": "device_properties_get",
"isdef": true,
"publisher": "平台",
"subscribe": "设备",
"topic": "$dg/device/{productId}/{deviceAddr}/properties/get/response/request_id={request_id}",
"type": "sub"
},
{
"category": "属性获取",
"desc": "属性获取",
"id": "thing_properties_get",
"isdef": true,
"publisher": "设备",
"subscribe": "平台",
"topic": "$dg/thing/{productId}/{deviceAddr}/properties/get/response/request_id={request_id}",
"type": "sub"
}
],
"thing": [
{
"category": "属性上报",
"desc": "设备属性上报",
"isdef": true,
"topic": "$dg/user/${deviceid}/post",
"type": "sub'"
},
{
"category": "属性上报",
"desc": "消息下发",
"isdef": true,
"topic": "$dg/thing/${deviceid}/",
"type": "pub"
}
]
}