# Calculate rain precipitation from URL with columns

**URL:** <https://discourse.nodered.org/t/calculate-rain-precipitation-from-url-with-columns/25849>\
**Category:** General\
**Created:** [1 May 2020 06:46 UTC](https://discourse.nodered.org/t/calculate-rain-precipitation-from-url-with-columns/25849 "2020-05-01T06:46:23Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![HaVi](https://avatars.discourse-cdn.com/v4/letter/h/b3f665/32.png) [@HaVi](https://discourse.nodered.org/u/HaVi)\
**Post date:** [1 May 2020 06:46 UTC](https://discourse.nodered.org/t/calculate-rain-precipitation-from-url-with-columns/25849/1 "2020-05-01T06:46:23Z")

</div>

Via the URL [https://gpsgadget.buienradar.nl/data/raintext/?lat=52.37&lon=4.89](https://gpsgadget.buienradar.nl/data/raintext/?lat=52.37&lon=4.89) I can get the expected rainfall for the next two hours for a GPS location. This is shown in two columns, the amount of precipitation on the left and the time per 5 minutes on the right.

Although I get a JSON Parse Error I can request the two columns in NR with a http request (see attachment).

I would like to calculate the rainfall for the next hour so I have to add the first twelve values from the left column. Can someone explain to me how I can properly request the data and then calculate the rainfall for the next hour?

 ![get](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/9/a/9aeea0f4a74b43becd21b56673a2ddd0c0c7a313.png)

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [1 May 2020 06:51 UTC](https://discourse.nodered.org/t/calculate-rain-precipitation-from-url-with-columns/25849/2 "2020-05-01T06:51:52Z")

</div>

Its not JSON so switch that option off.  
Next try feeding the payload to a split node.

---

<div class="post-metadata">

**Author:** ![HaVi](https://avatars.discourse-cdn.com/v4/letter/h/b3f665/32.png) [@HaVi](https://discourse.nodered.org/u/HaVi)\
**Post date:** [1 May 2020 07:08 UTC](https://discourse.nodered.org/t/calculate-rain-precipitation-from-url-with-columns/25849/3 "2020-05-01T07:08:12Z")

</div>

Thanks Steve, the JSON error is not showing anymore. I've added the split node and now the rows are shown separately (see attachment).

I have too little experience with NR to work this out further, so I hope someone can explain to me exactly how to do this.

 ![split](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/1/f/1fe6b934d639fef61b5ffbb29ce0c37bb8e3146e.png)

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [1 May 2020 07:17 UTC](https://discourse.nodered.org/t/calculate-rain-precipitation-from-url-with-columns/25849/4 "2020-05-01T07:17:32Z")

</div>

Could you export your flow and

`````  
`paste it between backticks like this`  
`````

Myself or another kind member will help you out

---

<div class="post-metadata">

**Author:** ![HaVi](https://avatars.discourse-cdn.com/v4/letter/h/b3f665/32.png) [@HaVi](https://discourse.nodered.org/u/HaVi)\
**Post date:** [1 May 2020 07:51 UTC](https://discourse.nodered.org/t/calculate-rain-precipitation-from-url-with-columns/25849/5 "2020-05-01T07:51:55Z")

</div>

Thanks again! Would be great if someone can help me out 😉

```auto
[{"id":"c0785c86.682e","type":"tab","label":"Flow 2","disabled":false,"info":""},{"id":"a322a220.a74e9","type":"http request","z":"c0785c86.682e","name":"GET Data","method":"GET","ret":"txt","paytoqs":false,"url":"https://gpsgadget.buienradar.nl/data/raintext/?lat=52.37&lon=4.89","tls":"","persist":false,"proxy":"","authType":"","x":400,"y":100,"wires":[["b7bc2e91.ccb9a"]]},{"id":"7d17f83d.1d5638","type":"inject","z":"c0785c86.682e","name":"","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":220,"y":100,"wires":[["a322a220.a74e9"]]},{"id":"6df9daa3.ba89a4","type":"debug","z":"c0785c86.682e","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":750,"y":100,"wires":[]},{"id":"b7bc2e91.ccb9a","type":"split","z":"c0785c86.682e","name":"","splt":"\\n","spltType":"str","arraySplt":1,"arraySpltType":"len","stream":true,"addname":"topic","x":570,"y":100,"wires":[["6df9daa3.ba89a4"]]}]

```

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [1 May 2020 08:14 UTC](https://discourse.nodered.org/t/calculate-rain-precipitation-from-url-with-columns/25849/6 "2020-05-01T08:14:33Z")

</div>

To get you started...  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/f/f/ff29d790cb2610ab40416aaad2e188ef5ef8cdab.png)

```auto
[{"id":"c18a41c1.78301","type":"http request","z":"c90da02f.d57d2","name":"GET Data","method":"GET","ret":"txt","paytoqs":false,"url":"https://gpsgadget.buienradar.nl/data/raintext/?lat=52.37&lon=4.89","tls":"","persist":false,"proxy":"","authType":"","x":740,"y":100,"wires":[["745545df.f5010c"]]},{"id":"5bfe12a7.97f05c","type":"inject","z":"c90da02f.d57d2","name":"","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":580,"y":100,"wires":[["c18a41c1.78301"]]},{"id":"745545df.f5010c","type":"function","z":"c90da02f.d57d2","name":"split and map","func":"//first split each line into an array\nvar lines = msg.payload.trim().split(\"\\n\");\n\n//next map each element of the lines\n//array into an object with .time and .value\nvar errors = [];\nvar count = lines ? lines.length : 0;\nvar data = [];\nif(count){\n data = lines.map((e) =>{\n try{\n let parts = e.split(\"|\");\n return {\n time: parts[1].trim(),\n value: parseInt(parts[0])\n } \n } catch(error) {\n errors.push(\"Error splitting '\" + e + \"': \" + error)\n }\n }) \n}\n\n//return the data\nmsg.payload = {\n count,\n errors,\n data\n}\n\nreturn msg;","outputs":1,"noerr":0,"x":570,"y":180,"wires":[["9b0d5e51.65864"]]},{"id":"9b0d5e51.65864","type":"debug","z":"c90da02f.d57d2","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":740,"y":180,"wires":[]}]

```

---

<div class="post-metadata">

**Author:** ![HaVi](https://avatars.discourse-cdn.com/v4/letter/h/b3f665/32.png) [@HaVi](https://discourse.nodered.org/u/HaVi)\
**Post date:** [1 May 2020 08:24 UTC](https://discourse.nodered.org/t/calculate-rain-precipitation-from-url-with-columns/25849/7 "2020-05-01T08:24:11Z")

</div>

Hi Steve,

Very helpfull and appreciated, thanks!

Best regards, Hans.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [30 June 2020 08:24 UTC](https://discourse.nodered.org/t/calculate-rain-precipitation-from-url-with-columns/25849/8 "2020-06-30T08:24:21Z")

</div>

Closed on 30 June 2020 08:24 UTC

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