Node-red-contrib-influxdb : influxdb batch : not sure about processing an array of data

I have seen some discussions regarding using the batch node for influxdb but have not got my head around it yet.

I have an array of data in msg.payload that I want to use the batch node to write an entry to a table but replacing the time value with a value in one of the array fields:

A short array of my data is below:

[{"time":"2023-01-20T00:20:03.271Z","domain":"sensor","elec_cons":7.138,"elec_cost_pounds":2.85,"elec_standing_charge_pence":49.54,"elec_tariff_pence":33.029,"entity_id":"utilities","friendly_name_str":"Utilities","gas_cons":28.756069,"gas_cost_pounds":3.23,"gas_standing_charge_pence":28.48,"gas_tariff_pence":10.244,"readings_date":20230119,"readings_date_str":"2023-01-19","value":6.08},
{"time":"2023-01-23T00:20:02.849Z","domain":"sensor","elec_cons":7.041,"elec_cost_pounds":2.82,"elec_standing_charge_pence":49.54,"elec_tariff_pence":33.029,"entity_id":"utilities","friendly_name_str":"Utilities","gas_cons":33.678944,"gas_cost_pounds":3.73,"gas_standing_charge_pence":28.48,"gas_tariff_pence":10.244,"readings_date":20230122,"readings_date_str":"2023-01-22","value":6.55},
{"time":"2023-01-24T00:20:02.673Z","domain":"sensor","elec_cons":7.419,"elec_cost_pounds":2.94,"elec_standing_charge_pence":49.54,"elec_tariff_pence":33.029,"entity_id":"utilities","friendly_name_str":"Utilities","gas_cons":21.903017,"gas_cost_pounds":2.53,"gas_standing_charge_pence":28.48,"gas_tariff_pence":10.244,"readings_date":20230123,"readings_date_str":"2023-01-23","value":5.47}
]

There can be a variable number of array entries.

for each of these, I would like to write a new influxdb sensor entry with the following fields:

time: this set to "readings_date_str" value, I guess at 00:00:00 time on that day
elec_cons: same as array input
elec_cost_pounds: same as array input
elec_standing_charge_pence: same as array input
elec_tariff_pence: same as array input
gas_cons: same as array input
gas_cost_pounds: same as array input
gas_standing_charge_pence: same as array input
gas_tariff_pence: same as array input
total_cost: set to "value"

I don't know how an array can be read and each processed by the batch node (although I assume this is built as a payload in a function node?) plus I am also unsure about measurement and tag fields. What do these really mean? Are the expected values in some standard list of values?

There are mentions of iterating through arrays in discussions but not many good examples of how that is actually coded.

That is not really a node-red issue, it is an influxdb issue, but basically anything that is a process measurement should be a field, and anything that is a identifier of some sort, such as meter id, batch number, operator name and so on should be a tag. Tags are automatically indexed so that you can efficiently search by, for example, meter_id in a query. Possible, therefore, domain, entity_id and friendly_name_str should be tags, if you need to record them that is.

As to formatting the data for the batch node, is all the data in the array to go in the same influxdb measurement? If so then it may be easier to use the normal influxdb out node, which can be given a set of data in an array as described in the help text. If you look at the node's page on the node-red flows site the last example in the section on the influxdb out node shows exactly that.

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.