From 3d8fccd0dc26981cf4de268b071cded8b5f60365 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=AE=89=E7=A4=BC=E6=88=90?= Date: Thu, 30 Mar 2023 20:33:58 +0800 Subject: [PATCH] fix --- apps/iot/src/iot_emqtt_client.erl | 2 +- apps/iot/src/iot_host.erl | 11 ++++++----- config/sys.config | 6 +++--- 3 files changed, 10 insertions(+), 9 deletions(-) diff --git a/apps/iot/src/iot_emqtt_client.erl b/apps/iot/src/iot_emqtt_client.erl index 744b8fa..95e8329 100644 --- a/apps/iot/src/iot_emqtt_client.erl +++ b/apps/iot/src/iot_emqtt_client.erl @@ -49,7 +49,7 @@ start_link() -> {stop, Reason :: term()} | ignore). init([]) -> %{ok, ServerOpts} = application:get_env(iot, emqx_server), - {ok, ConnPid} = emqtt:start_link([{clientid, iot_emqtt_client}, {owner, self()}|ServerOpts]), + % {ok, ConnPid} = emqtt:start_link([{clientid, iot_emqtt_client}, {owner, self()}|ServerOpts]), %{ok, _Props} = emqtt:connect(ConnPid), %SubOpts = [{qos, 1}], diff --git a/apps/iot/src/iot_host.erl b/apps/iot/src/iot_host.erl index ee16f25..4c62d20 100644 --- a/apps/iot/src/iot_host.erl +++ b/apps/iot/src/iot_host.erl @@ -52,19 +52,20 @@ init([Host]) -> lager:debug("[iot_host] host is: ~p", [Host]), %% 建立到emqx服务器的连接 {ok, Props} = application:get_env(iot, emqx_server), - Host = proplists:get_value(host, Props), - Port = proplists:get_value(port, Props, 18080), + EMQXHost = proplists:get_value(host, Props), + EMQXPort = proplists:get_value(port, Props, 18080), Username = proplists:get_value(username, Props), Password = proplists:get_value(password, Props), RetryInterval = proplists:get_value(retry_interval, Props, 5), + Keepalive = proplists:get_value(keepalive, Props, 86400), Opts = [ - {host, Host}, - {port, Port}, + {host, EMQXHost}, + {port, EMQXPort}, {owner, self()}, {tcp_opts, []}, {username, Username}, {password, Password}, - {keepalive, 'Keepalive'}, + {keepalive, Keepalive}, {retry_interval, RetryInterval} ], diff --git a/config/sys.config b/config/sys.config index 8d48f49..757d194 100644 --- a/config/sys.config +++ b/config/sys.config @@ -9,12 +9,12 @@ %% 目标服务器地址 {emqx_server, [ - {host, "103.113.157.7"}, - {port, 18080}, + {host, {103, 113, 157, 7}}, + {port, 1883}, {tcp_opts, []}, {username, "test"}, {password, "test1234"}, - {keepalive, 'Keepalive'}, + {keepalive, 86400}, {retry_interval, 5} ]}