emqx / emqx-coap

EMQX CoAP Gateway
https://www.emqx.com
Apache License 2.0
61 stars 34 forks source link

It does not work with MQTT message with qos >= 1? #125

Closed jerry-chao closed 5 years ago

jerry-chao commented 5 years ago

Environment

Description

I use libcoap client to subscribe a topic, but i cannot received msg with qos >= 1 which sent through mosquitto_pub.

Commands

coap-client

./examples/coap-client -m get -s 100 "coap://127.0.0.1:5683/mqtt/a/b/clientA/test?c=clientA&u=admin&p=public" -v 9

mqtt sender

mosquitto_pub  -u test -P test  -i test/pub1  -t 'a/b/clientA/test' -m 'test5555' -q 0

emqx console log

2019-08-02 01:06:24.021 [info] clientA [Protocol] Shutdown for {function_clause,
                            [{emqx_coap_mqtt_adapter,proto_deliver_ack,
                                 [{message,
                                      <<0,5,143,29,213,154,17,158,13,219,0,0,
                                        45,171,0,1>>,
                                      1,<<"test/pub1">>,
                                      #{dup => false,retain => false},
                                      #{allow_publish => true,
                                        peername => {{127,0,0,1},34450},
                                        username => <<"test">>},
                                      <<"a/b/clientA/test">>,<<"test5555">>,
                                      {1564,733514,275273}},
                                  {pstate,undefined,
                                      #Fun<emqx_coap_mqtt_adapter.0.108494585>,
                                      {{0,0,0,0},5683},
                                      {{127,0,0,1},38093},
                                      nossl,4,<<"MQTT">>,<<"clientA">>,false,
                                      <0.11679.0>,undefined,undefined,
                                      <<"admin">>,<0.11681.0>,true,#{},
                                      undefined,undefined,120,false,
                                      #{msg => 0,pkt => 2},
                                      #{msg => 2,pkt => 3},
                                      true,
                                      {1564,733501,342778},
                                      #{from_client => 0,to_client => 0},
                                      undefined,
                                      #{anonymous => true,
                                        auth_result => success,
                                        client_id => <<"clientA">>,
                                        mountpoint => undefined,
                                        peername => {{127,0,0,1},38093},
                                        sockname => {{0,0,0,0},5683},
                                        username => <<"admin">>,
                                        ws_cookie => undefined,
                                        zone => undefined},
                                      undefined}],
                                 [{file,
                                      "/home/zhangchao11/work/github.com/emqx-rel/_checkouts/emqx_coap/src/emqx_coap_mqtt_adapter.erl"},
                                  {line,284}]},
                             {emqx_coap_mqtt_adapter,deliver,3,
                                 [{file,
                                      "/home/zhangchao11/work/github.com/emqx-rel/_checkouts/emqx_coap/src/emqx_coap_mqtt_adapter.erl"},
                                  {line,309}]},
                             {emqx_coap_mqtt_adapter,deliver,3, 
                                 [{file,
                                      "/home/zhangchao11/work/github.com/emqx-rel/_checkouts/emqx_coap/src/emqx_coap_mqtt_adapter.erl"},
                                  {line,303}]},
                             {emqx_coap_mqtt_adapter,handle_info,2,
                                 [{file,
                                      "/home/zhangchao11/work/github.com/emqx-rel/_checkouts/emqx_coap/src/emqx_coap_mqtt_adapter.erl"},
                                  {line,184}]},
                             {gen_server,try_dispatch,4,
                                 [{file,"gen_server.erl"},{line,637}]},
                             {gen_server,handle_msg,6,
                                 [{file,"gen_server.erl"},{line,711}]},
                             {proc_lib,wake_up,3,
                                 [{file,"proc_lib.erl"},{line,259}]}]}
2019-08-02 01:06:24.068 [error] clientA ** Generic server {<<"clientA">>,<<"admin">>,<<"public">>} terminating 
** Last message in was {deliver,
                           [{publish,1,
                                {message,
                                    <<0,5,143,29,213,154,17,158,13,219,0,0,45,
                                      171,0,1>>,
                                    1,<<"test/pub1">>,
                                    #{dup => false,retain => false},
                                    #{allow_publish => true,
                                      peername => {{127,0,0,1},34450},
                                      username => <<"test">>},
                                    <<"a/b/clientA/test">>,<<"test5555">>,
                                    {1564,733514,275273}}},
                            {publish,2,
                                {message,
                                    <<0,5,143,29,213,154,17,158,13,219,0,0,45,
                                      171,0,1>>,
                                    1,<<"test/pub1">>,
                                    #{dup => false,retain => false},
                                    #{allow_publish => true,
                                      peername => {{127,0,0,1},34450},
                                      username => <<"test">>},
                                    <<"a/b/clientA/test">>,<<"test5555">>,
                                    {1564,733514,275273}}}]}
** When Server state == {state,
                            {pstate,undefined,
                                #Fun<emqx_coap_mqtt_adapter.0.108494585>,
                                {{0,0,0,0},5683},
                                {{127,0,0,1},38093},
                                nossl,4,<<"MQTT">>,<<"clientA">>,false,
                                <0.11679.0>,undefined,undefined,<<"admin">>,
                                <0.11681.0>,true,#{},undefined,undefined,120,
                                false,
                                #{msg => 0,pkt => 2},
                                #{msg => 2,pkt => 3},
                                true,
                                {1564,733501,342778},
                                #{from_client => 0,to_client => 0},
                                undefined,
                                #{anonymous => true,auth_result => success,
                                  client_id => <<"clientA">>,
                                  mountpoint => undefined,
                                  peername => {{127,0,0,1},38093},
                                  sockname => {{0,0,0,0},5683},
                                  username => <<"admin">>,
                                  ws_cookie => undefined,zone => undefined},
                                undefined},
                            {{127,0,0,1},38093},
                            {timer_state,90,true,
                                #Ref<0.1325469851.121110529.74827>,
                                {keepalive,check}},
                            [{<<"a/b/clientA/test">>,{false,<0.11678.0>}}],
                            false}
** Reason for termination == 
** {function_clause,
       [{emqx_coap_mqtt_adapter,proto_deliver_ack,
            [{message,
                 <<0,5,143,29,213,154,17,158,13,219,0,0,45,171,0,1>>,
                 1,<<"test/pub1">>,
                 #{dup => false,retain => false},
                 #{allow_publish => true,
                   peername => {{127,0,0,1},34450},
                   username => <<"test">>},
                 <<"a/b/clientA/test">>,<<"test5555">>,
                 {1564,733514,275273}},
             {pstate,undefined,#Fun<emqx_coap_mqtt_adapter.0.108494585>,
                 {{0,0,0,0},5683},
                 {{127,0,0,1},38093},
                 nossl,4,<<"MQTT">>,<<"clientA">>,false,<0.11679.0>,undefined,
                 undefined,<<"admin">>,<0.11681.0>,true,#{},undefined,
                 undefined,120,false,
                 #{msg => 0,pkt => 2},
                 #{msg => 2,pkt => 3},
                 true,
                 {1564,733501,342778},
                 #{from_client => 0,to_client => 0},
                 undefined,
                 #{anonymous => true,auth_result => success,
                   client_id => <<"clientA">>,mountpoint => undefined,
                   peername => {{127,0,0,1},38093},
                   sockname => {{0,0,0,0},5683},
                   username => <<"admin">>,ws_cookie => undefined,
                   zone => undefined},
                 undefined}],
            [{file,
                 "/home/zhangchao11/work/github.com/emqx-rel/_checkouts/emqx_coap/src/emqx_coap_mqtt_adapter.erl"},
             {line,284}]},
        {emqx_coap_mqtt_adapter,deliver,3,
            [{file,
                 "/home/zhangchao11/work/github.com/emqx-rel/_checkouts/emqx_coap/src/emqx_coap_mqtt_adapter.erl"},
             {line,309}]},
        {emqx_coap_mqtt_adapter,deliver,3,
            [{file,
                 "/home/zhangchao11/work/github.com/emqx-rel/_checkouts/emqx_coap/src/emqx_coap_mqtt_adapter.erl"},
             {line,303}]},
        {emqx_coap_mqtt_adapter,handle_info,2,
            [{file,
                 "/home/zhangchao11/work/github.com/emqx-rel/_checkouts/emqx_coap/src/emqx_coap_mqtt_adapter.erl"},
             {line,184}]},
        {gen_server,try_dispatch,4,[{file,"gen_server.erl"},{line,637}]},
        {gen_server,handle_msg,6,[{file,"gen_server.erl"},{line,711}]},
        {proc_lib,wake_up,3,[{file,"proc_lib.erl"},{line,259}]}]}
2019-08-02 01:06:24.112 [error] clientA crasher:
    initial call: emqx_coap_mqtt_adapter:init/1
    pid: <0.11679.0>
    registered_name: []
    exception error: no function clause matching 
                     emqx_coap_mqtt_adapter:proto_deliver_ack({message,
                                                               <<0,5,143,29,
                                                                 213,154,17,
                                                                 158,13,219,0,
                                                                 0,45,171,0,1>>,
                                                               1,
                                                               <<"test/pub1">>,
                                                               #{dup => false,
                                                                 retain =>
                                                                  false},
                                                               #{allow_publish =>
                                                                  true,
                                                                 peername =>
                                                                  {{127,0,0,1},
                                                                   34450},
                                                                 username =>
                                                                  <<"test">>},
                                                               <<"a/b/clientA/test">>,
                                                               <<"test5555">>,
                                                               {1564,733514,
                                                                275273}},
                                                              {pstate,
                                                               undefined,
                                                               #Fun<emqx_coap_mqtt_adapter.0.108494585>,
                                                               {{0,0,0,0},
                                                                5683},
                                                               {{127,0,0,1},
                                                                38093},
                                                               nossl,4,
                                                               <<"MQTT">>,
                                                               <<"clientA">>,
                                                               false,
                                                               <0.11679.0>,
                                                               undefined,
                                                               undefined,
                                                               <<"admin">>,
                                                               <0.11681.0>,
                                                               true,#{},
                                                               undefined,
                                                               undefined,120,
                                                               false,
                                                               #{msg => 0,
                                                                 pkt => 2},
                                                               #{msg => 2,
                                                                 pkt => 3},
                                                               true,
                                                               {1564,733501,
                                                                342778},
                                                               #{from_client =>
                                                                  0,
                                                                 to_client =>
                                                                  0},
                                                               undefined,
                                                               #{anonymous =>
                                                                  true,
                                                                 auth_result =>
                                                                  success,
                                                                 client_id =>
                                                                  <<"clientA">>,
                                                                 mountpoint => 
                                                                  undefined,
                                                                 peername =>
                                                                  {{127,0,0,1},
                                                                   38093},
                                                                 sockname =>
                                                                  {{0,0,0,0},
                                                                   5683},
                                                                 username =>
                                                                  <<"admin">>,
                                                                 ws_cookie =>
                                                                  undefined,
                                                                 zone =>
                                                                  undefined},
                                                               undefined}) (/home/zhangchao11/work/github.com/emqx-rel/_checkouts/emqx_coap/src/emqx_coap_mqtt_adapter.erl, line 284)
      in function  emqx_coap_mqtt_adapter:deliver/3 (/home/zhangchao11/work/github.com/emqx-rel/_checkouts/emqx_coap/src/emqx_coap_mqtt_adapter.erl, line 309)
      in call from emqx_coap_mqtt_adapter:deliver/3 (/home/zhangchao11/work/github.com/emqx-rel/_checkouts/emqx_coap/src/emqx_coap_mqtt_adapter.erl, line 303)
      in call from emqx_coap_mqtt_adapter:handle_info/2 (/home/zhangchao11/work/github.com/emqx-rel/_checkouts/emqx_coap/src/emqx_coap_mqtt_adapter.erl, line 184)
      in call from gen_server:try_dispatch/4 (gen_server.erl, line 637)
      in call from gen_server:handle_msg/6 (gen_server.erl, line 711)
    ancestors: [<0.11678.0>,<0.11676.0>,<0.11675.0>,<0.9258.0>,coap_server,
                  <0.9255.0>]
    message_queue_len: 82
    messages: [{deliver,
HJianBo commented 5 years ago

Hi, @jerry-chao I can't pull this 1979cb92a0611ed13f80b0bb21af5b67ea7593f4 commit for emqx.

I don't recommend using the develop branch for emqx. It maybe has some compatibility and stability problems with other connector plugins.

HJianBo commented 5 years ago

emqx: release-3.2 branch emqx_coap: master branch

I have check this issue with above versions. It works well.

So, That is not a good idea for dependent emqx develop code. Especially, these connection layer plugins. It often raises compatibility issues