Timingproblem in Calculation?

Hello,

I have something like this:

Its a simple addtion every step.

But if i use the flow like in the screen, only every second step has an addition.

I tried to give y back as global and wired.

If i use a function to simulate the Databaseoutput with an incrementing number, i get the addition every step.

Is it possible that there is a timing problem with that circle ?

Greetings
Chorum

It's hard to say for sure without more specific details on what each step is doing - such as whether it is asynchronous or synchronous etc.

Have you tried adding any debug to the flow to see what is happening at each step?

yes, i followed the value the whole way.

in the function node with the calculation i see it very clearly. i setup a template node to watch the added values and the result in live.

the second thing what can happen is that i get alternating values on the result. like that:

10
8
11
9
12
10

its only a sum from 2 values. one from DB & one from flow.

if i exchange the DB value with an incrementing number made in the same funktion node, everything works fine. only one sum and that every step.

so i think the problem isnt my calculation.

i think i will build up a minimal flow to check this out...

Ok i set up a minimal example.

only a function node working with globals.

Code:

var summand1 = global.get('W16Zaehlerstandout'); // comes from Database
var summand2 = global.get('W16Steptime');
var result;

result = (summand1 + (summand2/1000)).toFixed(0);
global.set('Bhmini',result); //goes in to database

msg.payload.summand1 = summand1;
msg.payload.summand2 = summand2;
msg.payload.result = result;
return msg;

the problem stays... only every second step a addition to see in result

a second try:

var summand1 = global.get('W16Zaehlerstandout'); // comes from Database
var summand2 = global.get('W16Steptime');
var result;

var z1 = context.get('z1')||0;
var z1alt = context.get('z1alt')||0;

if (z1 == z1alt){
    z1++;
    z1alt = z1;
}else{
    

}

context.set("z1",z1) ;
context.set("z1alt",z1alt) ;


result = (z1 + (summand2/1000)).toFixed(0);
global.set('Bhmini',result); //goes in to database

msg.payload.summand1 = summand1;
msg.payload.summand2 = summand2;
msg.payload.result = result;
return msg;

z1 instead summand1 in the addition.

everything works fine...

so it seems that the way to the database and back has a problem...

do i have to think about node runtimes ?

What database node are you using? I know MSSQL-PLUS gives you a result you can use to check how many rows were modified.

are you certain database is actually getting updated?
are you certain database is actually getting re-read properly?

Also, it may be a flaw or bug in your real flow (you havent shared the actual flow only psuedo flows so we cant check)

the test flow is only a the function node with that code in it.
i exchanged summand1 with a fixed "1", so i only have summand2 as a dynamic value.

i use a sql Database

What i can see in the values is, that i send the correct value with the query but the value from the database is falling one step back.

maybe i cant write and read at the same time.
i will try 2 database nodes parallel.

That doesnt really help! There are LOTS of SQL databases and even more SQL nodes!



That info would have been useful upfront. Thats why i said ...



You mean in series right? as in [prepare data]--> [WRITE SQL] --> [READ SQL] --> [next node]

I only know its a mysql database...

The node to connect to the database is: node-red-node-mysql

The flow is simply to big to post it, so i use small examples.

the read and the write query come at the same moment (parallel) to 1 sql node

[prepare data WRITE ] -->[WRITE SQL]
[prepare data READ ] -->[READ SQL ]--> [Data to prepare data WRITE]

mhmmm ok i try to make that in series....

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