# Problem combining data from two Serial ports

**URL:** <https://discourse.nodered.org/t/problem-combining-data-from-two-serial-ports/76693>\
**Category:** General\
**Created:** [18 March 2023 16:32 UTC](https://discourse.nodered.org/t/problem-combining-data-from-two-serial-ports/76693 "2023-03-18T16:32:05Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![yzerman](https://avatars.discourse-cdn.com/v4/letter/y/ce7236/32.png) [@yzerman](https://discourse.nodered.org/u/yzerman)\
**Post date:** [18 March 2023 16:32 UTC](https://discourse.nodered.org/t/problem-combining-data-from-two-serial-ports/76693/1 "2023-03-18T16:32:05Z")

</div>

Hi I am using two external devices connected to two COM ports.  
The data coming to COM 1 is at 50Hz rate. The data coming to COM2 is at 10Hz rate  
I am parsing the data from COM1 and I have:

`msg.payload = {"timestamp":1234, "P1":123} //This is at 50Hz`

from COM2 I have:

`msg.payload = {"P2":456}// This is at 10Hz`

I need to include P2 into the COM1 data when there is new value. So I save it value to  
`flow.set("P2",p2)`

then into COM1 data I am doing this:

```auto
let p2 = flow.get("P2");
let dataFrom1 = {
{"timestamp":1234, "P1":123, "P2":p2}
} 
flow.set("P2",'')

msg.payload = dataFrom1

```

as the data from COM2 is at 10Hz and the data from COM1 is at 50Hz, I must have p2 value on every 10-th COM1 data. Unfortunately this is not consistent. Vary between 6th and 12th. Does anyone have idea why the data is not updated at every 10th data vale from COM1?

Thanks in advance!

---

<div class="post-metadata">

**Author:** ![TotallyInformation](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/totallyinformation/32/31_2.png) [@TotallyInformation](https://discourse.nodered.org/u/TotallyInformation)\
**Post date:** [18 March 2023 17:34 UTC](https://discourse.nodered.org/t/problem-combining-data-from-two-serial-ports/76693/2 "2023-03-18T17:34:05Z")

</div>

> [@yzerman](#):
>
> as the data from COM2 is at 10Hz and the data from COM1 is at 50Hz, I must have p2 value on every 10-th COM1 data. Unfortunately this is not consistent. Vary between 6th and 12th. Does anyone have idea why the data is not updated at every 10th data vale from COM1?

Hard to say for sure but I suspect that you are hitting the same problem as in another recent thread. You are relying on exact timing in node-red and that does not work because not only is node-red not a realtime system neither is its underlying OS.

Therefore, you will never get exact timings on any input data. If you need realtime processing, you need to do it on a realtime system not a general purpose system.

---

<div class="post-metadata">

**Author:** ![yzerman](https://avatars.discourse-cdn.com/v4/letter/y/ce7236/32.png) [@yzerman](https://discourse.nodered.org/u/yzerman)\
**Post date:** [18 March 2023 18:48 UTC](https://discourse.nodered.org/t/problem-combining-data-from-two-serial-ports/76693/3 "2023-03-18T18:48:23Z")

</div>

Thank you very much for your answer. But if the data comes with 10Hz stable, isn't it be able to update a variable at same frequency?

---

<div class="post-metadata">

**Author:** ![TotallyInformation](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/totallyinformation/32/31_2.png) [@TotallyInformation](https://discourse.nodered.org/u/TotallyInformation)\
**Post date:** [19 March 2023 00:03 UTC](https://discourse.nodered.org/t/problem-combining-data-from-two-serial-ports/76693/4 "2023-03-19T00:03:42Z")

</div>

Not necessarily. Even a 1Hz signal might not be exactly processed as 1Hz. This is not the fault of Node-RED, it is simply that:

- Linux has many other processes running and some may throw off the timing
- Node-RED is a node.js app and node.js is mostly single threaded so any number of processes hitting the thread can throw off the exact timing.

If you want exact ms or better timing, use a microprocessor with sufficient power and with a real-time OS such as the ESP32.

---

<div class="post-metadata">

**Author:** ![yzerman](https://avatars.discourse-cdn.com/v4/letter/y/ce7236/32.png) [@yzerman](https://discourse.nodered.org/u/yzerman)\
**Post date:** [19 March 2023 10:28 UTC](https://discourse.nodered.org/t/problem-combining-data-from-two-serial-ports/76693/5 "2023-03-19T10:28:29Z")

</div>

Thank you very much! I will try with ESP32

---

<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:** [18 May 2023 10:29 UTC](https://discourse.nodered.org/t/problem-combining-data-from-two-serial-ports/76693/6 "2023-05-18T10:29:12Z")

</div>

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