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

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.
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;
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 :)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With