fix
This commit is contained in:
parent
aa05d062b6
commit
1eb246c43c
@ -324,7 +324,10 @@ handle_message(#{<<"method">> := <<"inform">>, <<"params">> := Info0}, State = #
|
|||||||
<<"version_copy">> => VersionCopy,
|
<<"version_copy">> => VersionCopy,
|
||||||
<<"status">> => Status,
|
<<"status">> => Status,
|
||||||
<<"created_at">> => At
|
<<"created_at">> => At
|
||||||
})
|
}),
|
||||||
|
|
||||||
|
%% TODO 需要更新微服务的状态
|
||||||
|
ok
|
||||||
end, ServiceInforms);
|
end, ServiceInforms);
|
||||||
Error ->
|
Error ->
|
||||||
lager:warning("[iot_host] inform error: ~p", [Error])
|
lager:warning("[iot_host] inform error: ~p", [Error])
|
||||||
|
|||||||
@ -192,6 +192,11 @@ handle_info({publish, #{payload := Payload, qos := Qos, topic := FromTopic}},
|
|||||||
|
|
||||||
%% 数据收集
|
%% 数据收集
|
||||||
% erlang:start_timer(?TICKER_INTERVAL + 1000, self(), data_ticker),
|
% erlang:start_timer(?TICKER_INTERVAL + 1000, self(), data_ticker),
|
||||||
|
|
||||||
|
%% 触发inform上传
|
||||||
|
erlang:start_timer(?TICKER_INTERVAL, self(), inform_ticker),
|
||||||
|
erlang:start_timer(?TICKER_INTERVAL, self(), feedback_ticker),
|
||||||
|
|
||||||
{noreply, State#state{aes = Aes}};
|
{noreply, State#state{aes = Aes}};
|
||||||
_ ->
|
_ ->
|
||||||
lager:debug("[host_mocker] auth failed")
|
lager:debug("[host_mocker] auth failed")
|
||||||
@ -259,6 +264,74 @@ handle_info({timeout, _, data_ticker}, State = #state{aes = Aes, topic = Topic})
|
|||||||
|
|
||||||
{noreply, State};
|
{noreply, State};
|
||||||
|
|
||||||
|
%% 上传微服务的inform信息
|
||||||
|
handle_info({timeout, _, inform_ticker}, State = #state{aes = Aes, topic = Topic}) ->
|
||||||
|
Info = jiffy:encode(#{
|
||||||
|
<<"at">> => iot_util:current_time(),
|
||||||
|
<<"services">> => [
|
||||||
|
#{
|
||||||
|
<<"scene_id">> => 1,
|
||||||
|
<<"name">> => <<"测试微服务"/utf8>>,
|
||||||
|
<<"version">> => <<"V1.0">>,
|
||||||
|
<<"version_copy">> => <<"CopyV1.0">>,
|
||||||
|
<<"status">> => 1
|
||||||
|
},
|
||||||
|
|
||||||
|
#{
|
||||||
|
<<"scene_id">> => 1,
|
||||||
|
<<"name">> => <<"水表"/utf8>>,
|
||||||
|
<<"version">> => <<"V1.0">>,
|
||||||
|
<<"version_copy">> => <<"CopyV1.0">>,
|
||||||
|
<<"status">> => 1
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}, [force_utf8]),
|
||||||
|
|
||||||
|
Msg = jiffy:encode(#{
|
||||||
|
<<"method">> => <<"inform">>,
|
||||||
|
<<"params">> => base64:encode(iot_cipher_aes:encrypt(Aes, Info))
|
||||||
|
}, [force_utf8]),
|
||||||
|
|
||||||
|
{ok, Ref} = iot_mqtt_publisher:publish(Topic, Msg, 1),
|
||||||
|
receive
|
||||||
|
{ok, Ref, PacketId} ->
|
||||||
|
lager:debug("[host_mocker] send inform success, packet_id: ~p", [PacketId]);
|
||||||
|
{error, Reason} ->
|
||||||
|
lager:debug("[host_mocker] send inform failed, reason: ~p", [Reason])
|
||||||
|
end,
|
||||||
|
|
||||||
|
erlang:start_timer(?TICKER_INTERVAL + 2000 + rand:uniform(5000), self(), data_ticker),
|
||||||
|
|
||||||
|
{noreply, State};
|
||||||
|
|
||||||
|
%% 上传微服务的feedback_result信息
|
||||||
|
handle_info({timeout, _, feedback_ticker}, State = #state{aes = Aes, topic = Topic}) ->
|
||||||
|
Info = jiffy:encode(#{
|
||||||
|
<<"task_id">> => 1,
|
||||||
|
<<"task_type">> => 2,
|
||||||
|
<<"code">> => 200,
|
||||||
|
<<"reason">> => <<"ok">>,
|
||||||
|
<<"error">> => <<"">>,
|
||||||
|
<<"created_at">> => iot_util:current_time()
|
||||||
|
}, [force_utf8]),
|
||||||
|
|
||||||
|
Msg = jiffy:encode(#{
|
||||||
|
<<"method">> => <<"feedback_result">>,
|
||||||
|
<<"params">> => base64:encode(iot_cipher_aes:encrypt(Aes, Info))
|
||||||
|
}, [force_utf8]),
|
||||||
|
|
||||||
|
{ok, Ref} = iot_mqtt_publisher:publish(Topic, Msg, 1),
|
||||||
|
receive
|
||||||
|
{ok, Ref, PacketId} ->
|
||||||
|
lager:debug("[host_mocker] send inform success, packet_id: ~p", [PacketId]);
|
||||||
|
{error, Reason} ->
|
||||||
|
lager:debug("[host_mocker] send inform failed, reason: ~p", [Reason])
|
||||||
|
end,
|
||||||
|
|
||||||
|
erlang:start_timer(?TICKER_INTERVAL + 2000 + rand:uniform(5000), self(), data_ticker),
|
||||||
|
|
||||||
|
{noreply, State};
|
||||||
|
|
||||||
%% 周期行的ping逻辑
|
%% 周期行的ping逻辑
|
||||||
handle_info({timeout, _, ping_ticker}, State = #state{aes = Aes, topic = Topic}) ->
|
handle_info({timeout, _, ping_ticker}, State = #state{aes = Aes, topic = Topic}) ->
|
||||||
Metric = jiffy:encode(#{
|
Metric = jiffy:encode(#{
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user