Search code examples
fiwarefiware-orionfiware-wirecloud

FIWARE - IoT Agent - Data for Orion


I have installed FIWARE on my machine (Ubuntu 18.04) and I am currently trying to work with the IoT Agent, using the HTTPBindings.js (my data is sent via LoRaWAN and I've changed the parseData function in order to use my own data "protocol" [id=1&temp=12&humidity=10], which brings me here to ask 2 questions for someone who is more experienced and can help me with:

 function parseData(req, res, next) {
    let data;
    let error;
    let payload;
    let obj; 
      try {
        let newPayload = new Buffer.from(payload, "base64").toString("ascii");
      var ps = newPayload.split("&").reduce((accum, x) => {
        const kv = x.split("=");
        return { ...accum, ...{ [kv[0]]: kv[1] } };
      }, {});
        data = ulParser.parse(newPayload.replace(/&/g, "|").replace(/=/g, "|"));
       
      } catch (e) {
          error = e;
      }
    
      if (error) {
          next(error);
      } else {
          req.ulPayload = data;
          config.getLogger().debug(context, 'Parsed data: [%j]', data);
          next();
      }
    }
  1. After changing this function, I can't get the data to be updated in the orion/v2/entities.. Would someone explain me how does this work?

  2. How can I add a proxy to usenter code heree in the Wirecloud? I've created it using the FIWARE servers, but testing on my own, I do not have this.

Thank you in advance.


Solution

  • Configuring NGSI Proxy

    The ngsi-proxy is configured using environment variables and a port.

      ngsi-proxy:
        image: fiware/ngsiproxy:1.2.0
        hostname: ngsi-proxy
        container_name: wc-ngsi-proxy
        networks:
          default:
            ipv4_address: 172.18.1.14
        expose:
          - "8100"
        ports:
          - "8100:8100"
        environment:
          - PORT=8100
          - TRUST_PROXY_HEADERS=0
    

    The NGSI proxy config in the wirecloud widget is then http://<host>:<port> - in this case http://ngsi-proxy:8100

    Testing HTTP Binding connectivity

    Incoming HTTP measures can be controlled by the IOTA_HTTP_PORT Environment variable:

    iot-agent:
        image: fiware/iotagent-ul:${ULTRALIGHT_VERSION}
        hostname: iot-agent
        container_name: fiware-iot-agent
        depends_on:
          - mongo-db
          - orion
        networks:
          - default
        ports:
          - "4041:4041" 
          - "7896:7896"
        expose:
          - "7896"
        environment:
    ..etc
          - IOTA_NORTH_PORT=4041
          - IOTA_LOG_LEVEL=DEBUG 
          - IOTA_HTTP_PORT=7896
          - IOTA_PROVIDER_URL=http://iot-agent:4041
    

    If you ramp up the debug and expose the relevant port, you should be able to send measures directly to your custom IoT Agent and see some sort of response (probably an error) - this can help track down your coding issue.

    You can always add additional debug logging to the custom IoT Agent to see how the conversion is working.