Parse message - how to cut a header

I am receiving a message with a http-in node, according to Nuki the callback function is supposed to deliver a JSON list. I want to extract from the list some values, but I am getting some header information in addition from the http-in node, some simple payload.mode doesn't work

[{"id":"897d8faf.9d9df8","type":"debug","z":"427fc89b.e34038","name":"Output","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":440,"y":2540,"wires":[]},{"id":"a11c1fb0.a08fe8","type":"tcp in","z":"427fc89b.e34038","name":"JSON","server":"server","host":"","port":"8186","datamode":"single","datatype":"utf8","newline":"{","topic":"","base64":false,"x":130,"y":2540,"wires":[["897d8faf.9d9df8"]]}]

The debug output gives me

POST / HTTP/1.0

User-Agent: NukiBridge_xxxxxxx

Host: 192.168.178.32

Connection: Close

Content-Type: application/json;charset=utf-8

Content-Length: 224

{"deviceType": 0, "nukiId": xxxxxxxx, "mode": 2, "state": 3, "stateName": "unlocked", "batteryCritical": false, "batteryCharging": false, "batteryChargeState": 40, "doorsensorState": 2, "doorsensorStateName": "door closed"}

I guess I need to remove the header before the "{", in order to be able parse each value, but I have no clue how to do that.

If you are receiving valid JSON, simply feed it through a JSON node and you will have a JS object that you can simply access the properties. See this page in the docs that will explain how to use the debug panel to find the right path to any data item.

@ueffchen the flow you have shared is using a TCP In node at the start.

If you are handling an incoming http request, you should be using the HTTP In node, which handles all the parsing for you.

@knolleary the http-in node needs an URL relative to a directory, whilst the TCP-in node simply listens to incoming data on a port. How to I set that in the http-in node?

You don't - you configure the HTTP In node to listen on a given path on the same port as the Node-RED server is listening on.

If you really need to listen on a different port, then you'll have to do the hard work of parsing the whole HTTP Request yourself - as well as generating the proper response to send back.

Personally, I'd stick with the HTTP In node as it does all that work for you and question why you can't do that.

My node red is a plugin to homematic.
I can enter into the Nuki, that is sending the JSON messages I want to retrieve, any IP/port I like.
Currently I have two target IPs in the Nuki:
The Nuki sends also a message to homematic on 8181. I can't use the same port for node red, tried that already.
Therefore I had to input a different port (same IP) in the Nuki for node red. For node red, the Nuki keylock sends a message to http://192.168.178.32:8186/ . I can enter that in the TCP-in but I have the unparsed data before the JSON list, as I described in my initial post. So, trying http-in now, but I don't really understand how that works.
A general question: How do I find out on which port the node red plugin listens to?
Is it not possible to enter a new port in the http-in node?
Assuming I can ony use one port: If I have i.e a second Nuki or a different server sending JSON lists, how to I make sure that this arrives in the target node? by adding a target directory to the URL? Would that then mean that the JSON data is written actually in the directory?

A general question: How do I find out on which port the node red plugin listens to?

It is the same ip/port you use to access the Node-RED editor

Is it not possible to enter a new port in the http-in node?

No

Assuming I can ony use one port: If I have i.e a second Nuki or a different server sending JSON lists, how to I make sure that this arrives in the target node? by adding a target directory to the URL? Would that then mean that the JSON data is written actually in the directory?

They are not directories. They are URL paths.

Lets say you access the Node-RED editor at http://127.0.0.1:1880

If you configure an HTTP In node with a path of /test then it would handle any HTTP request sent to http://127.0.0.1:1880/test.

You can configure another HTTP In node with a path of /test2 and it will handle requests sent to http://127.0.0.1:1880/test2.

my node red is simply on 192.168.178.32/addons/red without specific port, so I got that working by adding the URL /nuki to the parameter. The last point I struggled with was the wrong setting of http-in. Initially I set it to GET, because I thought it was GETting data, but I had to set to POST - I guess that's because the Nuki is POSTing data? Anyway, it is working now, thanks @knolleary

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