fix: login failed

This commit is contained in:
jhonliu 2022-05-24 16:17:56 +08:00
parent fd8088afc1
commit 177dc0ee8d
2 changed files with 12 additions and 4 deletions

View File

@ -41,9 +41,9 @@ init([#{<<"channel">> := ChannelId, <<"client">> := ClientId, <<"ip">> := Host,
Dclient = #dclient{channel = ChannelId, client = ClientId, status = ?DCLIENT_INTIALIZED, clock = Clock, userdata = UserData, child = ChildState},
dgiot_client:add(ChannelId, ClientId),
case Mod:init(Dclient) of
{ok, NewDclient} ->
do_connect(NewDclient),
{ok, NewDclient, hibernate};
{ok, NewChildState} ->
do_connect(Dclient#dclient{child = NewChildState}),
{ok, Dclient#dclient{child = NewChildState}, hibernate};
{stop, Reason} ->
{stop, Reason}
end.

View File

@ -25,6 +25,14 @@
-export([init/1, handle_info/2, terminate/2]).
%% tcp client callback
init(#dclient{channel = ChannelId, child = #child_state{} = ChildState}) ->
case dgiot_product:get_channel(ChannelId) of
not_find ->
{stop, <<"not find product">>};
ProductId ->
io:format("~s ~p ~p ~p ~n", [?FILE, ?LINE, ChannelId, ProductId]),
{ok, ChildState#child_state{product = ProductId}}
end;
init(#dclient{channel = ChannelId}) ->
case dgiot_product:get_channel(ChannelId) of
not_find ->
@ -46,7 +54,7 @@ handle_info(connection_ready, #dclient{child = #child_state{product = ProductId}
{noreply, ChildState#child_state{device = Device}}
end;
handle_info(#{<<"cmd">> := Cmd, <<"data">> := Data, <<"productId">> := ProductId}, #dclient{child = ChildState} = Dclient) ->
handle_info(#{<<"cmd">> := Cmd, <<"data">> := Data, <<"productId">> := ProductId}, #dclient{child = #child_state{} = ChildState} = Dclient) ->
case do_cmd(ProductId, Cmd, Data, Dclient) of
default ->
{noreply, ChildState};