Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TypeError: Cannot assign to read only property '_msgid'

Tags:

node-red

I'm trying my hand on node-red...

enter image description here

I do this web query https://api.forecast.io/forecast/

This is the given output:

{"latitude":-25.74486,"longitude":28.18783,"timezone":"Africa/Johannesburg","offset":2,"currently":
{"time":1462871342,"summary":"Foggy","icon":"fog","precipIntensity":0,"precipProbability":0,
"temperature":18.08,"apparentTemperature":18.08,
"dewPoint":9.3,"humidity":0.57,"windSpeed":3.75,"windBearing":351,"visibility":2.78,
"cloudCover":0.23,"pressure":1024.87,"ozone":252.43}}

which seems correct.

The code in Parse Weather is

  //parse forecast.io message

 var weather = JSON.parse(msg.payload);

 return weather.currently.temperature;

The error I get is:

TypeError: Cannot assign to read only property '_msgid' of 19.49

The value seems ok.

What am I doing wrong?

Thanks in advance.

like image 526
Nico vd Dussen Avatar asked Aug 02 '26 22:08

Nico vd Dussen


2 Answers

The problem is in your Parse Weather function. You are returning a int (18.08), Function nodes need to return a msg object.

Try something like this:

var weather = JSON.parse(msg.payload);
msg.payload = weather.currently.temperature;

return msg;
like image 141
hardillb Avatar answered Aug 04 '26 16:08

hardillb


Found the dummy error.

Changed the function code to:

//parse forecast.io message

 var weather = JSON.parse(msg.payload);
 msg.payload = weather.currently.temperature;
 return msg;

All working now as expected :)

like image 32
Nico vd Dussen Avatar answered Aug 04 '26 16:08

Nico vd Dussen



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!