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
|
%% 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/#"
|
%% "$dg/thing/productid/devaddr/#"
|
||||||
do_check(#{clientid := DeviceAddr, username := ProductID} = _ClientInfo, publish, <<"$dg/thing/", ProductID:10/binary, "/", DeviceInfo/binary>> = _Topic) ->
|
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
|
deny
|
||||||
end;
|
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/#"
|
%% 用户订阅 "$dg/user/deviceid/#"
|
||||||
do_check(#{clientid := Token, username := UserId} = _ClientInfo, subscribe, <<"$dg/user/", DeviceID:10/binary, "/", _Rest/binary>> = _Topic)
|
do_check(#{clientid := Token, username := UserId} = _ClientInfo, subscribe, <<"$dg/user/", DeviceID:10/binary, "/", _Rest/binary>> = _Topic)
|
||||||
when UserId =/= undefined ->
|
when UserId =/= undefined ->
|
||||||
|
@ -48,12 +48,12 @@ check(#{clientid := Token, username := UserId, password := Token}, AuthResult, #
|
|||||||
%% 2、 尝试ClientID 为deviceID的1机1密认证
|
%% 2、 尝试ClientID 为deviceID的1机1密认证
|
||||||
%% 3、 尝试ClientID 为deviceAddr的1机1密认证
|
%% 3、 尝试ClientID 为deviceAddr的1机1密认证
|
||||||
check(#{clientid := <<ProductID:10/binary, "_", DeviceAddr/binary>>, username := ProductID, password := Password, peerhost := PeerHost}, AuthResult, #{hash_type := _HashType}) ->
|
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),
|
DeviceId = dgiot_parse_id:get_deviceid(ProductID, DeviceAddr),
|
||||||
do_check(AuthResult, Password, ProductID, DeviceAddr, DeviceId, dgiot_utils:get_ip(PeerHost));
|
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}) ->
|
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),
|
DeviceId = dgiot_parse_id:get_deviceid(ProductID, DeviceAddr),
|
||||||
do_check(AuthResult, Password, ProductID, DeviceAddr, DeviceId, dgiot_utils:get_ip(PeerHost));
|
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}} ->
|
{ok, #{<<"productSecret">> := Password, <<"ACL">> := Acl, <<"name">> := Name, <<"devType">> := DevType, <<"dynamicReg">> := true}} ->
|
||||||
case dgiot_device:lookup(DeviceId) of
|
case dgiot_device:lookup(DeviceId) of
|
||||||
{ok, _} ->
|
{ok, _} ->
|
||||||
|
pass;
|
||||||
|
_ ->
|
||||||
Device = #{
|
Device = #{
|
||||||
<<"ip">> => Ip,
|
<<"ip">> => Ip,
|
||||||
<<"status">> => <<"ONLINE">>,
|
<<"status">> => <<"ONLINE">>,
|
||||||
@ -78,9 +80,7 @@ do_check(AuthResult, Password, ProductID, DeviceAddr, DeviceId, Ip) ->
|
|||||||
<<"product">> => ProductID,
|
<<"product">> => ProductID,
|
||||||
<<"ACL">> => Acl
|
<<"ACL">> => Acl
|
||||||
},
|
},
|
||||||
dgiot_device:create_device(Device);
|
dgiot_device:create_device(Device)
|
||||||
_ ->
|
|
||||||
pass
|
|
||||||
end,
|
end,
|
||||||
{stop, AuthResult#{anonymous => false, auth_result => success}};
|
{stop, AuthResult#{anonymous => false, auth_result => success}};
|
||||||
_ ->
|
_ ->
|
||||||
|
@ -32,16 +32,15 @@ on_message_publish(Message = #message{topic = <<"$dg/thing/", Topic/binary>>, pa
|
|||||||
NewPayload =
|
NewPayload =
|
||||||
case jsx:is_json(Payload) of
|
case jsx:is_json(Payload) of
|
||||||
true ->
|
true ->
|
||||||
jiffy:decode(Payload);
|
jiffy:decode(Payload,[return_maps]);
|
||||||
false ->
|
false ->
|
||||||
Payload
|
Payload
|
||||||
end,
|
end,
|
||||||
|
io:format("~s ~p NewPayload: ~p~n", [?FILE, ?LINE, NewPayload]),
|
||||||
dgiot_dlink_proctol:properties_report(ProductId, DevAddr, NewPayload);
|
dgiot_dlink_proctol:properties_report(ProductId, DevAddr, NewPayload);
|
||||||
_ ->
|
_ ->
|
||||||
pass
|
pass
|
||||||
end,
|
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};
|
{ok, Message};
|
||||||
|
|
||||||
on_message_publish(Message, _State) ->
|
on_message_publish(Message, _State) ->
|
||||||
|
Loading…
Reference in New Issue
Block a user