Code Monkey home page Code Monkey logo

emqx-coap's Introduction

emqx-coap

emqx-coap is a CoAP Gateway for EMQX Broker. It translates CoAP messages into MQTT messages and make it possible to communiate between CoAP clients and MQTT clients.

Client Usage Example

libcoap is an excellent coap library which has a simple client tool. It is recommended to use libcoap as a coap client.

To compile libcoap, do following steps:

git clone http://github.com/obgm/libcoap
cd libcoap
./autogen.sh
./configure --enable-documentation=no --enable-tests=no
make

Publish example:

libcoap/examples/coap-client -m put -e 1234  "coap://127.0.0.1/mqtt/topic1?c=client1&u=tom&p=secret"
  • topic name is "topic1", NOT "/topic1"
  • client id is client1
  • username is tom
  • password is secret
  • payload is a text string "1234"

A mqtt message with topic="topic1", payload="1234" has been published. Any mqtt client or coap client, who has subscribed this topic could receive this message immediately.

Subscribe example:

libcoap/examples/coap-client -m get -s 10 "coap://127.0.0.1/mqtt/topic1?c=client1&u=tom&p=secret"
  • topic name is "topic1", NOT "/topic1"
  • client id is client1
  • username is tom
  • password is secret
  • subscribe time is 10 seconds

And you will get following result if any mqtt client or coap client sent message with text "1234567" to "topic1":

v:1 t:CON c:GET i:31ae {} [ ]
1234567v:1 t:CON c:GET i:31af {} [ Observe:1, Uri-Path:mqtt, Uri-Path:topic1, Uri-Query:c=client1, Uri-Query:u=tom, Uri-Query:p=secret ]

The output message is not well formatted which hide "1234567" at the head of the 2nd line.

Configure

Common

File: etc/emqx_coap.conf

## The UDP port that CoAP is listening on.
##
## Value: Port
coap.port = 5683

## Interval for keepalive, specified in seconds.
##
## Value: Duration
##  -s: seconds
##  -m: minutes
##  -h: hours
coap.keepalive = 120s

## Whether to enable statistics for CoAP clients.
##
## Value: on | off
coap.enable_stats = off

DTLS

emqx_coap enable one-way authentication by default.

If you want to disable it, comment these lines.

File: etc/emqx_coap.conf

## The DTLS port that CoAP is listening on.
##
## Value: Port
coap.dtls.port = 5684

## Private key file for DTLS
##
## Value: File
coap.dtls.keyfile = {{ platform_etc_dir }}/certs/key.pem

## Server certificate for DTLS.
##
## Value: File
coap.dtls.certfile = {{ platform_etc_dir }}/certs/cert.pem
Enable two-way autentication

For two-way autentication:

## A server only does x509-path validation in mode verify_peer,
## as it then sends a certificate request to the client (this
## message is not sent if the verify option is verify_none).
## You can then also want to specify option fail_if_no_peer_cert.
## More information at: http://erlang.org/doc/man/ssl.html
##
## Value: verify_peer | verify_none
## coap.dtls.verify = verify_peer

## PEM-encoded CA certificates for DTLS
##
## Value: File
## coap.dtls.cacertfile = {{ platform_etc_dir }}/certs/cacert.pem

## Used together with {verify, verify_peer} by an SSL server. If set to true,
## the server fails if the client does not have a certificate to send, that is,
## sends an empty certificate.
##
## Value: true | false
## coap.dtls.fail_if_no_peer_cert = false

Load emqx-coap

./bin/emqx_ctl plugins load emqx_coap

CoAP Client Observe Operation (subscribe topic)

To subscribe any topic, issue following command:

  GET  coap://localhost/mqtt/{topicname}?c={clientid}&u={username}&p={password}    with OBSERVE=0
  • "mqtt" in the path is mandatory.
  • replace {topicname}, {clientid}, {username} and {password} with your true values.
  • {topicname} and {clientid} is mandatory.
  • if clientid is absent, a "bad_request" will be returned.
  • {topicname} in URI should be percent-encoded to prevent special characters, such as + and #.
  • {username} and {password} are optional.
  • if {username} and {password} are not correct, an uauthorized error will be returned.
  • topic is subscribed with qos1.

CoAP Client Unobserve Operation (unsubscribe topic)

To cancel observation, issue following command:

  GET  coap://localhost/mqtt/{topicname}?c={clientid}&u={username}&p={password}    with OBSERVE=1
  • "mqtt" in the path is mandatory.
  • replace {topicname}, {clientid}, {username} and {password} with your true values.
  • {topicname} and {clientid} is mandatory.
  • if clientid is absent, a "bad_request" will be returned.
  • {topicname} in URI should be percent-encoded to prevent special characters, such as + and #.
  • {username} and {password} are optional.
  • if {username} and {password} are not correct, an uauthorized error will be returned.

CoAP Client Notification Operation (subscribed Message)

Server will issue an observe-notification as a subscribed message.

  • Its payload is exactly the mqtt payload.
  • payload data type is "application/octet-stream".

CoAP Client Publish Operation

Issue a coap put command to do publishment. For example:

  PUT  coap://localhost/mqtt/{topicname}?c={clientid}&u={username}&p={password}
  • "mqtt" in the path is mandatory.
  • replace {topicname}, {clientid}, {username} and {password} with your true values.
  • {topicname} and {clientid} is mandatory.
  • if clientid is absent, a "bad_request" will be returned.
  • {topicname} in URI should be percent-encoded to prevent special characters, such as + and #.
  • {username} and {password} are optional.
  • if {username} and {password} are not correct, an uauthorized error will be returned.
  • payload could be any binary data.
  • payload data type is "application/octet-stream".
  • publish message will be sent with qos0.

CoAP Client Keep Alive

Device should issue a get command periodically, serve as a ping to keep mqtt session online.

  GET  coap://localhost/mqtt/{any_topicname}?c={clientid}&u={username}&p={password}
  • "mqtt" in the path is mandatory.
  • replace {any_topicname}, {clientid}, {username} and {password} with your true values.
  • {any_topicname} is optional, and should be percent-encoded to prevent special characters.
  • {clientid} is mandatory. If clientid is absent, a "bad_request" will be returned.
  • {username} and {password} are optional.
  • if {username} and {password} are not correct, an uauthorized error will be returned.
  • coap client should do keepalive work periodically to keep mqtt session online, especially those devices in a NAT network.

CoAP Client NOTES

emqx-coap gateway does not accept POST and DELETE requests.

Topics in URI should be percent-encoded, but corresponding uri_path option has percent-encoding converted. Please refer to RFC 7252 section 6.4, "Decomposing URIs into Options":

Note that these rules completely resolve any percent-encoding.

That implies coap client is responsible to convert any percert-encoding into true character while assembling coap packet.

ClientId, Username, Password and Topic

ClientId/username/password/topic in the coap URI are the concepts in mqtt. That is to say, emqx-coap is trying to fit coap message into mqtt system, by borrowing the client/username/password/topic from mqtt.

The Auth/ACL/Hook features in mqtt also applies on coap stuff. For example:

  • If username/password is not authorized, coap client will get an uauthorized error.
  • If username or clientid is not allowed to published specific topic, coap message will be dropped in fact, although coap client will get an acknoledgement from emqx-coap.
  • If a coap message is published, a 'message.publish' hook is able to capture this message as well.

well-known locations

Discovery always return ","

For example

libcoap/examples/coap-client -m get "coap://127.0.0.1/.well-known/core"

License

Apache License Version 2.0

Author

EMQX Team.

emqx-coap's People

Contributors

emqplus avatar gilbertwong96 avatar grutabow avatar hjianbo avatar huangdan avatar justina111 avatar qingchuwudi avatar rory-z avatar terry-xiaoyu avatar tigercl avatar turtledeng avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

emqx-coap's Issues

coap DTLS

1.关于这方面的资料,在官方文档中并未明确;
2.coap DTLS自签名证书的生成步骤;
3.根据生成的证书进行coap插件的配置;
4.Java的californium如何连接coap DTLS

Can't start coap plugin

Environment

emq 2.3.1 in docker, official image from here

Expected behaviour

I can start the coap plugin from the dashboard and I can connect to it with clients (Caliornium).

Actual behaviour

Started image with:
docker run --rm -ti --name emq -p 18083:18083 -p 1883:1883 -p 5683:5683 -p 5684:5684 -v /my/certs/are/here:/etc/certs emqttd-docker-v2.3.1:latest

Dashboard shows up, I set up the certificates then turn on the coap plugin. Dashboard shows it is ok, but it doesn't show up under listeners. In the logs I see

13:13:42.856 [error] CRASH REPORT Process <0.1562.0> with 0 neighbours exited with reason: {cannot_listen,5684,{options,{ciphers,[]}}} in gen_server:init_it/6 line 344

Cert was generated using this tutorial (CA + Server with unprotected key). If I try without certs (emptying the 2 fields for the cert and key) the result is:

13:17:30.443 [error] CoAP: certfile [] or keyfile [] are not valid, turn off coap DTLS

Dashboard still shows it is started ok, but not visible under listeners, and I can't connect. I have tried both 5683 and 5684 ports with no luck.

can't connect to emqx by DTLS

Environment

  • OS: CentOS7
  • Erlang/OTP: NA
  • EMQ: v3.2.0

Description
I can use libcoap and californium client to connect EMQX_COAP By udp. And terminal was online in EMQX Dashboard, I can publish subscribe topic. But when i use DTLS, I can't get any message from log without any error , but i can't find my terminal in EMQ Dashboard.
I can communicate with californium demo server using the same client by DTLS.
I would like to know how to connect to EMQX using DTLS, thanks!

EMQ 最新版的coap插件问题

安装完成最新版的EMQ 后,在 管理 里边打开Coap插件 后不能正常使用Coap协议通信,
有朋友用的旧版本EMQ ,同样的方法打开coap插件后 可以正常通信,这是为什么呢??

Coap-client Request timeout problem

EMQ version:v4.1.0-alpha.1
openssl:1.1.1d
libcoap:v4.3.0-alpha

When I run coap-client -m put -e 1234 "coap://127.0.0.1/mqtt/topic1?c=client1&u=tom&p=secret" command,The coap Messages can be published。
But when I replace 127.0.0.1 with my public address。The request will be unresponsive。I think it should be overtime。
I have two machines, one with EMQ and the other with libcoap and EMQ。But It still doesn't work。There are no printing related errors in the log。
It doesn't seem to have happened before when using version 4.0.2。

I hope it can be solved. Thank you

Coap plugin started, but can't use it

Environment

emq 2.3.9 in docker, official image from here

Expected behaviour

I can start the coap plugin from the dashboard and connect to it with clients libcoap or coap-cli

Actual behaviour

Started image with:

sudo docker run -tid --name emqtt-coap -p 5683:5683 -p 5684:5684 -p 1883:1883 -p 8083:8083 -p 8883:8883 -p 8084:8084 -p 18083:18083 emqttd-docker-v2.3.9

Open plugin with

  1. sudo docker container exec -it [containerID] /bin/sh
  2. ./bin/emqttd_ctl plugins load emq_coap

Result

  1. Dashboard shows up
    image
  2. Port listen
    image
  3. Logs
    image

Connetct through libcoap

image

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

Environment

  • OS: ubuntu-18.04.2 LTS
  • Erlang/OTP: otp-21.2.2
  • EMQ: branch develop(1979cb92a0611ed13f80b0bb21af5b67ea7593f4)
  • EMQX-CoAP: master(7358349)

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,

CoAP Notification acknowledge failure

Hello,

we have a situation, we keep receiving repeats of observed topic notifications.
Running emqx 4.3.4...

We receive a notification (hex format):
44 45 0a ae 00 11 22 33 61 01
61 2a ff 7b 22 35 30 22 3a 22
which is generaly translated into:
{
"type": "Confirmable",
"code": "Content",
"id": 2734,
"token": 1122867,
"options": [
"Observe(value=1)",
"Content-Format: application/octet-stream"
]
"payload":"7B 22 35 30 22 3A 22"
}
We acknowledge this message with (hex format):
64 44 0a ae 00 11 22 33
which is generaly translated into:
{
"type": "Acknowledgement",
"code": "Changed",
"id": 2734,
"token": 1122867,
"options": [
]
}

As you can see we acknowledge the notification...
Why does the coap plugin keep sending the same notification?

Do we need to configure libcoap differently? Or does this plugin not work anymore?

EMQ的coap插件猜想

除了2.3.11版本的coap插件可以正常使用,其余均无法正常使用。我猜想是打着开源的旗号,干着收费的事情,大家在使用的过程中注意避开这个巨坑

emqx-coap has device control function?

Hi, recently,i use emqx coap function,I have some question ask for advice. I want to know weather emqx-coap has device control function, I just see device infrom function? if it support control function ,the borker translate mqtt to coap and sent to device? if device send a coap request ,how it guarantee this message synchronous response or how shoule i do to guarantee a synchronous response?

emq_coap has no response

Environment

OS: linux/win7
Erlang/OTP: R19
EMQ: 2.0
Description

Send a GET request to emq_coap, have no response
Send an OBSERVE request to emq_coap, no response
Mqtt.fx publish a message which a coap client has observed, but this message can not reach the coap client.

coap get returns 5.00

hi,

while trying to get/put message via coap receving always 5.00 reply. What am I missing?

coap-client: libcoap
emqx broker version 3 rc1


./coap-client -m get -s 100 "coap://127.0.0.1/mqtt/test?c=1&u=admin&p=public" -v 9
Apr 11 10:35:11 DEBG ***127.0.0.1:33665 <-> 127.0.0.1:5683 UDP : new outgoing session
Apr 11 10:35:11 DEBG sending CoAP request:
Apr 11 10:35:11 DEBG * 127.0.0.1:33665 <-> 127.0.0.1:5683 UDP : sent 36 bytes
v:1 t:CON c:GET i:736a {} [ Observe:0, Uri-Path:mqtt, Uri-Path:test, Uri-Query:c=1, Uri-Query:u=admin, Uri-Query:p=public ]
Apr 11 10:35:11 DEBG ** 127.0.0.1:33665 <-> 127.0.0.1:5683 UDP : tid=29546 added to retransmit queue (2313ms)
Apr 11 10:35:11 DEBG timeout is set to 90 seconds
Apr 11 10:35:11 DEBG * 127.0.0.1:33665 <-> 127.0.0.1:5683 UDP : received 4 bytes
v:1 t:ACK c:5.00 i:736a {} [ ]
Apr 11 10:35:11 DEBG ** 127.0.0.1:33665 <-> 127.0.0.1:5683 UDP : tid=29546: removed
Apr 11 10:35:11 DEBG ** process incoming 5.00 response:
5.00
Apr 11 10:35:11 DEBG ***127.0.0.1:33665 <-> 127.0.0.1:5683 UDP : session closed


emqx console output:

([email protected])1>
([email protected])1> 2019-04-11 10:35:11.729 [error] 1 ** Generic server <0.1877.0> terminating
** Last message in was {'EXIT',<0.1875.0>,
{{case_clause,ok},
[{emqx_protocol,send,2,
[{file,"src/emqx_protocol.erl"},{line,682}]},
{emqx_coap_mqtt_adapter,proto_init,5,
[{file,"src/emqx_coap_mqtt_adapter.erl"},
{line,258}]},
{emqx_coap_mqtt_adapter,init,1,
[{file,"src/emqx_coap_mqtt_adapter.erl"},
{line,120}]},
{gen_server,init_it,2,
[{file,"gen_server.erl"},{line,374}]},
{gen_server,init_it,6,
[{file,"gen_server.erl"},{line,342}]},
{proc_lib,init_p_do_apply,3,
[{file,"proc_lib.erl"},{line,249}]}]}}
** When Server state == {state,30000,true,#Fun<emqx_session.1.64839632>,
<<"1">>,<<"admin">>,undefined,undefined,1,0,
#{},false,
{emqx_inflight,65535,{0,nil}},
0,undefined,
{mqueue,true,1000,0,0,none,0,{queue,[],[],0}},
#{},undefined,undefined,undefined,0,undefined,
true,undefined,undefined,
{1554,971711,726113},
undefined,undefined}
** Reason for termination ==
** {{case_clause,ok},
[{emqx_protocol,send,2,[{file,"src/emqx_protocol.erl"},{line,682}]},
{emqx_coap_mqtt_adapter,proto_init,5,
[{file,"src/emqx_coap_mqtt_adapter.erl"},
{line,258}]},
{emqx_coap_mqtt_adapter,init,1,
[{file,"src/emqx_coap_mqtt_adapter.erl"},
{line,120}]},
{gen_server,init_it,2,[{file,"gen_server.erl"},{line,374}]},
{gen_server,init_it,6,[{file,"gen_server.erl"},{line,342}]},
{proc_lib,init_p_do_apply,3,[{file,"proc_lib.erl"},{line,249}]}]}


log output:

2019-04-11 12:47:32.747 [error] 1 crasher:
initial call: emqx_coap_mqtt_adapter:init/1
pid: <0.3599.0>
registered_name: []
exception error: no case clause matching ok
in function emqx_protocol:send/2 (src/emqx_protocol.erl, line 682)
in call from emqx_coap_mqtt_adapter:proto_init/5 (src/emqx_coap_mqtt_adapter.erl, line 258)
in call from emqx_coap_mqtt_adapter:init/1 (src/emqx_coap_mqtt_adapter.erl, line 120)
in call from gen_server:init_it/2 (gen_server.erl, line 374)
in call from gen_server:init_it/6 (gen_server.erl, line 342)
ancestors: [<0.3598.0>,<0.3596.0>,<0.3595.0>,<0.1721.0>,coap_server,
<0.1718.0>]
message_queue_len: 1
messages: [{keepalive,start,90}]
links: [<0.3601.0>]
dictionary: [{'$logger_metadata$',#{client_id => <<"1">>}},
{guid,{1554979652747166,268555715087887,0}}]
trap_exit: false
status: running
heap_size: 2586
stack_size: 27
reductions: 2357
neighbours:
2019-04-11 12:47:32.750 [error] 1 ** Generic server <0.3601.0> terminating
** Last message in was {'EXIT',<0.3599.0>,
{{case_clause,ok},
[{emqx_protocol,send,2,
[{file,"src/emqx_protocol.erl"},{line,682}]},
{emqx_coap_mqtt_adapter,proto_init,5,
[{file,"src/emqx_coap_mqtt_adapter.erl"},
{line,258}]},
{emqx_coap_mqtt_adapter,init,1,
[{file,"src/emqx_coap_mqtt_adapter.erl"},
{line,120}]},
{gen_server,init_it,2,
[{file,"gen_server.erl"},{line,374}]},
{gen_server,init_it,6,
[{file,"gen_server.erl"},{line,342}]},
{proc_lib,init_p_do_apply,3,
[{file,"proc_lib.erl"},{line,249}]}]}}
** When Server state == {state,30000,true,#Fun<emqx_session.1.64839632>,
<<"1">>,<<"admin">>,undefined,undefined,1,0,
#{},false,
{emqx_inflight,65535,{0,nil}},
0,undefined,
{mqueue,true,1000,0,0,none,0,{queue,[],[],0}},
#{},undefined,undefined,undefined,0,undefined,
true,undefined,undefined,
{1554,979652,746745},
undefined,undefined}
** Reason for termination ==
** {{case_clause,ok},
[{emqx_protocol,send,2,[{file,"src/emqx_protocol.erl"},{line,682}]},
{emqx_coap_mqtt_adapter,proto_init,5,
[{file,"src/emqx_coap_mqtt_adapter.erl"},
{line,258}]},
{emqx_coap_mqtt_adapter,init,1,
[{file,"src/emqx_coap_mqtt_adapter.erl"},
{line,120}]},
{gen_server,init_it,2,[{file,"gen_server.erl"},{line,374}]},
{gen_server,init_it,6,[{file,"gen_server.erl"},{line,342}]},
{proc_lib,init_p_do_apply,3,[{file,"proc_lib.erl"},{line,249}]}]}
2019-04-11 12:47:32.762 [error] 1 crasher:
initial call: emqx_session:init/1
pid: <0.3601.0>
registered_name: []
exception exit: {{case_clause,ok},
[{emqx_protocol,send,2,
[{file,"src/emqx_protocol.erl"},{line,682}]},
{emqx_coap_mqtt_adapter,proto_init,5,
[{file,"src/emqx_coap_mqtt_adapter.erl"},
{line,258}]},
{emqx_coap_mqtt_adapter,init,1,
[{file,"src/emqx_coap_mqtt_adapter.erl"},
{line,120}]},
{gen_server,init_it,2,
[{file,"gen_server.erl"},{line,374}]},
{gen_server,init_it,6,
[{file,"gen_server.erl"},{line,342}]},
{proc_lib,init_p_do_apply,3,
[{file,"proc_lib.erl"},{line,249}]}]}
in function gen_server:handle_common_reply/8 (gen_server.erl, line 751)
ancestors: [emqx_session_sup,emqx_sm_sup,emqx_sup,<0.1382.0>]
message_queue_len: 0
messages: []
links: [<0.1650.0>]
dictionary: [{'$logger_metadata$',#{client_id => <<"1">>}}]
trap_exit: true
status: running
heap_size: 10958
stack_size: 27
reductions: 353733
neighbours:


more emqx_auth_clientid.conf
##--------------------------------------------------------------------

ClientId Authentication Plugin

##--------------------------------------------------------------------

Examples

auth.client.1.clientid = 1
auth.client.1.password = public

Password hash.

Value: plain | md5 | sha | sha256

auth.client.password_hash = sha256


Thanks!

Subtopic doesn't work

Hi , I have tested this plugin with 2.3.11 and it works. I can pub/sub to a topic.
But when doing a pub to topic/subtopic it doesn't work.

What do i do wrong and how to get that working?

Also what does it mean to mandatory use mqtt in the topic url?
When i add it to the url it works, but not when i leave it out.

COAP on IPv6

Hi,

I'm trying to enable CoAP listener on IPv6 interface but can't find option for this. Putting ":::5683" in the plugin config doesn't work as it expects just integer as the port.

Is this supported? If so, what's the config for this?

CoAP plugin unsubscribes from topic

Hello!

we have a situation where our CoAP clients succesfully begin Observing a topic. Next we use an MQTT client to periodicaly (20s) post something on that topic. We receive some messages through this pipeline. Alongside this feature our CoAP client keeps sending Confirmable data packets to the server, every 5s.

But after some time the packets stop coming... we have observed on the dashboard that on the MQTT side the client is not subscribed anymore. Meanwhile we still successfully deliver the data and get confirmation messages from the server...

We did multiple checks and we know that our client does not send an Un-Observe CoAP packet. As such we cannot find why it unsubscribes.

Similar behaviour happens instantly if we use 3-5 packet bursts from the MQTT client side, as if the CoAP plugin cannot handle this situation...

We are using eqmx 4.3.4.
We extended the CoAP "keep alive" to 24h.

Please could you provide suggestion on which setting we could check or set...

CoAP Put error

I want publish a message to a topic, which topic name is topic1/toic2.
So, I put a message to the url : "coap://localhost/mqtt/topic1%2Ftopic2?c=client1" but put has error.

tips: If I put the message to the url: "coap://localhost/mqtt/topic1?c=client1", it will success.

Coap Message is missed.

If I use java coapclient to put the coap message to the emqtt.
At the first time, it is OK and work well. However, after 5 mins, if I put the message again, EMQ can't receive the Coap message.
I catch up the eth package in my desktop. It seems my java coapclient has sent the packages.
ca
And I also use tcpdump to capture the package in the EMQ server. I find the package arrived.

Unable to use this plugin with emqttd

When after enabling coap plugin from dashboard of emqttd, When I test the thing using "coap.me" website, I get following error log in console.

`12:33:02.928 [error] {badarg,[{erlang,binary_to_list,"m",[]},{core_link,join_uri,1,[{file,"src/core_link.erl"},{line,54}]},{core_link,encode_link_uri,2,[{file,"src/core_link.erl"},{line,48}]},{core_link,encode_link_value,1,[{file,"src/core_link.erl"},{line,37}]},{lists,foldl,3,[{file,"lists.erl"},{line,1263}]},{coap_server_content,coap_get,4,[{file,"src/coap_server_content.erl"},{line,23}]},{coap_responder,invoke_callback,3,[{file,"src/coap_responder.erl"},{line,278}]},{coap_responder,check_resource,3,[{file,"src/coap_responder.erl"},{line,142}]}]}`

Any quickfix for the same?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.