Cumulocity smarREST 响应模板 [英] Cumulocity smarREST response templates

查看:47
本文介绍了Cumulocity smarREST 响应模板的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试设置 Cumulocity smartREST 响应模板以提供来自应用程序存储的设备对象的信息.我认为这是不可能的,但我想确认一下,因为文档简短且不清楚.

I am trying to set up the Cumulocity smartREST response templates to supply info from the device object stored by an app. I am thinking it is not possible but I want to confirm because the documentation is brief and not clear.

我之前已经成功实施了 MEASUREMENT POST 模板,但我现在正在尝试执行 INVENTORY GET.我在设备对象中设置了一些值,我可以从tenant.cumulocity.com/inventory/managedObjects/id/看到它们.这可能看起来像:

I have successfully implemented MEASUREMENT POST templates previously but I am trying to do INVENTORY GET now. I have set some values in the device object and I can see them from tenant.cumulocity.com/inventory/managedObjects/id/. This could look like:

"custom_values": {
    "val1": "abcde",
    "val2": "fghij"
}

现在我转到 smartREST 模板 Web 界面编辑器并创建模板(例如 t1)并设置消息(例如 m001)并将其设置为库存"和获取"并勾选包括响应".我不确定这里是否需要自定义字段.然后我创建一个响应(例如 r001),现在我必须用一个条件和一些其他模式填充基本模式.我假设在其中一个字段中我有 $.custom_values.val1 等,但我尝试的所有排列都会导致主题s/e"中的无法访问对象"错误.

Now I go to the smartREST template web interface editor and create a template (eg t1) and set a message (eg m001) and set it to 'inventory' and 'get' and tick 'includes response'. I'm not sure if I need custom fields here. Then I create a response (eg r001) and I now have to fill in base pattern with a condition and some number of other patterns. I assume in one of those fields I have $.custom_values.val1 etc but all permutations I try result in 'no access to object' error from topic 's/e'.

我的理想结果(从上面的例子中)是用'm001'发布到'/s/uc/t1'并接收'r001,abcde'(即custom_values.val1)并发布'm002'并接收'r001,fghij'(即 custom_values.val2).

My ideal result (from the above example) would be to publish to '/s/uc/t1' with 'm001' and receive 'r001,abcde' (ie custom_values.val1) and publish 'm002' and receive 'r001,fghij' (ie custom_values.val2).

感谢您抽出时间阅读.

推荐答案

您的方法是正确的,但您的 MQTT 用户可能只是缺少对应用程序创建的对象的权限(我猜 mqtt 客户端是一个设备用户).这里最好的方法是为您从应用程序创建的这个对象提供片段 c8y_Global

Your approach is correct but your MQTT user probably is just missing the rights to the object as it is created by the app (I guess the mqtt client is a device user). The best approach here is to give this object you are creating from the app the fragment c8y_Global

{
    "name": "testObject3", 
    "c8y_Global": {},
    "custom_values": {
        "val1": "abcde",
        "val2": "fghij"
    }
}

此片段将使所有注册用户都可以使用此对象.这是应用元数据的常见做法.

This fragment will make this object available to all registered users. This is common practice for app meta data.

这篇关于Cumulocity smarREST 响应模板的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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