attributes - 如何从 thingsboard 服务器端访问属性

标签 attributes thingsboard

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

最佳答案

我们必须非常清楚服务器端客户端。 事实上,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 模块。

关于attributes - 如何从 thingsboard 服务器端访问属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49950517/

相关文章:

XSLT count() 不起作用

javascript - 用于设备控制的自定义 Thingsboard 小部件 (REST)

networking - 为什么我收到错误 ("status":405 ,"error" :"Method Not Allowed") upon sending data to Thingsboard device via command line

thingsboard - 如何通过 websocket 从 Thingsboard 检索所有客户设备的遥测数据

c# - 属性和类

xml - 在 XML 中,属性顺序重要吗?

attributes - 在源代码上添加一个新属性,该属性会传播到 LLVM 中的 MC 级别?

ios - 包含 NSMutableArray 属性的核心数据对象?

widget - 如何在 thingsboard 中制作自定义小部件?

javascript - ThingsBoard 动态更改简单卡片小部件元素的背景颜色