Skip to content

Commit

Permalink
fix: add name for product
Browse files Browse the repository at this point in the history
  • Loading branch information
lsxredrain committed May 7, 2022
1 parent f42b28c commit 2d17dac
Showing 2 changed files with 9 additions and 9 deletions.
2 changes: 1 addition & 1 deletion apps/dgiot_device/src/dgiot_product.erl
Original file line number Diff line number Diff line change
@@ -97,7 +97,7 @@ to_frame(ProductId, Msg) ->
format_product(#{<<"objectId">> := ProductId} = Product) ->
Thing = maps:get(<<"thing">>, Product, #{}),
Props = maps:get(<<"properties">>, Thing, []),
Keys = [<<"ACL">>, <<"status">>, <<"nodeType">>, <<"dynamicReg">>, <<"topics">>, <<"productSecret">>],
Keys = [<<"ACL">>, <<"status">>, <<"name">>, <<"nodeType">>, <<"dynamicReg">>, <<"topics">>, <<"productSecret">>],
Map = maps:with(Keys, Product),
Map#{
<<"productId">> => ProductId,
16 changes: 8 additions & 8 deletions apps/dgiot_dlink/src/proctol/dgiot_mqtt_auth.erl
Original file line number Diff line number Diff line change
@@ -47,29 +47,29 @@ check(#{clientid := Token, username := UserId, password := Token}, AuthResult, #
%% 1、 尝试1型1密认证
%% 2、 尝试ClientID 为deviceID的1机1密认证
%% 3、 尝试ClientID 为deviceAddr的1机1密认证
check(#{clientid := <<ProductID:10/binary, "_", DevAddr/binary>>, username := ProductID, password := Password, peerhost := PeerHost}, AuthResult, #{hash_type := _HashType}) ->
%% io:format("~s ~p ProductID: ~p ClientId ~p Password ~p ~n", [?FILE, ?LINE, ProductID, ClientId, Password]),
DeviceId = dgiot_parse_id:get_deviceid(ProductID, DevAddr),
do_check(AuthResult, Password, ProductID, DevAddr, DeviceId, PeerHost);
check(#{clientid := <<ProductID:10/binary, "_", DeviceAddr/binary>>, username := ProductID, password := Password, peerhost := PeerHost}, AuthResult, #{hash_type := _HashType}) ->
io:format("~s ~p ProductID: ~p ClientId ~p Password ~p PeerHost ~p ~n", [?FILE, ?LINE, ProductID, DeviceAddr, Password,dgiot_utils:get_ip(PeerHost)]),
DeviceId = dgiot_parse_id:get_deviceid(ProductID, DeviceAddr),
do_check(AuthResult, Password, ProductID, DeviceAddr, DeviceId, dgiot_utils:get_ip(PeerHost));

check(#{clientid := DeviceAddr, username := ProductID, password := Password, peerhost := PeerHost}, AuthResult, #{hash_type := _HashType}) ->
%% io:format("~s ~p ProductID: ~p ClientId ~p Password ~p ~n", [?FILE, ?LINE, ProductID, ClientId, Password]),
io:format("~s ~p ProductID: ~p ClientId ~p Password ~p PeerHost ~p ~n", [?FILE, ?LINE, ProductID, DeviceAddr, Password,dgiot_utils:get_ip(PeerHost)]),
DeviceId = dgiot_parse_id:get_deviceid(ProductID, DeviceAddr),
do_check(AuthResult, Password, ProductID, DeviceAddr, DeviceId, PeerHost);
do_check(AuthResult, Password, ProductID, DeviceAddr, DeviceId, dgiot_utils:get_ip(PeerHost));

check(#{username := _Username}, AuthResult, _) ->
%% io:format("~s ~p Username: ~p~n", [?FILE, ?LINE, _Username]),
{stop, AuthResult#{anonymous => false, auth_result => password_error}}.

description() -> "Authentication with Mnesia".

do_check(AuthResult, Password, ProductID, DeviceAddr, DeviceId, PeerHost) ->
do_check(AuthResult, Password, ProductID, DeviceAddr, DeviceId, Ip) ->
case dgiot_product:lookup_prod(ProductID) of
{ok, #{<<"productSecret">> := Password, <<"ACL">> := Acl, <<"name">> := Name, <<"devType">> := DevType, <<"dynamicReg">> := true}} ->
case dgiot_device:lookup(DeviceId) of
{ok, _} ->
Device = #{
<<"ip">> => dgiot_utils:to_binary(PeerHost),
<<"ip">> => Ip,
<<"status">> => <<"ONLINE">>,
<<"brand">> => Name,
<<"devModel">> => DevType,

0 comments on commit 2d17dac

Please sign in to comment.