# Receive real time data

**URL:** <https://discourse.nodered.org/t/receive-real-time-data/28702>\
**Category:** General\
**Created:** [21 June 2020 23:50 UTC](https://discourse.nodered.org/t/receive-real-time-data/28702 "2020-06-21T23:50:11Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![seyeon](https://avatars.discourse-cdn.com/v4/letter/s/3bc359/32.png) [@seyeon](https://discourse.nodered.org/u/seyeon)\
**Post date:** [21 June 2020 23:50 UTC](https://discourse.nodered.org/t/receive-real-time-data/28702/1 "2020-06-21T23:50:11Z")

</div>

Receive real-time data once every 10 seconds.

 ![스크린샷 2020-06-22 오전 8.42.29](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/e/b/ebec622a5beffeb9ada2c94af48720f560bbd0b0.png)

I'm a student and beginner.  
I want to average the data. (by 10 times)  
I think... First, sort the data that is measured once every 10 seconds...  
I've tried many times, but I don't know how. 😢

---

<div class="post-metadata">

**Author:** ![Trying\_to\_learn](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/trying_to_learn/32/28400_2.png) [@Trying\_to\_learn](https://discourse.nodered.org/u/Trying_to_learn)\
**Post date:** [22 June 2020 00:12 UTC](https://discourse.nodered.org/t/receive-real-time-data/28702/2 "2020-06-22T00:12:04Z")

</div>

Hi and welcome to _Node-Red_.

> [@seyeon](#):
>
> I want to average the data. (by 10 times)

I'm not sure I understand the question.

Say you are getting: 2 5 7 5 9 3 1 7 9 4

You want the average of those numbers?

---

<div class="post-metadata">

**Author:** ![Trying\_to\_learn](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/trying_to_learn/32/28400_2.png) [@Trying\_to\_learn](https://discourse.nodered.org/u/Trying_to_learn)\
**Post date:** [22 June 2020 00:28 UTC](https://discourse.nodered.org/t/receive-real-time-data/28702/3 "2020-06-22T00:28:38Z")

</div>

Here is a basic flow that shows you what to do.

You will have to change things to make it work as you want.

```auto
[{"id":"799cc16e.505f18","type":"inject","z":"b9924a74.4d98f8","name":"","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":250,"y":2530,"wires":[["85be1c1d.8b3928"]]},{"id":"85be1c1d.8b3928","type":"random","z":"b9924a74.4d98f8","name":"","low":"1","high":"10","inte":"true","property":"payload","x":250,"y":2570,"wires":[["f95b8e2b.24fa98"]]},{"id":"f95b8e2b.24fa98","type":"join","z":"b9924a74.4d98f8","name":"","mode":"custom","build":"array","property":"payload","propertyType":"msg","key":"topic","joiner":"\\n","joinerType":"str","accumulate":false,"timeout":"","count":"3","reduceRight":false,"reduceExp":"","reduceInit":"","reduceInitType":"","reduceFixup":"","x":580,"y":2570,"wires":[["6dcc8c5f.9e1664","a6bdfd63.1d7ab8"]]},{"id":"6dcc8c5f.9e1664","type":"debug","z":"b9924a74.4d98f8","name":"Just to show you what is happening.","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","x":820,"y":2610,"wires":[]},{"id":"a6bdfd63.1d7ab8","type":"function","z":"b9924a74.4d98f8","name":"Average","func":"// This is a basic way to do it.\n// You will have to add extra lines\n// to get all 10 values and change the last\n// line to `/ 10` and not `/ 3`\n\nx = msg.payload[0];\n//node.warn(x);\nx = x + msg.payload[1];\n//node.warn(x);\nx = x + msg.payload[2];\n//node.warn(x);\nx = x / 3;\nmsg.payload = x;\nreturn msg;","outputs":1,"noerr":0,"x":730,"y":2570,"wires":[["140608e8.a14c37"]]},{"id":"140608e8.a14c37","type":"debug","z":"b9924a74.4d98f8","name":"Result","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","x":870,"y":2570,"wires":[]},{"id":"d20bcf7f.07deb","type":"comment","z":"b9924a74.4d98f8","name":"This is your flow here.","info":"","x":630,"y":2530,"wires":[]},{"id":"a21efb2d.b420c8","type":"comment","z":"b9924a74.4d98f8","name":"Simulation. Press 3 times to see what happens.","info":"","x":260,"y":2490,"wires":[]}]

```

---

<div class="post-metadata">

**Author:** ![seyeon](https://avatars.discourse-cdn.com/v4/letter/s/3bc359/32.png) [@seyeon](https://discourse.nodered.org/u/seyeon)\
**Post date:** [22 June 2020 00:34 UTC](https://discourse.nodered.org/t/receive-real-time-data/28702/4 "2020-06-22T00:34:13Z")

</div>

real time data is blue color text(msg.payload)  
I want to avg of payload numbers ;  
49.9827, 49.9449, 60.1888, 68.110099999 ••• (average of every 10 times)

Did you get that?

---

<div class="post-metadata">

**Author:** ![Trying\_to\_learn](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/trying_to_learn/32/28400_2.png) [@Trying\_to\_learn](https://discourse.nodered.org/u/Trying_to_learn)\
**Post date:** [22 June 2020 00:38 UTC](https://discourse.nodered.org/t/receive-real-time-data/28702/5 "2020-06-22T00:38:42Z")

</div>

The flow I posted does that for **three** numbers.

Look at the node called `average` and edit it to do it for **ten** numbers, not three.

What is happening with the flow:

The first two nodes are **simulation**.

Press the `inject` node three times and you will get an average in the `result` node.

The `join` node is used to create an _array_ which can then be handled by the next node.  
You will have to change that to be `10` and not `3` as it is now.

Then edit the `average` node as I said above.

That will do a basic job of giving you an average from ten inputs.

Can you understand how I wrote the code?

This is the `join` node part you need to change.

 ![Screenshot from 2020-06-22 10-40-01](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/5/9/59b09c01d337ad53b512bfe241b2b250fe64d1c2.png)

---

<div class="post-metadata">

**Author:** ![seyeon](https://avatars.discourse-cdn.com/v4/letter/s/3bc359/32.png) [@seyeon](https://discourse.nodered.org/u/seyeon)\
**Post date:** [22 June 2020 02:09 UTC](https://discourse.nodered.org/t/receive-real-time-data/28702/6 "2020-06-22T02:09:57Z")

</div>

![스크린샷 2020-06-22 오전 11.05.39](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/c/8/c89cb6ddf8cbb7b305315da302fef951b2cd6949.png)

Amazing...!!!!  
Thanks for everything.  
you're the best teacher ever.

---

<div class="post-metadata">

**Author:** ![Trying\_to\_learn](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/trying_to_learn/32/28400_2.png) [@Trying\_to\_learn](https://discourse.nodered.org/u/Trying_to_learn)\
**Post date:** [22 June 2020 02:29 UTC](https://discourse.nodered.org/t/receive-real-time-data/28702/7 "2020-06-22T02:29:40Z")

</div>

Looking at your screen shot though that is only using 6 values.

You said 10.

Just checking, because sometimes mistakes like that can bite you further down the track and you can't understand what is going on.

Just to be 100% sure, look at the picture below. Those two nodes.

Export them and post the code.

 ![스크린샷 2020-06-22 오전 11.05.39](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/8/4/849eeb0854d89d66777746e184aa3f18e450ac82.png)

This is done by drag-selecting the nodes then selecting EXPORT from the menu (top right of the screen.)

![Screenshot from 2020-06-22 12-25-45](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/0/8/08aa4e6145a6ef340641d04eb04a29833d9c716a.png)

and pasting the code in your reply and inserting it correctly.

This is done by clicking the `</>` button at the top of the edit screen, and pasting the code then.

---

<div class="post-metadata">

**Author:** ![seyeon](https://avatars.discourse-cdn.com/v4/letter/s/3bc359/32.png) [@seyeon](https://discourse.nodered.org/u/seyeon)\
**Post date:** [22 June 2020 02:37 UTC](https://discourse.nodered.org/t/receive-real-time-data/28702/8 "2020-06-22T02:37:12Z")

</div>

Thank you for the reply and Thank you for your concern.  
it' just a test. i understand! 😁

---

<div class="post-metadata">

**Author:** ![Trying\_to\_learn](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/trying_to_learn/32/28400_2.png) [@Trying\_to\_learn](https://discourse.nodered.org/u/Trying_to_learn)\
**Post date:** [22 June 2020 02:38 UTC](https://discourse.nodered.org/t/receive-real-time-data/28702/9 "2020-06-22T02:38:20Z")

</div>

OK.

All good. I just wanted to be sure you understand the _tricks_ involved in doing what you want and do understand all the things that needed to be changed to get it working as you described.

All good. Enjoy!

---

<div class="post-metadata">

**Author:** ![edje11](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/edje11/32/572_2.png) [@edje11](https://discourse.nodered.org/u/edje11)\
**Post date:** [22 June 2020 15:41 UTC](https://discourse.nodered.org/t/receive-real-time-data/28702/10 "2020-06-22T15:41:23Z")

</div>

Have a look at the node-red-contrib-calculate node.  
Is very easy to average and release every 10 samples.

---

<div class="post-metadata">

**Author:** ![seyeon](https://avatars.discourse-cdn.com/v4/letter/s/3bc359/32.png) [@seyeon](https://discourse.nodered.org/u/seyeon)\
**Post date:** [23 June 2020 01:51 UTC](https://discourse.nodered.org/t/receive-real-time-data/28702/11 "2020-06-23T01:51:33Z")

</div>

Thanks for telling me 🙂

---

<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:** [7 July 2020 01:51 UTC](https://discourse.nodered.org/t/receive-real-time-data/28702/12 "2020-07-07T01:51:45Z")

</div>

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