|
|
пре 3 година | |
|---|---|---|
| .. | ||
| doc | пре 4 година | |
| handler | пре 3 година | |
| include | пре 3 година | |
| README.md | пре 4 година | |
| emqx_coap_api.erl | пре 3 година | |
| emqx_coap_channel.erl | пре 3 година | |
| emqx_coap_frame.erl | пре 3 година | |
| emqx_coap_impl.erl | пре 3 година | |
| emqx_coap_medium.erl | пре 3 година | |
| emqx_coap_message.erl | пре 3 година | |
| emqx_coap_observe_res.erl | пре 3 година | |
| emqx_coap_session.erl | пре 3 година | |
| emqx_coap_tm.erl | пре 3 година | |
| emqx_coap_transport.erl | пре 3 година | |
emqx-coap is a CoAP Gateway for EMQX. It translates CoAP messages into MQTT messages and make it possible to communiate between CoAP clients and MQTT clients.
Publish
Method: POST\ URI Schema: ps/{+topic}{?q*}\ q*: Shared Options\ Response:
Subscribe
Method: GET Options:
URI Schema: ps/{+topic}{?q*}\ q*: see Shared Options\ Response:
Client1 Client2 Broker
| | Subscribe |
| | ----- GET /ps/topic1 Observe:0 Token:XX ----> |
| | |
| | <---------- 2.05 Content Observe:10---------- |
| | |
| | |
| | Publish |
| ---------|----------- PUT /ps/topic1 "1033.3" --------> |
| | Notify |
| | <---------- 2.05 Content Observe:11 --------- |
| | |
UnSubscribe
Method : GET Options:
URI Schema: ps/{+topic}{?q*}\ q*: see Shared Options\ Response:
Establishing a connection is optional. If the CoAP client needs to use connection-based operations, it must first establish a connection. At the same time, the connectionless mode and the connected mode cannot be mixed. In connection mode, the Publish/Subscribe/UnSubscribe sent by the client must be has Token and ClientId in query string. If the Token and Clientid is wrong/miss, EMQX will reset the request. The communication token is the data carried in the response payload after the client successfully establishes a connection. After obtaining the token, the client's subsequent request must attach "token=Token" to the Query String ClientId is necessary when there is a connection, and is a unique identifier defined by the client. The server manages the client through the ClientId. If the ClientId is wrong, EMQX will reset the request.
Create a Connection
Method: POST URI Schema: mqtt/connection{?q*} q*:
Response:
Payload: Token if success
Close a Connection
Method : DELETE URI Schema: mqtt/connection{?q*} q*:
Response:
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/connection{?q*} q*:
Response:
CoAP gateway uses some options in query string to conversion between MQTT CoAP.
Connect Options
Publish
| Option | Type | Default |
|---|---|---|
| retain | boolean | false |
| qos | MQTT Qos | See here |
| expiry | Message Expiry Interval | 0(Never expiry) |
Subscribe
| Option | Type | Default |
|---|---|---|
| qos | MQTT Qos | See here |
| nl | MQTT Subscribe No Local | 0 |
| rh | MQTT Subscribe Retain Handing | 0 |
MQTT Qos <=> CoAP non/con
1.notif_type Control the type of notify messages when the observed object has changed.Can be:
2.subscribe_qos Control the qos of subscribe.Can be:
3.publish_qos like subscribe_qos, but control the qos of the publish MQTT message
Authorization check
Check whether the clientid and token in the query string match the current connection
Session
Manager the "Transport Manager" "Observe Resources Manager" and next message id
Transport Mnager
Manager "Transport" create/close/dispatch
Observe resources Mnager
Mnager observe topic and token
Transport
Handler
pubsub
| Method | Observe | Action |
|---|---|---|
| GET | 0 | subscribe and reply result |
| GET | 1 | unsubscribe and reply result |
| POST | X | publish and reply result |
mqtt
| Method | Action |
|---|---|
| PUT | reply result |
| POST | return create connection action |
| DELETE | return close connection action |
Create Connection
coap-client -m post -e "" "coap://127.0.0.1/mqtt/connection?clientid=123&username=admin&password=public"
Server will return token X in payload
Update Connection
coap-client -m put -e "" "coap://127.0.0.1/mqtt/connection?clientid=123&token=X"
Publish
coap-client -m post -e "Hellow" "obstoken" "coap://127.0.0.1/ps/coap/test?clientid=123&username=admin&password=public"
if you want to publish with auth, you must first establish a connection, and then post publish request on the same socket, so libcoap client can't simulation publish with a token
coap-client -m post -e "Hellow" "coap://127.0.0.1/ps/coap/test?clientid=123&token=X"
coap-client -m get -s 60 -O 6,0x00 -o - -T "obstoken" "coap://127.0.0.1/ps/coap/test?clientid=123&username=admin&password=public"
Orcoap-client -m get -s 60 -O 6,0x00 -o - -T "obstoken" "coap://127.0.0.1/ps/coap/test?clientid=123&token=X"
coap-client -m delete -e "" "coap://127.0.0.1/mqtt/connection?clientid=123&token=X