gus
December 21, 2023, 3:14pm
1
Hi all
I’m simply trying to update a device property via NodeRED, but i’m struggling to find the right format.
My device property:
My NodeRED flow:
The code in the function:
var updatedflow = {};
updatedflow.url="https://myserver.aws.thinger.io/v3/users/"+user+"/devices/"+device+"/properties/prevInstWaterFlow";
updatedflow.headers={};
updatedflow.headers["Authorization"] = "Bearer "+token;
updatedflow.headers["content-type"] = "application/json";
updatedflow.content={
prevInstWaterFlow:0
}
return updatedflow;
The http component:
I keep getting the errors “invalid JSON content provided”. I tried already all combinations that i could think of, but it doesn’t work.
Instead of .content, i tried already .payload, .message, .body…
Any idea what i’m doing wrong?
Thanks!
Gus
jaimebs
December 21, 2023, 4:10pm
2
Hi @gus
Is there any reason why you are not using the property write node?
I believe this will make it easier as the node handles the underlying communication and authorization with thinger
gus
December 21, 2023, 4:18pm
3
Hi
I tried this indeed, but i couldn’t figure out how to have a variable in the value field? Because this is a changing value in every event. Is it possible to make it variable?
jaimebs
December 21, 2023, 5:00pm
4
You can pass the value field from the input msg, just as you where doing with the http request node, in the field msg.payload or msg.value. Example:
msg.value = 0;
return msg;
Try it out with a simple inject flow with an inject node
Translate it then to a function node and you would be able to use a variable.
Just note that at the moment there is a bug when using msg.payload instead of msg.value and where the value is 0, so it is not possible to pass it as:
msg.payload = 0;
return msg;
Will have it fixed for the next version of the plugin.
gus
December 21, 2023, 5:23pm
5
Okay that seems to fix it.
First i build a function like this:
And then i give it to the write property component:
Thanks!
Gus