问题
I am using libcoap implementation of CoAP for one of my IOT application.
Query: I want to group more than one resource under one topic. For example, I want to group 'current time' resource and 'date' resource under 'TIME' resource.
On GET request to '/TIME' resource, server should provide date and current time to client. On GET request to '/TIME/current time' resource, server should provide current time to client. On GET request to '/TIME/date' resource, server should provide today's date to client.
Also, I am using Firefox Copper plugin to test my iot server application.
回答1:
Assuming you have created both the /TIME/currenttime and /TIME/date resources, what's left is that you create a /TIME/ resource (the slash at the end does matter) and announce it in .well-known/core as </TIME/>;if="core.b"
.
The GET handler for /TIME/ should return data in application/senml+json
format, like [{"n":"currenttime","sv":"10:40:25"},{"n":"date","sv":"2018-07-27"}]
.
All the details are described in core-interfaces draft, but that's the gist of it.
来源:https://stackoverflow.com/questions/34893380/coap-group-similar-resources-under-one