2015-02-04 4 views
1

필드를 내 엔티티의 각 속성에 적용하려고합니다. Orion을 Quering하고 엔티티를 가져 오는 것은 문제가되지 않습니다. (NGSI Source 위젯을 통해이 작업을 수행합니다.)하지만 이러한 매개 변수를 가져 오는 방법입니다. NGSI 소스 (오리온 인스턴스에 대한 일반적인 suscription)에서 JavaScript (WireCloud)에서 OCB 쿼리하기

:

var doInitialSubscription = function doInitialSubscription() { 

    this.subscriptionId = null; 

    this.ngsi_server = MashupPlatform.prefs.get('ngsi_server'); 
    this.ngsi_proxy = MashupPlatform.prefs.get('ngsi_proxy'); 
    this.connection = new NGSI.Connection(this.ngsi_server, { 
     ngsi_proxy_url: this.ngsi_proxy 
    }); 

    var types = MashupPlatform.prefs.get('ngsi_entities').split(new RegExp(',\\s*')); 
    var entityIdList = []; 
    var entityId; 
    for (var i = 0; i < types.length; i++) { 
     entityId = { 
      id: '.*', 
      type: types[i], 
      isPattern: true 
     }; 
     entityIdList.push(entityId); 
    } 
    var attributeList = null; 
    var duration = 'PT3H'; 
    var throttling = null; 
    var notifyConditions = [{ 
     'type': 'ONCHANGE', 
     'condValues': MashupPlatform.prefs.get('ngsi_update_attributes').split(new RegExp(',\\s*')) 
    }]; 
    var options = { 
     flat: true, 
     onNotify: handlerReceiveEntity.bind(this), 
     onSuccess: function (data) { 
      this.subscriptionId = data.subscriptionId; 
      this.refresh_interval = setInterval(refreshNGSISubscription.bind(this), 1000 * 60 * 60 * 2); // each 2 hours 
      window.addEventListener("beforeunload", function() { 
       this.connection.cancelSubscription(this.subscriptionId); 
      }.bind(this)); 
     }.bind(this) 
    }; 
    this.connection.createSubscription(entityIdList, attributeList, duration, throttling, notifyConditions, options); 
}; 
var handlerReceiveEntity = function handlerReceiveEntity(data) { 
    for (var entityId in data.elements) { 
     MashupPlatform.wiring.pushEvent("entityOutput", JSON.stringify(data.elements[entityId])); 
    } 
}; 

MyWidget 사람 : 나는 유형 필드의 값을 얻을 비슷한 코드를하려고 해요

MashupPlatform.wiring.registerCallback("entityInput", function (entityString) { 
    var entity; 
    entity = JSON.parse(entityString); 
    id = entity.id; 
    type = entity.type; 
    for(var attr in entity){ 
     attribute = entity[attr]; 
    } 

. 어떻게해야합니까? (확실 합니다만 ...)

+0

'entityString' 변수의 내용을 추가하여 질문을 편집하여 사례를 더 잘 이해할 수 있습니까? – fgalan

+0

@fgalan 그 이유는 다음과 같습니다. '{ "id": "387243781", "type": "MyApp", "BAT": "65", "value1": "351", "value2" : "0.023", "value3": "0.039", "value4": "37.375476", "value5": "- 5.989363", "date": "23/11/2014 13:26:27" : "Parque de María Luisa 41013 Sevilla"}'. 엔티티의 이름 및 값 필드 만 검색하고 있습니다. 나는 또한 내가 오리온을 통해 변화에 매달리는 방식을 덧붙였다. 내가 뭔가 잘못하고 있는거야? –

답변

2

NGSI 소스가 사용하는 것처럼 속성의 유형 메타 데이터를 얻으려는 경우 현재의 NGSI 소스 연산자 구현 (적어도 v3.0.2 이상)을 사용할 수 없습니다. flat 옵션 (해당 정보 삭제) 옵션

이 연산자를 업데이트하여 flat 옵션을 사용하지 않고 구독을 만들 수 있습니다. 여기에서 가장 큰 문제는 다른 컴포넌트가 flat 옵션을 사용할 때 반환되는 형식으로이 연산자가 제공하는 데이터를 제공 할 것으로 기대한다는 것입니다. 문제를 깊이 분석 한 후에이 답변을 업데이트하겠습니다.