mirror of
https://gitee.com/dgiiot/dgiot.git
synced 2024-12-02 12:18:30 +08:00
fix: create device error
This commit is contained in:
parent
8a5723f1c4
commit
8a36220632
@ -38,13 +38,6 @@ description() -> "Acl with Dlink".
|
||||
%%--------------------------------------------------------------------
|
||||
%% Internal functions
|
||||
%%-------------------------------------------------------------------
|
||||
%%"$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);
|
||||
|
||||
do_check(#{clientid := DeviceAddr, username := ProductID} = _ClientInfo, subscribe, <<"$dg/device/", 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/thing/productid/devaddr/#"
|
||||
do_check(#{clientid := DeviceAddr, username := ProductID} = _ClientInfo, publish, <<"$dg/thing/", ProductID:10/binary, "/", DeviceInfo/binary>> = _Topic) ->
|
||||
@ -65,6 +58,14 @@ do_check(#{clientid := Token, username := UserId} = _ClientInfo, publish, <<"$dg
|
||||
deny
|
||||
end;
|
||||
|
||||
%%"$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);
|
||||
|
||||
do_check(#{clientid := DeviceAddr, username := ProductID} = _ClientInfo, subscribe, <<"$dg/device/", 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/user/deviceid/#"
|
||||
do_check(#{clientid := Token, username := UserId} = _ClientInfo, subscribe, <<"$dg/user/", DeviceID:10/binary, "/", _Rest/binary>> = _Topic)
|
||||
when UserId =/= undefined ->
|
||||
|
@ -48,12 +48,12 @@ check(#{clientid := Token, username := UserId, password := Token}, AuthResult, #
|
||||
%% 2、 尝试ClientID 为deviceID的1机1密认证
|
||||
%% 3、 尝试ClientID 为deviceAddr的1机1密认证
|
||||
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)]),
|
||||
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 PeerHost ~p ~n", [?FILE, ?LINE, ProductID, DeviceAddr, Password,dgiot_utils:get_ip(PeerHost)]),
|
||||
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));
|
||||
|
||||
@ -68,6 +68,8 @@ do_check(AuthResult, Password, ProductID, DeviceAddr, DeviceId, Ip) ->
|
||||
{ok, #{<<"productSecret">> := Password, <<"ACL">> := Acl, <<"name">> := Name, <<"devType">> := DevType, <<"dynamicReg">> := true}} ->
|
||||
case dgiot_device:lookup(DeviceId) of
|
||||
{ok, _} ->
|
||||
pass;
|
||||
_ ->
|
||||
Device = #{
|
||||
<<"ip">> => Ip,
|
||||
<<"status">> => <<"ONLINE">>,
|
||||
@ -78,9 +80,7 @@ do_check(AuthResult, Password, ProductID, DeviceAddr, DeviceId, Ip) ->
|
||||
<<"product">> => ProductID,
|
||||
<<"ACL">> => Acl
|
||||
},
|
||||
dgiot_device:create_device(Device);
|
||||
_ ->
|
||||
pass
|
||||
dgiot_device:create_device(Device)
|
||||
end,
|
||||
{stop, AuthResult#{anonymous => false, auth_result => success}};
|
||||
_ ->
|
||||
|
@ -32,16 +32,15 @@ on_message_publish(Message = #message{topic = <<"$dg/thing/", Topic/binary>>, pa
|
||||
NewPayload =
|
||||
case jsx:is_json(Payload) of
|
||||
true ->
|
||||
jiffy:decode(Payload);
|
||||
jiffy:decode(Payload,[return_maps]);
|
||||
false ->
|
||||
Payload
|
||||
end,
|
||||
io:format("~s ~p NewPayload: ~p~n", [?FILE, ?LINE, NewPayload]),
|
||||
dgiot_dlink_proctol:properties_report(ProductId, DevAddr, NewPayload);
|
||||
_ ->
|
||||
pass
|
||||
end,
|
||||
%% io:format("~s ~p Topic: ~p Username ~p ~n", [?FILE, ?LINE, Topic, Headers]),
|
||||
io:format("~s ~p Payload: ~p ~n", [?FILE, ?LINE, Payload]),
|
||||
{ok, Message};
|
||||
|
||||
on_message_publish(Message, _State) ->
|
||||
|
Loading…
Reference in New Issue
Block a user