简体   繁体   English

使用NGSI API进行Wirecloud查询

[英]Make a wirecloud query using NGSI API

I'm trying to make a query using NGSI API in my Wire Cloud widget but always fails and I don't receive anything: 我试图在我的Wire Cloud小部件中使用NGSI API进行查询,但始终失败,但我什么也没收到:

var descubrimiento = connection.query([{
       isPattern: true,
       id: MashupPlatform.prefs.get('idfuente')
   }],
   null,
   {
      flat: true              
   }
);

connection is the object where I have the connection with the context broker and it works fine. connection是我与上下文代理connection的对象,并且工作正常。 Also if I make the query with the NGSI10 RESTful API via RESTclient I receive the data that I want but with the wirecloud NGSI API in my widget it is imposible to make the query. 另外,如果我通过RESTclient使用NGSI10 RESTful API进行查询,那么我会收到所需的数据,但是在小部件中使用wirecloud NGSI API进行查询是不可能的。

Someone has this problem too? 有人也有这个问题吗?

Take a look at this tutorial about how to use the Orion Context Broker from WireCloud. 看看这个教程中有关如何从WireCloud使用猎户座语境经纪人。

The main problem is that you're assuming the method the query response is returned synchronously while in reality is returned asynchronously. 主要问题是您假设查询响应的方法是同步返回的,而实际上是异步返回的。 For being able to read the returned data, you need to pass a onSuccess callback. 为了能够读取返回的数据,您需要传递一个onSuccess回调。 This callback will be called as soon the response from the Orion server is available. Orion服务器的响应可用后,将立即调用此回调。 The data returned by Orion will be passed as the first parameter of the onSuccess callback function (see the referenced documentation for examples about how the returned data is formatted). Orion返回的数据将作为onSuccess回调函数的第一个参数传递(有关如何格式化返回的数据的示例,请参阅参考文档)。 Eg: 例如:

connection.query([{
       isPattern: true,
       id: MashupPlatform.prefs.get('idfuente')
   }],
   null,
   {
      flat: true,
      onSuccess: function (descubrimiento) {
          ...
      }
   }
);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM