Cumulocity实时最新测量数据获取

标签 cumulocity

c8yMeasurements.latest(filter, realtime)
  .then(function (latestMeasurement) {
    vm.text = latestMeasurement.c8y_TemperatureMeasurement.T.value;
    console.log(vm.text);
  });

我尝试使用此处的文档从某个设备获取最新测量值:http://resources.cumulocity.com/documentation/jssdk/latest/#/api/c8y.core.service:c8yMeasurements .

但是,我不太确定 realtime 是如何实现的事情确实有效。我设置realtime为 true,但 vm.text 的值每次代理更改值时都不会更新。

为了解决这个问题,我使用了 setInterval JS 中的方法(这很讨厌 T T)。然后它在我的定制应用程序中运行良好。

但是,在我c8y build:plugin hello之后(hello是我的插件的名称)并将zip文件上传到cockpit,无法获取该值。

请帮忙:(谢谢。

最佳答案

为了使其实时工作,您需要将结果包装到一个函数中,以便 Angular 在更新模型时可以调用它。这是一个例子

function getLatestMeasurementForDatapoint({ fragment, series, __target }) {
  return c8yMeasurements.latest({
      fragment,
      series,
      device: _.get(__target, 'id')
    }, true)
      .then(
        (rtLatestMeasurement) => {
          return {
            value: () => _.get(rtLatestMeasurement, [fragment, series, 'value'])
          };
        }
      );
}

在你的 Controller 中,你可以调用这个函数,它将返回一个包含键值的对象

getLatestMeasurementForDatapoint(vm.datapoint)
  .then((latestMeasurement) => { vm.latestMeasurement = latestMeasurement; });

最后,您可以在模型中引用该结果。请注意,值是一个函数,因此您需要像函数一样调用它。

{{vm.latestMeasurement.value()}}

关于Cumulocity实时最新测量数据获取,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49485006/

相关文章:

children - 如何通过 inventory api 将子设备设置为设备?

java - 访问 cumulocity Maven 存储库

基于类型的 Cumulocity 警报文本重写

linux - Cumulocity Raspberry PI - 连接问题

cumulocity - 订阅 channel /实时通知

java - 从 Java 设置 c8y_Command 结果字符串

java - 使用 java 11 编译 cumulocity-clients-java 时出错

cumulocity - 如何使用 Cumulocity Device mgm/Configuration Repository?