Merge pull request #544 from dgiot/yanliubao

fix:online_status
This commit is contained in:
dawnwinterLiu 2022-08-11 11:07:52 +08:00 committed by GitHub
commit 9a490cfc8e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 17 additions and 20 deletions

View File

@ -79,7 +79,10 @@ do_check(AuthResult, Password, ProductID, DeviceAddr, DeviceId, Ip) ->
{ok, #{<<"productSecret">> := Password} = Product} ->
case dgiot_device:lookup(DeviceId) of
{ok, _} ->
pass;
Body = #{
<<"status">> => <<"ONLINE">>},
dgiot_device:online(DeviceId),
dgiot_parse:update_object(<<"Device">>, DeviceId, Body);
_ ->
case Product of
#{<<"ACL">> := Acl, <<"name">> := Name, <<"devType">> := DevType, <<"dynamicReg">> := true} ->

View File

@ -173,25 +173,19 @@ get_deviceid(ProdcutId, DevAddr) ->
create_device(DeviceId, ProductId, DTUMAC, DTUIP, Dtutype) ->
case dgiot_product:lookup_prod(ProductId) of
{ok, #{<<"ACL">> := Acl, <<"devType">> := DevType}} ->
case dgiot_parse:get_object(<<"Device">>, DeviceId) of
{ok, #{<<"devaddr">> := _GWAddr}} ->
dgiot_parse:update_object(<<"Device">>, DeviceId, #{<<"ip">> => DTUIP, <<"status">> => <<"ONLINE">>}),
dgiot_task:save_pnque(ProductId, DTUMAC, ProductId, DTUMAC);
_ ->
dgiot_device:create_device(#{
<<"devaddr">> => DTUMAC,
<<"name">> => <<Dtutype/binary, DTUMAC/binary>>,
<<"ip">> => DTUIP,
<<"isEnable">> => true,
<<"product">> => ProductId,
<<"ACL">> => Acl,
<<"status">> => <<"ONLINE">>,
<<"location">> => #{<<"__type">> => <<"GeoPoint">>, <<"longitude">> => 120.161324, <<"latitude">> => 30.262441},
<<"brand">> => Dtutype,
<<"devModel">> => DevType
}),
dgiot_task:save_pnque(ProductId, DTUMAC, ProductId, DTUMAC)
end,
dgiot_device:create_device(#{
<<"devaddr">> => DTUMAC,
<<"name">> => <<Dtutype/binary, DTUMAC/binary>>,
<<"ip">> => DTUIP,
<<"isEnable">> => true,
<<"product">> => ProductId,
<<"ACL">> => Acl,
<<"status">> => <<"ONLINE">>,
<<"location">> => #{<<"__type">> => <<"GeoPoint">>, <<"longitude">> => 120.161324, <<"latitude">> => 30.262441},
<<"brand">> => Dtutype,
<<"devModel">> => DevType
}),
dgiot_task:save_pnque(ProductId, DTUMAC, ProductId, DTUMAC),
Productname =
case dgiot_parse:get_object(<<"Product">>, ProductId) of
{ok, #{<<"name">> := Productname1}} ->