CoAP:将类似资源归为一类 [英] CoAP: Group similar resources under one

查看:65
本文介绍了CoAP:将类似资源归为一类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在为我的一个物联网应用程序使用CoAP的libcoap实现.

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.

在对"/TIME"资源的GET请求中,服务器应向客户端提供日期和当前时间. 在对"/TIME/当前时间"资源的GET请求中,服务器应向客户端提供当前时间. 在对"/TIME/date"资源的GET请求中,服务器应向客户端提供今天的日期.

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.

此外,我正在使用Firefox Copper插件来测试我的物联网服务器应用程序.

Also, I am using Firefox Copper plugin to test my iot server application.

推荐答案

假设您同时创建了/TIME/currenttime和/TIME/date资源,剩下的就是创建/TIME/资源(结束确实很重要),并在.well-known/core中将其声明为</TIME/>;if="core.b".

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".

/TIME/的GET处理程序应以application/senml+json格式返回数据,例如[{"n":"currenttime","sv":"10:40:25"},{"n":"date","sv":"2018-07-27"}].

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.

这篇关于CoAP:将类似资源归为一类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆