Function tried to send a message of type number

Hi,

i am trying to do some basic calculations but keep getting the error 'function tried to send a message of type number'.

I read most forum discussion and added = {}; in the beginning of the flow for all variables.. but this did not fix the issue.

var meting = {};
var gem = {};
var stddev = {};
var gemstd = {};
var metstd = {};


meting = msg.payload;
gem = msg.average;
stddev = flow.get("stddev");
gemstd = gem + stddev;
metstd = meting + stddev;

meting.payload= msg.payload;
meting.topic= "meting";
gem.payload= msg.average;
gem.topic= "gemiddelde";
gemstd.topic = "gem +stddev";
gemstd.payload = gemstd;
metstd.topic = "meting +stddev";
metstd.payload = metstd;

return [meting, gem, metstd, gemstd]

the issue is probably obvision, but I can't find it....

You are correctly creating empty messages at the start, but then you say, for example,

meting = msg.payload;

which destroys the empty message you had already created. Then you say

meting.payload= msg.payload;

which I am suprised does not generate an error. Possibly you intended to create a separate set of temporary variables instead of overwriting meting and the others.

1 Like

after some reading I figured I should take out the 'var meting = {};' and 'var gem = {};'
since it deletes the payload before i use them... But also making that change did not resolve the issue:

var stddev = {};
var gemstd = {};
var metstd = {};


var meting = msg.payload;
var gem = msg.average;
stddev = flow.get("stddev");
gemstd = gem + stddev;
metstd = meting + stddev;

meting.payload= meting;
meting.topic= "meting";
gem.payload= gem;
gem.topic= "gemiddelde";
gemstd.topic = "gem +stddev";
gemstd.payload = gemstd;
metstd.topic = "meting +stddev";
metstd.payload = metstd;

return [gemstd, metstd, meting, gem]

I think those are correct, it is the overwriting of them that is the problem

Thanks Colin, i Understand. fixed it!

var G = {};
var GS = {};
var M = {};
var MS = {};


var meting = msg.payload;
var gem = msg.average;
var stddev = flow.get("stddev");
var gemstd = gem + stddev;
var metstd = meting + stddev;

M.payload= meting;
M.topic= "meting";
G.payload= gem;
G.topic= "gemiddelde";
GS.topic = "gem +stddev";
GS.payload = gemstd;
MS.topic = "meting +stddev";
MS.payload = metstd;

return [G, GS, M, MS]

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