diff --git a/apps/iot/src/iot_host.erl b/apps/iot/src/iot_host.erl index c3949d8..e84a695 100644 --- a/apps/iot/src/iot_host.erl +++ b/apps/iot/src/iot_host.erl @@ -131,11 +131,6 @@ remove_container(Pid, ContainerName) when is_pid(Pid), is_binary(ContainerName) EncCallBin = message_codec:encode(?MESSAGE_JSONRPC_REQUEST, Request), gen_statem:call(Pid, {jsonrpc_call, self(), EncCallBin}). -%-spec task_log(Pid :: pid(), TaskId :: integer()) -> {ok, Ref :: reference()} | {error, Reason :: any()}. -%task_log(Pid, TaskId) when is_pid(Pid), is_integer(TaskId) -> -% TaskLogBin = message_pb:encode_msg(#fetch_task_log{task_id = TaskId}), -% gen_statem:call(Pid, {jsonrpc_call, self(), ?PUSH_TASK_LOG, TaskLogBin}). - -spec await_reply(Ref :: reference(), Timeout :: integer()) -> {ok, Result :: binary()} | {error, Reason :: binary()}. await_reply(Ref, Timeout) when is_reference(Ref), is_integer(Timeout) -> receive @@ -314,7 +309,6 @@ handle_event({call, From}, {attach_channel, ChannelPid}, StateName, State = #sta erlang:monitor(process, ChannelPid), %% 更新主机为在线状态 ChangeResult = iot_api:change_host_status(UUID, ?HOST_ONLINE), - report_event(UUID, ?HOST_ONLINE), lager:debug("[iot_host] host_id(attach_channel) uuid: ~p, will change status, result: ~p", [UUID, ChangeResult]), {keep_state, State#state{channel_pid = ChannelPid, has_session = true}, [{reply, From, ok}]}; %% 主机未激活 @@ -412,8 +406,7 @@ handle_event(info, {timeout, _, heartbeat_ticker}, _, State = #state{uuid = UUID ?HOST_OFFLINE -> lager:debug("[iot_host] host: ~p, host_maybe_offline, host now is offline, do nothing", [UUID]); ?HOST_ONLINE -> - iot_api:change_host_status(UUID, ?HOST_OFFLINE), - report_event(UUID, ?HOST_OFFLINE) + iot_api:change_host_status(UUID, ?HOST_OFFLINE) end, %% 关闭channel,主机需要重新连接,才能保存状态的一致 @@ -463,26 +456,6 @@ get_route_key(<<"">>) -> get_route_key(RouteKey) when is_binary(RouteKey) -> RouteKey. --spec report_event(UUID :: binary(), NewStatus :: integer()) -> no_return(). -report_event(UUID, NewStatus) when is_binary(UUID), is_integer(NewStatus) -> - TextMap = #{ - 0 => <<"离线"/utf8>>, - 1 => <<"在线"/utf8>> - }, - - %% 设备的状态信息上报给中电 - Timestamp = iot_util:timestamp_of_seconds(), - FieldsList = [#{ - <<"key">> => <<"host_status">>, - <<"value">> => NewStatus, - <<"value_text">> => maps:get(NewStatus, TextMap), - <<"unit">> => 0, - <<"type">> => <<"DI">>, - <<"name">> => <<"主机状态"/utf8>>, - <<"timestamp">> => Timestamp - }], - lager:debug("[iot_host] host_uuid: ~p, route fields: ~p", [UUID, FieldsList]). - %% 将当前的state转换成map state_map(#state{host_id = HostId, uuid = UUID, has_session = HasSession, heartbeat_counter = HeartbeatCounter, channel_pid = ChannelPid, metrics = Metrics}) -> #{