Confusing error

I am getting an error in a flow.

{"message":"ReferenceError: IP_Address is not defined (line 3, col 60)","source":{"id":"ee68941a.7bad58","type":"function","name":"TimeStamp","count":1}}

Note: line 3 column 60

Entering ee68941a.7bad58 into the search I get a node. function called TimeStamp.
That bit is good.

But....

This is the code from said node:

var time = new Date().toLocaleString();
//msg.payload = time + " Test message";
//node.warn(msg.payload.WIFI_DEVICE);
msg.payload = time + " " + msg.payload.IP_Address + " >" + msg.payload.WIFI_DEVICE + "<";
msg.time = time;
return msg;

Line 3 is a remark.

Putting that aside, and looking at line 4 (column 60)
That isn't right either.

Can someone help me work out where this error is?

Put a debug node on the output of the node feeding the function node and have it display the complete msg object then you can see if msg.payload.IP_Address exists coming into the function node.

I'm waiting for the bug to again stick his/their head up.

:sleeping:

I hope this is it:

{"topic":"STATUS/WIFIDEVICEID","payload":"{\"WIFI_DEVICE\":\"GPS\",\"IP_Address\":\"192.168.1.4\"}","qos":0,"retain":false,"_msgid":"6ec38677.69fe88","time":"2019-6-13 15:40:39","ttl":0,"_queuetimestamp":1560404439925,"_queueCount":3}
{"topic":"STATUS/WIFIDEVICEID","payload":"{\"WIFI_DEVICE\":\"GPS\",\"IP_Address\":\"192.168.1.4\"}","qos":0,"retain":false,"_msgid":"6a3faeb1.cb12","time":"2019-6-13 15:40:42","ttl":0,"_queuetimestamp":1560404442423,"_queueCount":2}
{"topic":"STATUS/WIFIDEVICEID","payload":"{\"WIFI_DEVICE\":\"GPS\",\"IP_Address\":\"192.168.1.4\"}","qos":0,"retain":false,"_msgid":"912ba1fe.22654","time":"2019-6-14 05:39:16","ttl":0,"_queuetimestamp":1560454756656,"_queueCount":1}
{"topic":"STATUS/WIFIDEVICEID","payload":"{\"WIFI_DEVICE\":\"GPS\",\"IP_Address\":\"192.168.1.4\"}","qos":0,"retain":false,"_msgid":"6f20281d.e8e578","time":"2019-6-14 05:39:21","ttl":0,"_queuetimestamp":1560454761191,"_queueCount":0}

I am tracking a few problems with WiFi, connections, etc.
I have log files coming out of.... (well, you get the rest) I don't know why but something is going on.

I got those lines from the "RAW IFF" file which just logs the IFF messages coming in.
(As you suggested)
Then they go through the other nodes and get saved as something useful to me.

To help myself I also inject a MARK here and there which is basically a line with the date/time so if I am looking for something I can section it off with respect to the mark.

Strangely those 4 messages didn't make it through to the rest of the nodes.

But look at this picture and I hope it helps also with what is going on.

And this is the suspect node code:

var time = new Date().toLocaleString();
//msg.payload = time + " Test message";
//node.warn(msg.payload.WIFI_DEVICE);
msg.payload = time + " " + msg.payload.IP_Address + " >" + msg.payload.WIFI_DEVICE + "<";
msg.time = time;
return msg;

Or maybe this one:

if (msg.topic == "TIMESTAMP")
{
    return msg;
}
var time_ = new Date().toLocaleString();
var WIFI_DEVICE = msg.payload.WIFI_DEVICE;
var IP_ = msg.payload.IP_Address;

node.warn(WIFI_DEVICE);
node.warn(IP_Address);

msg = {payload:time_ + " " + WIFI_DEVICE + " " + IP_};
return msg;

It is early morning and I just got up.
(Poor excuse but....)

(Typically it will be something easy and I just missed it.)

if (msg.topic == "TIMESTAMP")
{
    return msg;
}
var time_ = new Date().toLocaleString();
var WIFI_DEVICE = msg.payload.WIFI_DEVICE;
var IP_ = msg.payload.IP_Address;
msg = {payload:time_ + " " + WIFI_DEVICE + " " + IP_};
return msg;

this code will not process any of those messages since the topics do not match

1 Like

Thanks very much.

That has shown/exposed other problems to me.

Good.

Alas I have to scoot now. Other things. New day. Hopefully I will get it worked out tonight.

You realise that payload is a JSON string right? So accessing msg.payload.IP_Address won't be possible unless you run it through a JSON node or use JSON.parse() first.

1 Like

Yes, I pass it through a JSON node, but it all goes to pot after that - in other ways.

Thanks.

The error message you are trying to track down the cause of is: ReferenceError: IP_Address is not defined (line 3, col 60).

So this means anywhere you have code referencing a variable called IP_Address you need to take a closer look to see why it might not be defined.

In a later post, you've shared the following code block:

if (msg.topic == "TIMESTAMP")
{
    return msg;
}
var time_ = new Date().toLocaleString();
var WIFI_DEVICE = msg.payload.WIFI_DEVICE;
var IP_ = msg.payload.IP_Address;

node.warn(WIFI_DEVICE);
node.warn(IP_Address);

msg = {payload:time_ + " " + WIFI_DEVICE + " " + IP_};
return msg;

In this code you do node.warn(IP_Address); - but no where in this code have you defined IP_Address - so that will be the line of code causing the error message.

A few lines earlier you create a variable called IP_ set to the value of msg.payload.IP_Address. I guess you meant to call that variable IP_Address.

Thanks Nick.

I am closing in on the problem.

This is now what I see/get:

Going into node:

{"topic":"STATUS/WIFIDEVICEID","payload":"2019-6-14 17:29:11 192.168.1.4 >GPS<","qos":0,"retain":false,"_msgid":"cc5d14d.72050e8","WIFI_DEVICE":"GPS","IP_Address":"192.168.1.4","time":"2019-6-14 17:29:11","_event":"node:ca022be0.ef864"}

Node code:


var time_ = new Date().toLocaleString();
var WIFI_DEVICE  = msg.WIFI_DEVICE;
var IP_Address = msg.IP_ADDRESS;

node.warn("*******");
node.warn(WIFI_DEVICE);
node.warn("*******");
node.warn(IP_Address);

msg = {payload:time_ + " " + WIFI_DEVICE + " " + IP_Address};
return msg;

But WIFI_DEVICE is not working.

I'm guessing it is the names tripping over one another.

(Going to try new names but posting to maintain the honesty of what is happening.)

Yeah, ok. Seems the names were a problem.

Now back to the other problem pointed out to me earlier today by Zenofmud.

All:

Thanks.

Found a few more bugs. I really hope that I have learnt my lesson on most (if not all) of them.

What caught me a few times was a missing ELSE as mentioned by Zenofmud.

That is what happens when you bash code into a node way after making the node.

Other silly mistakes which I shall have to accept as part of learning.

All seems to now be working.

Now back to chasing the original problem about erroneous messages from a WiFi device.

Part 2:

Though I hope not related to the original problem, I am (again) getting weird error messages.

I have parts of the flows catching the errors and queuing them for me to see.

I look at the message and see this:

Clearly saying it is WiFi Scanner flow.

Going to said flow I see nothing.
This is a quick picture of the flow. Note the queue is empty.

But then, going back to the first screen, You can see a list of flows and "Telemetry" has a blue light beside it.
That means there is a captured error on that flow.

Going there I see this:

Following that node I get to this:

Well, when I look at it the " is the 23rd letter of line 19, but I won't hold that as a problem.

But what I am not understanding is: Is there a problem?
I've checked the syntax and as best I can see it is ok.

Why is it saying it is in "WiFI Scanner Flow" when the error is in Telemetry?

Are you certain you are looking at the correct function node?

Copy the id from the error and use search (ctrl+f) and double check you're looking at the right node.

It looks like it's coming from a function node named test

Yes I am certain.

That is what I did.

I got the ID (78e95481.ea2e84) searched it and that node flashed.
Ok, I didn't show the screen shot of that, but I opened it up and showed the code.

If you disconnect the node's input and feed it false with an inject node does it give that error? If so then export the node so we can try it. I can only think the quotes are mixed up for some reason, but can't see anything.

Just did it.

Injected false and no error.

I was looking at that. Thinking maybe it's an extended character (copy paste from somewhere?) rather than a regular double quote?

No harm in simply overtyping the quotes and trying again.

1 Like

I suggest (on the top of previous good suggestions) adding a status node connected to a debug node (as below). Configure the status node to monitor only the function node under analysis.

I wonder if you will get an "undefined" displayed in the debug panel.

r-01

What is the Node-RED version in use? You are not using a beta test version, are you?

Andrie,

NR 0.20.3

I added this. Which is slightly more, but I really want to catch this problem.

[{"id":"7cd498e9.1a7cc8","type":"function","z":"c636aa5a.cc34","name":"Time stamp","func":"msg.time = new Date().toLocaleString();\nreturn msg;","outputs":1,"noerr":0,"x":3310,"y":3070,"wires":[["36aedb4c.5d6724"]]},{"id":"36aedb4c.5d6724","type":"simple-queue","z":"c636aa5a.cc34","name":"queue1","firstMessageBypass":false,"bypassInterval":"0","x":3530,"y":3070,"wires":[["8608bdfd.9a35a"]]},{"id":"33d25560.bbef52","type":"inject","z":"c636aa5a.cc34","name":"Next","topic":"","payload":"next","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":3360,"y":3130,"wires":[["e3688214.4b1028"]]},{"id":"e3688214.4b1028","type":"change","z":"c636aa5a.cc34","name":"","rules":[{"t":"set","p":"trigger","pt":"msg","to":"1","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":3530,"y":3130,"wires":[["36aedb4c.5d6724"]]},{"id":"3db36dc9.0fd7b2","type":"inject","z":"c636aa5a.cc34","name":"Wipe","topic":"","payload":"wipe","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":3360,"y":3170,"wires":[["50c8d2ad.be1484"]]},{"id":"50c8d2ad.be1484","type":"change","z":"c636aa5a.cc34","name":"","rules":[{"t":"set","p":"reset","pt":"msg","to":"1","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":3530,"y":3170,"wires":[["36aedb4c.5d6724"]]},{"id":"8608bdfd.9a35a","type":"debug","z":"c636aa5a.cc34","name":"Test node activity","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":3730,"y":3070,"wires":[]},{"id":"4ed206b5.898e4","type":"status","z":"c636aa5a.cc34","name":"","scope":["78e95481.ea2e84"],"x":2850,"y":3020,"wires":[["7cd498e9.1a7cc8"]]}]

ok good, and did you try Steve´s suggestion to rewrite the line inside the function node? The error message indicates that the runtime is evaluating what is on the right side of fill as red instead of "red"