From 20f9cf19cd0944e0991ba34d54c63afc10f40980 Mon Sep 17 00:00:00 2001 From: lafirest Date: Thu, 12 Aug 2021 18:52:34 +0800 Subject: [PATCH] fix(emqx_gateway): fix some error in README and code --- apps/emqx_gateway/etc/emqx_gateway.conf | 18 ++++----- apps/emqx_gateway/src/coap/README.md | 40 ++++++++++--------- .../src/coap/emqx_coap_channel.erl | 6 +-- .../src/coap/emqx_coap_session.erl | 6 +-- 4 files changed, 36 insertions(+), 34 deletions(-) diff --git a/apps/emqx_gateway/etc/emqx_gateway.conf b/apps/emqx_gateway/etc/emqx_gateway.conf index 6c7928174..8c77fe652 100644 --- a/apps/emqx_gateway/etc/emqx_gateway.conf +++ b/apps/emqx_gateway/etc/emqx_gateway.conf @@ -38,7 +38,7 @@ gateway: { } coap.1: { - enable_stats: false + enable_stats: false authentication: { enable: true @@ -52,16 +52,16 @@ gateway: { ] } - #authentication.enable: false + #authentication.enable: false - heartbeat: 30s - notify_type: qos - subscribe_qos: qos0 - publish_qos: qos1 - listener.udp.1: { - bind: 5683 + heartbeat: 30s + notify_type: qos + subscribe_qos: qos0 + publish_qos: qos1 + listener.udp.1: { + bind: 5683 } - } + } mqttsn.1: { ## The MQTT-SN Gateway ID in ADVERTISE message. diff --git a/apps/emqx_gateway/src/coap/README.md b/apps/emqx_gateway/src/coap/README.md index c451d6533..12b5ac5b7 100644 --- a/apps/emqx_gateway/src/coap/README.md +++ b/apps/emqx_gateway/src/coap/README.md @@ -108,10 +108,10 @@ The server manages the client through the ClientId. If the ClientId is wrong, EM 1. Create a Connection Method: POST - URI Schema: mqtt/{+topic}{?q\*} + URI Schema: mqtt/connection{?q\*} q\*: - - clientId := client uid + - clientid := client uid - username - password @@ -126,10 +126,10 @@ The server manages the client through the ClientId. If the ClientId is wrong, EM 2. Close a Connection Method : DELETE - URI Schema: mqtt/{+topic}{?q\*} + URI Schema: mqtt/connection{?q\*} q\*: - - clientId := client uid + - clientid := client uid - token Resonse: @@ -143,12 +143,14 @@ The server manages the client through the ClientId. If the ClientId is wrong, EM ### Heartbeat -The Coap client can maintain the "connection" with the server through the heartbeat (regardless of whether it is authenticated or not), so that the server will not release related resources +The Coap client can maintain the "connection" with the server through the heartbeat, +regardless of whether it is authenticated or not, +so that the server will not release related resources Method : PUT -URI Schema: mqtt/{+topic}{?q\*} +URI Schema: mqtt/connection{?q\*} q\*: -- clientId if authenticated +- clientid if authenticated - token if authenticated Response: @@ -166,7 +168,7 @@ CoAP gateway uses some options in query string to conversion between MQTT CoAP. 1. Shared Options - - clientId + - clientid - token 2. Connect Options @@ -188,9 +190,9 @@ CoAP gateway uses some options in query string to conversion between MQTT CoAP. - option - value type - default + Option + Type + Default @@ -204,7 +206,7 @@ CoAP gateway uses some options in query string to conversion between MQTT CoAP. qos - MQTT QOS + MQTT Qos See here @@ -231,16 +233,16 @@ CoAP gateway uses some options in query string to conversion between MQTT CoAP. - option - value type - default + Option + Type + Default qos - MQTT QOS + MQTT Qos See here @@ -260,7 +262,7 @@ CoAP gateway uses some options in query string to conversion between MQTT CoAP. -5. MQTT QOS <=> CoAP non/con +5. MQTT Qos <=> CoAP non/con 1.notif_type Control the type of notify messages when the observed object has changed.Can be: @@ -268,7 +270,7 @@ CoAP gateway uses some options in query string to conversion between MQTT CoAP. - non - con - qos - in this value, MQTT QOS0 -> non, QOS1/QOS2 -> con + in this value, MQTT Qos0 -> non, Qos1/Qos2 -> con 2.subscribe_qos Control the qos of subscribe.Can be: @@ -300,7 +302,7 @@ CoAP gateway uses some options in query string to conversion between MQTT CoAP. 2. Session - Manager the "Transport Mnager" "Observe Resouces Manger" and next message id + Manager the "Transport Manager" "Observe Resouces Manger" and next message id 3. Transport Mnager diff --git a/apps/emqx_gateway/src/coap/emqx_coap_channel.erl b/apps/emqx_gateway/src/coap/emqx_coap_channel.erl index 7612a6142..760a832ae 100644 --- a/apps/emqx_gateway/src/coap/emqx_coap_channel.erl +++ b/apps/emqx_gateway/src/coap/emqx_coap_channel.erl @@ -148,7 +148,7 @@ get_config(Key, #exec_ctx{config = Cfg}, Def) -> maps:get(Key, Cfg, Def). result_keys() -> - [out, reply, connection]. + [out, connection]. transfer_result(From, Value, Result) -> ?TRANSFER_RESULT(From, Value, Result). @@ -289,9 +289,9 @@ handle_result(out, #{out := Out}, _, Channel) -> handle_result(_, _, _, Channel) -> {ok, Channel}. -check_auth_state(Method, #channel{config = Cfg} = Channel) -> +check_auth_state(Msg, #channel{config = Cfg} = Channel) -> #{authentication := #{enable := Enable}} = Cfg, - check_token(Enable, Method, Channel). + check_token(Enable, Msg, Channel). check_token(true, #coap_message{options = Options} = Msg, diff --git a/apps/emqx_gateway/src/coap/emqx_coap_session.erl b/apps/emqx_gateway/src/coap/emqx_coap_session.erl index 98e24f05c..50e91797b 100644 --- a/apps/emqx_gateway/src/coap/emqx_coap_session.erl +++ b/apps/emqx_gateway/src/coap/emqx_coap_session.erl @@ -162,7 +162,7 @@ deliver(Delivers, Ctx, Session) -> end, lists:foldl(Fun, #{out => [], session => Session}, - Delivers). + lists:reverse(Delivers)). timeout(Timer, Ctx, Session) -> call_transport_manager(?FUNCTION_NAME, Timer, Ctx, [fun process_tm/3], Session). @@ -189,8 +189,8 @@ call_transport_manager(Fun, Session), emqx_coap_channel:transfer_result(session, Session2, Result2) catch Type:Reason:Stack -> - ?ERROR("process transmission with, message:~p failed~n -Type:~p,Reason:~p~n,StackTrace:~p~n", [Msg, Type, Reason, Stack]), + ?ERROR("process transmission with, message:~p failed~nType:~p,Reason:~p~n,StackTrace:~p~n", + [Msg, Type, Reason, Stack]), ?REPLY({error, internal_server_error}, Msg) end.