Skip to content

Commit

Permalink
feat: mqtt bridge
Browse files Browse the repository at this point in the history
  • Loading branch information
dawnwinterLiu committed Oct 18, 2023
1 parent f5ffeaa commit 930dc73
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 0 deletions.
1 change: 1 addition & 0 deletions apps/dgiot_bridge/src/channel/dgiot_mqttc_worker.erl
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ handle_info(disconnect, #dclient{channel = ChannelId} = State) ->
handle_info({sub, Client, ProductId, DevAddr}, State) ->
emqtt:subscribe(Client, {<<"$dg/device/", ProductId/binary, "/", DevAddr/binary, "/#">>, 1}), % cloud to edge
dgiot_mqtt:subscribe(<<"edge2cloud/#">>), % edge to cloud
emqtt:subscribe(Client, {<<"$dg/thing/", ProductId/binary, "/", DevAddr/binary, "/#">>, 1}), % cloud to edge
{noreply, State};

%% #{client_pid => <0.11482.0>, dup => false, packet_id => undefined, payload => <<"{ \"msg\": \"Hello, World!\" }">>, topic =><<"$dg/device/5392ccb3d7/00E0B45BFB4F_usb6-ai15/test">>, properties => undefined,qos => 0, retain => false}
Expand Down
8 changes: 8 additions & 0 deletions apps/dgiot_dlink/src/proctol/dgiot_mqtt_acl.erl
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,14 @@ do_check(#{clientid := Token, username := UserId} = _ClientInfo, publish, <<"$dg
deny
end;

%%"$dg/thing/productid/devaddr/#"
do_check(#{clientid := <<ProductID:10/binary, "_", DeviceAddr/binary>>, username := ProductID} = _ClientInfo, subscribe, <<"$dg/thing/", ProductID:10/binary, "/", DeviceInfo/binary>> = _Topic) ->
check_device_addr(DeviceInfo, DeviceAddr);

do_check(#{clientid := DeviceAddr, username := ProductID} = _ClientInfo, subscribe, <<"$dg/thing/", ProductID:10/binary, "/", DeviceInfo/binary>> = _Topic) ->
%% io:format("~s ~p Topic: ~p _ClientInfo ~p~n", [?FILE, ?LINE, _Topic, _ClientInfo]),
check_device_addr(DeviceInfo, DeviceAddr);

%%"$dg/device/productid/devaddr/#"
do_check(#{clientid := <<ProductID:10/binary, "_", DeviceAddr/binary>>, username := ProductID} = _ClientInfo, subscribe, <<"$dg/device/", ProductID:10/binary, "/", DeviceInfo/binary>> = _Topic) ->
check_device_addr(DeviceInfo, DeviceAddr);
Expand Down
1 change: 1 addition & 0 deletions apps/dgiot_dlink/src/proctol/dgiot_mqtt_message.erl
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ on_message_publish(Message = #message{topic = <<"$dg/thing/", Topic/binary>>, pa
_ ->
pass
end,
dgiot_mqttc_channel:send(ProductId, DevAddr, <<"$dg/thing/", Topic/binary>>, Payload),
dgiot_dlink_proctol:properties_report(ProductId, DevAddr, get_payload(Payload));
[ProductId, DevAddr, <<"report">>] ->
%% 属性获取 $dg/thing/{productId}/{deviceAddr}/properties/report 设备 => 平台
Expand Down

0 comments on commit 930dc73

Please sign in to comment.