gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-04 01:56:56 32 4
gpt4 key购买 nike

我知道如何从客户端访问属性,但我想从 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 atthingsboard/ui/src/app/api/attribute.service.js

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

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

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com