WireCloud offers support for a number of GEs including the Context Broker and the Object Storage GE. What follows is an example of how a developer can access Orion Context Broker (reference implementation of the FIWARE's Pub/Sub Context Broker GE) instances from widgets and operators running on WireCloud. For more detailed information on how to use this and other FIWARE GEs from WireCloud, please refer to WireCloud tutorials.

First of all, widgets and operators wishing to use the JavaScript bindings provided by WireCloud for accessing the FIWARE NGSI Open RESTful API in order to seamlessly interoperate with the Orion Context Broker must add the NGSI feature as a requirement into their description files (config.xml files).

The following is an example of a widget description using the XML flavour of the WDL:

<?xml version='1.0' encoding='UTF-8'?>
<widget xmlns="http://wirecloud.conwet.fi.upm.es/ns/macdescription/1" vendor="CoNWeT" name="observation-reporter" version="1.0">
    <title>Observation Reporter</title>
    <description>Creates a new observation</description>
    <feature name="NGSI"/>
  <contents src="index.html" contenttype="text/html" charset="utf-8" useplatformstyle="true"/>
  <rendering height="20" width="5"/>

The RDF/xml flavour of the same widget description is:

<?xml version='1.0' encoding='UTF-8'?>
  <wire:Widget rdf:about="http://wirecloud.conwet.fi.upm.es/ns/widget#CoNWeT/observation-reporter/1.0">
      <vcard:Work rdf:nodeID="Nb17ce611aa2645e488515f86eb855e53">
      <usdl:Resource rdf:about="index.html">
      <wire:PlatformWiring rdf:nodeID="Neecb97db81ed40859b8c04e935a9a9cc"/>
    <wire:displayName>Observation Reporter</wire:displayName>
    <wire:hasiPhoneImageUri rdf:resource="images/smartphone.png"/>
      <ns1:BusinessEntity rdf:nodeID="N9a6bf56577c741ac806997a80281afff">
    <wire:hasImageUri rdf:resource="images/catalogue.png"/>
      <wire:PlatformRendering rdf:nodeID="N713e5ea11dce4750a592c754c748def7">
      <wire:Feature rdf:nodeID="N3cb336bd9b6243ecbf345c80442498f9">
    <dcterms:description>Creates a new observation</dcterms:description>
      <foaf:Person rdf:nodeID="Ndb72cb5a7f3844b29b72f304baaa14a7">

One of the most important operations provided by the context broker is the support for subscriptions. By using subscriptions our dashboard can obtain right time notifications about the status of the entities of interest. Subscriptions are very similar to queries, the main difference between queries and subscriptions is that queries are synchronous operations, whilst subscriptions are asynchronous. Moreover, the Orion Context Broker will send a first notification containing the data that would be returned for the equivalent query operation. This way, you will know that there is no gap between the current values and the notified changes.

Subscriptions are created through the createSubscription method. The following example explains how to be notified about the changes of the position of the vans we are managing:

var entityIdList = [
    {type: 'Van', id: '.*', isPattern: true}
var attributeList = null;
var duration = 'PT3H';
var throttling = null;
var notifyConditions = [{
    type: 'ONCHANGE',
    condValues: ['current_position']
var options = {
    flat: true,
    onNotify: function (data) {
        // called when the context broker sends a new notification
    onSuccess: function (data) {
        ngsi_subscriptionId = data.subscriptionId;
var ngsi_connection = new NGSI.Connection(ngsi_server[, options]);
ngsi_connection.createSubscription(entityIdList, attributeList, duration, throttling, notifyConditions, options);

In this example, the call to createSubscription will make the context broker invoke the onNotify function each time the 'current_position' attribute of the entities of type 'Van' is changed. You must take into account that the Orion Context Broker evaluates patterns at runtime, so using patters you will be able to receive notification about new entities provided that the notify conditions are meet.

This subscription will be expiring after 3 hours, time from which the context broker will stop sending notifications. Anyway, widgets/operators can renew those subscriptions by using the updateSubscription method, even if they have expired. Subscriptions can be cancelled using the cancelSubscription method making the context broker release any info about the subscription. In any case, WireCloud will cancel any subscription automatically when widgets/operators are unloaded.

As an example, what follows is the value of the data parameter passed to the onNotify callback when using the flat option:

    "elements": {
        "van2": {
            "id": "van2",
            "type": "Van",
            "current_position": "43.47258, -3.8026643"
        "van4": {
            "id": "van4",
            "type": "Van",
            "current_position": "43.471214, -3.7994885"
    "subscriptionId": "53708768286043030c116e2c",
    "originator": "localhost"

WireCloud tutorial on how to use Orion Context Broker from widgets and operators further explain how to create connections, make queries, deal with pagination, create entities and update their attributes, use geolocation capabilities, etc. It also includes a complete example. Please also refer to the NGSI javascript API documentation for a more detailed description of the API calls used along the tutorial.