HTTP Integration - Custom Body

Hi Everyone,

I have a Web API for an IoT Platform that I’d like to push data to using the TTN HTTP Integration

I can use postman to push data - successfully

I am stuck for some example HTTP integrations to see how things are done…

Issue 1: exact format for multiple header params (does it use a ‘;’ seperator or comman ? or something else JSON?

Issue 2:
The Web API I must use has a very specific custom JSON format and wont accept the TTN JSON as it stands.

I have a LoRaWAN device that monitors Temperature / Humidity but the Web API requires a seperate POST for temperature and second POST for humidity. So I will need two HTTP integrations attached to the device.

I haven’t been able to find an example anywhere on how I would separate out the temperature from the TTN JSON payload in order to add to my HTTP Body

I have my Postman setup below:

URL: https://xxx.io/api/sensor/v2/observations
Params: streamid=xxx_test_ttn_lansitec-temp
Authorizations: Basic Auth [username] [password]
Headers: Content-Type = application/json
Accept = application/json
Body:
{
“results” : [
{
“t” : “2016-11-12T00:00:00.000Z”,
“v” : {
“v” : 1.0
}
}
]
}

What I can’t work out is how to substitute t and v into the HTTP Body:

  • Time as t
  • Temperature Value as v

PS: I noticed the documentation and video for HTTP Integration don’t reflect the current page which now has separated out the authorization, custom header name, custom header value. I don’t see an option for custom body. I can imagine at some point there would be a need to add a javascript to convert payload_fields => custom http body -

Should I modify my decoder to be like the HTTP body I need?
As currently send data to another integration that uses all the JSON data.

Your Thoughts?

PS: Apologies for miss categorizing i couldn’t find a category for integration

PS requestb.in isn’t working for me but https://requestbin.fullcontact.com/ does work (unsure of firewall related)

I did not fully understood the post, however I do not think there is a way to transform a single packet to two different posts - its a strange need.
You may either program a “splitter” on a web server, that receives one POST from TTN and sends two POST to your platform, or program your device in order to send packets that alternate temperature and humidity, with waste of airtime (or also change platform to a more flexible one :wink: ).

1 Like

You will need to use an intermediate system that splits the data and posts it. The payload decoder does not provide the option to perform two separate posts.
I would look into using either node or node-red with an mqtt subscription to get the data and to perform the post data to the IoT platform.

2 Likes

What me and @kersing suggested is that you create a splitter in some place. In addition to the method proposed by @kersing, you can use http integration towards a simple script in a language of your choice on some hosting, that receives the JSON, iterates through the payload_fields property, and for each variable you post towards the IoT platform (using cURL like libraries). Maybe 20 lines of code.

1 Like

…and if you don’t want some hosting to be running continuously, see also HTTP integration with Azure Functions (testing) and TTN to Azure Functions - Downlink and Uplink.

or if you like an amazon flavour, you could use some Amazon Lambdas

This could be a way to do it (check the XMLHttpRequest class in Javascript), but I do not expect all libraries being available for a decoder function. Regarding elegance, side effects in functions are not particularly elegant :slight_smile:
If you already have programmed a splitter, it’s one step more for data, but at the end there shouldn’t be much traffic.

1 Like

Like already noted:

@kersing is right: it’s just bare JavaScript (ECMAScript5 to be precise). It does not add anything to support HTTP (even more: it does not even include any library to make parsing the number array bytes easier).

(Also, it can run for at most 100 ms, mainly to limit resources, but as an application might want to respond with a downlink processing should be fast too.)

1 Like

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.