2

I would like to make a httpCustom payload in OCB but no replace info properly. I think i have tested all the ways i know but no results, someone who could help me. This is my code:

"notification": {
            "httpCustom": {
                "url": "http://xxxx.xxxx.xxxx:8080/api/v1/telemetry",
                "payload": "[{ %22temperature%22: %22${id}%22, %22humidity%22: %22${humidity}%22, %22battery%22: %22${battery}%22 }]"
            },
            "attrs": [
                "temperature","humidity","battery"
            ]
        },

I have no error when i do subscription, but when i test in my end point no replace for the macros ${...}, the payload take object information compose but with no values.

I have test to write/send ${id} as then value of a field in payload and no substitution at all. Test it with URL encode and %22 and no success, I think could be disable substitution ? but i have check it and it has FALSE value.

This is a http response:

{
  "method": "POST",
  "path": "/",
  "query": {},
  "headers": {
    "x-forwarded-for": "3.124.211.58",
    "x-forwarded-proto": "https",
    "x-forwarded-port": "443",
    "host": "83efe9565d48d8bc8cf298d7786b8042.m.pipedream.net",
    "x-amzn-trace-id": "Root=1-5f1bddce-7f2b4277458e77b98c0920d1",
    "content-length": "54",
    "user-agent": "orion/2.1.0 libcurl/7.29.0",
    "fiware-service": "example",
    "fiware-servicepath": "/example",
    "accept": "application/json",
    "content-type": "application/json",
    "fiware-correlator": "a7fcfe32-ce47-11ea-9723-0242ac14000a",
    "ngsiv2-attrsformat": "custom"
  },
  "bodyRaw": "[{ \"temperature\": \"\", \"humidity\": \"\", \"battery\": \"\" }]",
  "body": [
    {
      "temperature": "",
      "humidity": "",
      "battery": ""
    }
  ]
}

Orion Versión: 2.1.0 and tested in 2.4.0

Any help ? Thanks in advance !!

  • A quick question... how do you are sending your request? curl? Postman? other? Thanks! – fgalan Jul 27 '20 at 20:11
  • I have an IoTAgent (LoraWan) to update my device at OCB, then i have a subscription to historic on Crate.db working properly and another subscription (this one), to integrate with thingboards.io (that´s the reason i need a manual payload). I am testing my subscription an see that works because a send it to piperdream.com (requestbin) and there i can see no replace for macros is done. I have update my OCB to 2.4.0 but the same results. Thank you for you help. – José Checa Claudel Jul 28 '20 at 10:39

1 Answers1

0

I have done the following test, with Orion 2.4.0. Orion database is empty before starting the test.

First, create this subscription:

curl -v localhost:1026/v2/subscriptions -s -S -H 'Content-Type: application/json' -d @- <<EOF
{
  "subject": {
    "entities": [
      {
        "id": "Device1",
        "type": "Device"
      }
    ]
  },
  "notification": {
    "httpCustom": {
      "url": "http://localhost:1027/api/v1/telemetry",
      "payload": "[{ %22temperature%22: %22\${id}%22, %22humidity%22: %22\${humidity}%22, %22battery%22: %22\${battery}%22 }]"},
      "attrs": [
         "temperature","humidity","battery"
      ]
  }
}
EOF

Next, start a listining process at port 1027:

nc -l -p 1027

Next, create entity as follows (which triggers a notification):

curl localhost:1026/v2/entities -s -S -H 'Content-Type: application/json' -d @- <<EOF
{
  "id": "Device1",
  "type": "Device",
  "temperature": {
    "value": 23,
    "type": "Number"
  },
  "humidity": {
    "value": 99,
    "type": "Number"
  },
  "battery": {
    "value": 15,
    "type": "Number"  
  }
}
EOF

What I get in nc is:

POST /api/v1/telemetry HTTP/1.1
Host: localhost:1027
User-Agent: orion/2.4.0 libcurl/7.52.1
Fiware-Servicepath: /
Accept: application/json
Content-Length: 65
Content-Type: text/plain; charset=utf-8
Fiware-Correlator: 4ae608b0-d248-11ea-81de-000c29df7908
Ngsiv2-AttrsFormat: custom

[{ "temperature": "Device1", "humidity": "99", "battery": "15" }]

which is the expected result, with replacements.

Next, restart the listening process and update the entity this way (triggering a new notification):

curl localhost:1026/v2/entities/Device1/attrs?options=forcedUpdate -s -S -H 'Content-Type: application/json' -d @- <<EOF
{  
  "temperature": {
    "value": 32,
    "type": "Number"
  },
  "humidity": {
    "value": 79,
    "type": "Number"
  },
  "battery": {
    "value": 25,
    "type": "Number"  
  }
}
EOF

and I get now in nc:

POST /api/v1/telemetry HTTP/1.1
Host: localhost:1027
User-Agent: orion/2.4.0 libcurl/7.52.1
Fiware-Servicepath: /
Accept: application/json
Content-Length: 65
Content-Type: text/plain; charset=utf-8
Fiware-Correlator: 66278dd8-d248-11ea-822d-000c29df7908
Ngsiv2-AttrsFormat: custom

[{ "temperature": "Device1", "humidity": "79", "battery": "25" }]

Conclusion: according my tests, Orion is working as expected.

I'd suggest to have a close look to the steps above and try to identify any possible diference comparing with your case. Note the \$ in the subscription creation payload: it is needed to avoid bash vars replacement in curl. Maybe you are facing a similar problem? You can check how your subscription is with GET /v2/subscriptions or checking directly in the database (csubs collection).

fgalan
  • 11,732
  • 9
  • 46
  • 89
  • I never thought i had to scape $ character, no specified in documentation examples so thank you very much for your appointment. It's working properly right now. – José Checa Claudel Jul 30 '20 at 11:45
  • If you have found a document which wrong examples on this, please let me know so we can fix it. Thanks! – fgalan Jul 30 '20 at 16:38
  • Custom payload section at: https://fiware-orion.readthedocs.io/en/master/user/forbidden_characters/index.html#custom-payload-special-treatment – José Checa Claudel Jul 31 '20 at 10:15
  • Orion Context Broker Programming Manual found it in this google search: https://www.google.com/url?sa=t&rct=j&q=&esrc=s&source=web&cd=&ved=2ahUKEwivjbG3n_fqAhWHkhQKHVr0CDAQFjACegQIAhAB&url=https%3A%2F%2Fec.europa.eu%2Fcefdigital%2Fwiki%2Fdownload%2Fattachments%2F82773747%2FORION%2520CONTEXT%2520BROKER%2520-%2520Programmers%2520Manual%2520%2528EN%2529%255B1%255D.pdf%3Fversion%3D1%26modificationDate%3D1548153173293%26api%3Dv2&usg=AOvVaw0ede_pxPjueGfSVuv-u-5U – José Checa Claudel Jul 31 '20 at 10:17
  • With regards to the custom payload section on at https://fiware-orion.readthedocs.io/en/master/user/forbidden_characters/index.html#custom-payload-special-treatment note that what is shown there is a verbatim example of `httpCustom` fragment, agnostic from the tool in which that fragment is being used (curl or whatever). Thus, from my point of view that's not a wrong example (or maybe I'm missing something, in which case I'd kindly ask if you could elaborate on it). Same applies to the cited Orion Context Broker Programming Manual – fgalan Dec 29 '20 at 11:32