How can I recover a json message from a distant server?

I would like to recover a JSON message in node-red from a distant server

I've tried with a node "tcp-in"

but I don't know if it's a good solution because I don't have only the JSON....

what's the node better for me ?

I want to extract json part in a message with node red

I receive the message in node red but I can't extract the data
exemple of message:

POST / HTTP/1.1

Host: xxx.xx.xxx.5:9000

User-Agent: libcurl-agent/1.0

Content-type: application/json

Accept: application/json

Content-Length: 526   
   {
   "timestamp": 1571997083,
   "data": {
      "temperature": 20.613545532227,
      "humidity": 61.3828125,
      "battery": 3.47
   },
   "frame": "814962xxxx16a1dc5",
   "gatewayID": "AA555Axxxx0xx964",
   "othersGW": [],
   "clientID": "xxxx",
   "DevAddr": "011xxxxb",
   "DevEUI": "8cf9xxx000000xxx",
   "sensorInstallId": "8cf95xxx0000xxxx",
   "loraPort": 8,
   "fcnt": 1607,
   "rxpk": {
      "tmst": 2380181019,
      "time": "2019-10-25T09:51:23.472998Z",
      "chan": 0,
      "rfch": 0,
      "freq": 867.1,
      "stat": 1,
      "modu": "LORA",
      "datr": "SF7BW125",
      "codr": "4/5",
      "lsnr": 9,
      "rssi": -72,
      "size": 22,
      "data": "xxxxxxxxxxxxxxxx/YxWg=="
   }
}

so I would like to have data of temperature etc... and I don't know the node I have to use

Thanks a lot

You can receive data from the device using curl ?
In node-red you can use the http request node.

Hi, you asked this same question on stack overflow a couple days ago and received a lot of replies there.

If the remote server is sending it as an http request to your Node-RED instance then you should use the HTTP In node to receive it which will parse the response and the values you want will be in msg.payload.

thank you but if I ask the question on the forum nodered as indicated is that I can not do it ...
and I'm looking for help.

But you have asked exactly the same question and ignored all the answers you have received. So now you will get a lot of the same answers because we don't know what you have tried.

Have you tried the HTTP In node to receive the request? If not, why not? If you have, then what problem did you hit?

yes I have tried the HTTP IN but doesn't work

Can you explain what part of it does not work? By stating "doesn't work" without additional information, for example on how you used it and what your flow looked like we can't offer suggestions on how to fix it to make it work in the end.

https://nodered.org/docs/user-guide/messages

1 Like

image

I've nothing in debug
but I can read a message when I listen the port 9000 with the "TCP IN"

Could you set the debug node to show the complete msg object ?

Can you try to explain how you think the HTTP-In node works, because based on your screenshot and this message I think you have a different working in mind than how it works.
Take a look at the following from the built-in description for this node:

The following is an example from one of my own flows in creating a callback for a Spotify OAuth request. It includes an HTTP In node, various in-betweens for doing the requested action, and an HTTP Response node.

What is going on here is that when I go to the address my device is on, with the path /oauth/neela/spotify-callback that flow is triggered, and in the end the payload coming in to the http (200) node in the flow shown is posted back in the page that is requested.

Does this kind of behaviour match the thing you're trying to do, or not at all?

in fact... that's what I said in my first message :a server push me a message


I can read on the port 9000 this message:

POST / HTTP/1.1

Host: xxx.xx.xxx.5:9000

User-Agent: libcurl-agent/1.0

Content-type: application/json

Accept: application/json

Content-Length: 526   
   {
   "timestamp": 1571997083,
   "data": {
      "temperature": 20.613545532227,
      "humidity": 61.3828125,
      "battery": 3.47
   },
   "frame": "814962xxxx16a1dc5",
   "gatewayID": "AA555Axxxx0xx964",
   "othersGW": [],
   "clientID": "xxxx",
   "DevAddr": "011xxxxb",
   "DevEUI": "8cf9xxx000000xxx",
   "sensorInstallId": "8cf95xxx0000xxxx",
   "loraPort": 8,
   "fcnt": 1607,
   "rxpk": {
      "tmst": 2380181019,
      "time": "2019-10-25T09:51:23.472998Z",
      "chan": 0,
      "rfch": 0,
      "freq": 867.1,
      "stat": 1,
      "modu": "LORA",
      "datr": "SF7BW125",
      "codr": "4/5",
      "lsnr": 9,
      "rssi": -72,
      "size": 22,
      "data": "xxxxxxxxxxxxxxxx/YxWg=="
   }
}

that I want to do is to extract data like temperature .... and I don't know what node to use

@chris35 again, use the HTTP In node. The example you shared where you tried to use it is incorrectly configured and will not work. @afelix has tried to show you where you went wrong, but you do not appear to have read her reply fully.

  1. Add an HTTP In node.
  2. Configure the URL to be /my-data and the method to be POST.
  3. Configure the remote system to send its request to http://<ip-of-machine-running-node-red>/my-data
  4. Connect the HTTP In node to a Debug node

Here is a method to get at the JSON

[{"id":"c07cfd49.9ee07","type":"inject","z":"3da0d845.11d708","name":"","topic":"","payload":"POST / HTTP/1.1  Host: xxx.xx.xxx.5:9000  User-Agent: libcurl-agent/1.0  Content-type: application/json  Accept: application/json  Content-Length: 526       {    \"timestamp\": 1571997083,    \"data\": {       \"temperature\": 20.613545532227,       \"humidity\": 61.3828125,       \"battery\": 3.47    },    \"frame\": \"814962xxxx16a1dc5\",    \"gatewayID\": \"AA555Axxxx0xx964\",    \"othersGW\": [],    \"clientID\": \"xxxx\",    \"DevAddr\": \"011xxxxb\",    \"DevEUI\": \"8cf9xxx000000xxx\",    \"sensorInstallId\": \"8cf95xxx0000xxxx\",    \"loraPort\": 8,    \"fcnt\": 1607,    \"rxpk\": {       \"tmst\": 2380181019,       \"time\": \"2019-10-25T09:51:23.472998Z\",       \"chan\": 0,       \"rfch\": 0,       \"freq\": 867.1,       \"stat\": 1,       \"modu\": \"LORA\",       \"datr\": \"SF7BW125\",       \"codr\": \"4/5\",       \"lsnr\": 9,       \"rssi\": -72,       \"size\": 22,       \"data\": \"xxxxxxxxxxxxxxxx/YxWg==\"    } }","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":666,"y":198,"wires":[["8115857.60bb578"]]},{"id":"4aa31be9.5e95f4","type":"debug","z":"3da0d845.11d708","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":1144,"y":198,"wires":[]},{"id":"8115857.60bb578","type":"change","z":"3da0d845.11d708","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"\"{\" & $substringAfter(payload, \"{\")\t","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":830,"y":198,"wires":[["67871c2b.8e0334"]]},{"id":"67871c2b.8e0334","type":"json","z":"3da0d845.11d708","name":"","property":"payload","action":"obj","pretty":false,"x":984,"y":198,"wires":[["4aa31be9.5e95f4"]]}]

cymplecy thank's a lot : it works...

ok I will test.... excuse me for my bad english

Hello
I test the method of knolleary but it's don' t work:
in the part 2 : I've only to put /my-data in URL ? nothing else ?
in the part 4 : nothing in debug Node

Thanks

Did you follow step 3 as well?

yes for me it's ok for 3

@chris35 Please provide a screenshot of the HTTP In node showing how you have configured it.