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