fix
This commit is contained in:
parent
627be12a6e
commit
748a4c2d9a
@ -247,7 +247,9 @@ handle_event({call, From}, {cancel_command_call, Ref}, _, State = #state{channel
|
||||
end;
|
||||
|
||||
%% 发送指令时, pub/sub
|
||||
handle_event({call, From}, {pub, Topic, Qos, Content}, ?STATE_ACTIVATED, State = #state{uuid = UUID, channel_pid = ChannelPid, has_session = HasSession}) ->
|
||||
handle_event({call, From}, {pub, Topic, Qos, Content}, StateName, State = #state{uuid = UUID, channel_pid = ChannelPid, has_session = HasSession}) ->
|
||||
case StateName of
|
||||
?STATE_ACTIVATED ->
|
||||
case HasSession andalso is_pid(ChannelPid) of
|
||||
true ->
|
||||
logger:debug("[iot_host] host: ~p, publish to topic: ~p, content: ~p", [UUID, Topic, Content]),
|
||||
@ -259,6 +261,9 @@ handle_event({call, From}, {pub, Topic, Qos, Content}, ?STATE_ACTIVATED, State =
|
||||
logger:debug("[iot_host] uuid: ~p, publish to topic: ~p, content: ~p, invalid state: ~p", [UUID, Topic, Content, state_map(State)]),
|
||||
{keep_state, State, [{reply, From, {error, <<"主机离线,发送失败"/utf8>>}}]}
|
||||
end;
|
||||
?STATE_DENIED ->
|
||||
{keep_state, State, [{reply, From, {error, <<"主机未激活,发送失败"/utf8>>}}]}
|
||||
end;
|
||||
|
||||
%% 激活/关闭授权只修改 iot 本地授权状态;efka 连接保持在线,数据是否处理由 host 状态决定。
|
||||
handle_event({call, From}, {activate, Auth}, _, State = #state{uuid = UUID}) ->
|
||||
|
||||
@ -84,8 +84,12 @@ handle_request("POST", "/host/pub", _, #{<<"uuid">> := UUID, <<"topic">> := Topi
|
||||
logger:debug("[host_handler] pub host_id: ~p, topic: ~p, failed with reason: ~p", [UUID, Topic, Reason]),
|
||||
{ok, 200, iot_util:json_error(400, <<"host not found">>)};
|
||||
{ok, Pid} when is_pid(Pid) ->
|
||||
ok = iot_host:pub(Pid, Topic, Qos, Content),
|
||||
{ok, 200, iot_util:json_data(<<"success">>)}
|
||||
case iot_host:pub(Pid, Topic, Qos, Content) of
|
||||
ok ->
|
||||
{ok, 200, iot_util:json_data(<<"success">>)};
|
||||
{error, Reason} ->
|
||||
{ok, 200, iot_util:json_error(400, Reason)}
|
||||
end
|
||||
end;
|
||||
|
||||
handle_request(_, Path, _, _) ->
|
||||
|
||||
@ -118,7 +118,6 @@ handle_heartbeat_packet(Packet, Peer) when is_binary(Packet) ->
|
||||
{ok, UUID, Timestamp, Payload, Mac} ->
|
||||
case efka_client_store:verify_heartbeat(UUID, Timestamp, Payload, Mac) of
|
||||
true ->
|
||||
logger:warning("[udp_server] heartbeat auth from peer: ~p, uuid: ~p", [Peer, UUID]),
|
||||
Pid = iot_host:get_pid(UUID),
|
||||
iot_host:heartbeat(Pid);
|
||||
false ->
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user