I want to make the difference from two values (spread) and multiply this value by a third, multiply the result by a constant and output the result in the dashboard as the thermal power (W).
but I don't know how to get the values of the 3 registers as msg.payload for a function.
Any idea ?
See this article in the cookbook for an example of how to join messages into one object.
Then you can access them in msg.payload.x and msg.payload.y to do your math.
I got my values: {"40012":26.7,"40017":26,"40072":0} in debug
but how can I link them mathematically and output the result ?
("40012"-"40017") * "40072" * "69,45" = output
var temp = (msg.payload.a - msg.payload.b) * msg.payload.c * msg.payload.d
msg.originalPayload = msg.payload; //save for later debugging / verifying results
msg.payload = temp;
return msg; //this causes the msg to be sent out the output & on to the next node
As for what msg.payload.a and msg.payload.b should really be - use the copy path from the debug output
The general syntax for accessing JavaScript object (like msg) properties is that any property can be accessed quoted in brackets with a double or singe quote (" or '), e.g. msg.payload['123'], msg.payload['temperature'], or msg.payload["my property"].
Alternatively if the property name consists of only alphanumerical characters or underscores, it can be accessed with just a period as a separator, e.g. msg.payload.temp1 or msg.payload.my_property. The property cannot start with a number though.
In this case yes. The property names (object keys) are always strings (not numbers) internally in JavaScript. In the case of numbers the numeric keys are translated to strings, e.g. msg.payload[123] becomes msg.payload['123'].
The same does not apply if the key is alphanumerical though. This is why I said "the general syntax". msg.payload[temperature] for example would mean that variable named temperature would contain the key. I hope this makes sense.