抓住CoAP协议的“心” (2)

启动Shell:

java -jar coap-shell-1.1.2-SNAPSHOT.jar _____ ___ ___ ______ ____ / ___/__ / _ | / _ \ / __/ / ___ / / / / /__/ _ \/ __ |/ ___/ _\ \/ _ \/ -_) / / \___/\___/_/ |_/_/ /___/_//_/\__/_/_/ CoAP Shell (v1.1.2-SNAPSHOT) For assistance hit TAB or type "help". server-unknown:>

连接到CoAP服务器(例如coap://californium.eclipse.org/或coap://coap.me)

server-unknown:>connect coap://coap.me available coap://coap.me:>ping available coap://coap.me:>

发现可用的CoAP资源

coap://coap.me:>discover ┌──────────────────────────────┬────────────────────────┬─────────────────────────┬───────────┬──────┬─────────────┐ │Path [href] │Resource Type [rt] │Content Type [ct] │Interface │Size │Observable │ │ │ │ │[if] │[sz] │[obs] │ ├──────────────────────────────┼────────────────────────┼─────────────────────────┼───────────┼──────┼─────────────┤ │/123412341234123412341234 │123412341234123412341234│text/plain (0) │ │ │ │ │/3 │3 │application/json (50) │ │ │ │ │/4 │4 │application/json (50) │ │ │ │ │/5 │5 │application/json (50) │ │ │ │ │/bl%C3%A5b%C3%A6rsyltet%C3%B8y│blåbærsyltetøy │text/plain (0) │ │ │ │ │/broken │Type2, Type1 │text/plain (0) │If2, If1 │ │ │ │/create1 │create1 │text/plain (0) │ │ │ │ │/hello │Type1 │text/plain (0) │If1 │ │ │ │/large │Type1, Type2 │text/plain (0) │If2 │1700 │ │ │/large-create │large-create │text/plain (0) │ │ │ │ │/large-update │large-update │text/plain (0) │ │ │ │ │/location-query │location-query │text/plain (0) │ │ │ │ │/location1 │location1 │application/link-format │ │ │ │ │ │ │(40) │ │ │ │ │/multi-format │multi-format │text/plain (0) │ │ │ │ │/path │path │application/link-format │ │ │ │ │ │ │(40) │ │ │ │ │/query │query │text/plain (0) │ │ │ │ │/secret │secret │text/plain (0) │ │ │ │ │/seg1 │seg1 │application/link-format │ │ │ │ │ │ │(40) │ │ │ │ │/separate │separate │text/plain (0) │ │ │ │ │/sink │sink │text/plain (0) │ │ │ │ │/test │test │text/plain (0) │ │ │ │ │/validate │validate │text/plain (0) │ │ │ │ │/weird33 │weird33 │text/plain (0) │ │ │ │ │/weird333 │weird333 │text/plain (0) │ │ │ │ │/weird3333 │weird3333 │text/plain (0) │ │ │ │ │/weird33333 │weird33333 │text/plain (0) │ │ │ │ │/weird44 │weird44 │text/plain (0) │ │ │ │ │/weird55 │weird55 │text/plain (0) │ │ │ │ └──────────────────────────────┴────────────────────────┴─────────────────────────┴───────────┴──────┴─────────────┘ coap://coap.me:>

GET获取资源数据

coap://coap.me:>get /hello ----------------------------------- Response ----------------------------------- GET coap://coap.me/hello MID: 64187, Type: ACK, Token: 50E8F0AC1BA8D277, RTT: 3368ms Options: {"Content-Format":"text/plain"} Status : 205-Reset Content, Payload: 5B ................................... Payload .................................... world --------------------------------------------------------------------------------

从以上列表能清晰的看出CoAP的消息格式和数据包。

coap://coap.me/hello : 是CoAP协议的uri

MID: 消息的ID,用于唯一区分消息。

Type: 消息类型,这里的消息类型为:Acknowledgement(确认)

Token: 消息会话

Options:{"Content-Format":"text/plain"}消息可选性,这里表示消息的数据类型为文本

Status: 状态码

Payload: 消息负载数据

Delete资源数据

coap://coap.me:>get /sink NULL response! coap://coap.me:>delete /sink ----------------------------------- Response ----------------------------------- DELETE coap://coap.me/sink MID: 64264, Type: ACK, Token: 0C2338F7FB9447F7, RTT: 274ms Options: {"Content-Format":"text/plain"} Status : 202-Accepted, Payload: 9B ................................... Payload .................................... DELETE OK -------------------------------------------------------------------------------- coap://coap.me:>get /sink ----------------------------------- Response ----------------------------------- GET coap://coap.me/sink MID: 64265, Type: ACK, Token: 04A8DACB450186A7, RTT: 276ms Options: {"ETag":0xa6166ef62ce0b4bc, "Content-Format":"text/plain"} Status : 205-Reset Content, Payload: 38B ................................... Payload .................................... I was deleted, and you put here: hello -------------------------------------------------------------------------------- coap://coap.me:>

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/zyydpf.html