【问题标题】:How to access attributes from thingsboard serverside如何从 thingsboard 服务器端访问属性
【发布时间】:2018-04-20 22:31:36
【问题描述】:

我知道如何从客户端访问属性,但我想从 thingsboard 服务器端访问设备的属性。因此,在开发新的小部件时,我可以显示所有属性的列表并在必要时更改它们。我该怎么做?

【问题讨论】:

    标签: attributes thingsboard


    【解决方案1】:

    server-sideclient-side我们要非常清楚。 事实上,Thingsboard 小部件在浏览器的客户端运行。

    据我了解,我们有两个选项可用于小部件中的属性访问。

    1. 在小部件的数据源中定义属性访问或
    2. 使用 HTTP-Api 访问属性

    Thingsboard 为使用 HTTP-Api 提供了一个方便的“服务”,我们可以像这样使用它:

    var entityId, attributeKey, myAttribute, attributeService;
    
    entityId         = ... // entity id from the widgets datasource.
    attributeKey     = 'MyAttribute';
    myAttribute      = {
        key: attributeKey,
        value: 'MyAttributeValue';
    };
    
    attributeService = self.ctx.$scope.$injector.get('attributeService');
    
    // Access attributes.
    attributeService.getEntityAttributesValues('DEVICE', entityId, 'SERVER_SCOPE', attributeKey)
        .then(function success(attributes) {
            // Use the attribute value.
        });
    
    // Write attributes.
    attributeService.saveEntityAttributes(
            'DEVICE', entityId, 'SERVER_SCOPE', [myAttribute]);
    

    Http-Api 有更多选项,甚至服务提供了一些更方便的功能。查看sources of the service at thingsboard/ui/src/app/api/attribute.service.js

    注意:这是指低于 3 的 Thingsboard 版本的 ui 模块。

    【讨论】:

    • 链接转到 404,FWIW
    猜你喜欢
    • 2013-06-15
    • 2014-06-05
    • 2011-06-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-07-08
    • 1970-01-01
    相关资源
    最近更新 更多