I've set up a Raspberry Pi to ultimately log data from my solar inverter for display in Grafana. I figured it would be a good exercise to get familiar Node-Red and influxdb by starting with my Ambient Weather PWS API.
Being a complete newb at all of this, I've managed over the last couple of days to successfully pull in the msg.payload from the API via an http request node and can see the data I want to inject into influxdb. The part that I can't wrap my head around is the function parsing between the request and the influxdb batch node. Here's what I have thus far, but it throws a "TypeError: Cannot read property '0' of undefined". I expect I need to define "object 0", but I'm not sure where to do that.
Or... I may well be on the entirely wrong track. Any pointers would be much appreciated.
Refer to the message object in function nodes as msg, so payload can be used as msg.payload.
Unless you use asynchronous function in your function node, or need to return multiple times, just returning a message object at the end is enough. Your approach of {payload} is good in basis, but you can just edit the existing msg.payload object and then return msg.
Just wondered why you are using the Batch Output format, when you are not processing batch data.
Wouldn't it be easier to add the 'measurement' setting in the influxdb node itself, and structure your function node as per the influxdb node readme. For example;
Notice that square brackets are used to create an array that is fed into the influxdb node. (You seem to be using parentheses)
PS - Its always helpful if you paste the actual function node code instead of using a screenshot, as it enables others to copy, paste & edit it, instead of having to type it out in full.
Thanks very much to you both for your quick responses.
@afelix - your doc links were very helpful. I'm getting new errors, but I think I know why now.
@Paul-Reed - I was thinking I needed a batch because of the nested arrays, but I changed to a regular influx out instead. I was working from that readme but getting confused because the examples were inserting values rather than parsing them from a JSON stream. I found another example in the forum that sent me in the wrong direction.
I think I'm close. Thanks to you both. Will update.
Thanks again. Data is going to influxdb now! I'm adding other fields now that I'm starting to get it.
Since my flow includes personal info (address, lat/lon etc,), would the best method for obfuscating when posting a flow here or elsewhere be to just edit the API request and then post the flow?