i need some help with Node Red. I´m want to migrate to the newest versions of InfluxDB MQTT Broker Mosquitto and Node RED. Everything went smooth more or less.
The Problem is I cannot get the nodes correctly so the data is written into the influxDB
I don't know how far you have got but are you sure you want to go to influxdb 2? Many think that V2 has problems, Flux in particular, and are waiting for v3.
However, putting that aside, your msg.payload is not valid for sending to the database. Look at the influxdb help text, and the more detailed description and example here for how it should be formatted.
I do not see how the msg.payload that you posted agrees with any of the formats defined in help text.
The fields and tags to write are in msg.payload. If msg.payload is a string, number, or boolean, it will be written as a single value to the specified measurement (called value).
If msg.payload is an object containing multiple properties, the fields will be written to the measurement.
If msg.payload is an array containing two objects, the first object will be written as the set of named fields, the second is the set of named tags.
Finally, if msg.payload is an array of arrays, it will be written as a series of points containing fields and tags.
Given the payload you show, what fields and tags do you expect to be written to the database?
OK, that is because (as the error says) you have previously written a string to that measurement. You will have to delete that measurement from the DB before writing it as a float.
Thank you! I got it working now on a new Bucket.
My question is, as this was a migrated 1.8 DB is there any way to keep it as it has a lot of my old solar panel data?
Is it possible to change the value back to a string? (sorry if this is a dumb question)
Are you sure it Is stored as a string in the original? That is horribly inefficient. There is no change to the influxdb node, so if you sent that payload in the original it would have written it as a number not a string.
If you do want to write it as a string then in a function node you can pu
msg.payload = msg.payload.toString()
return msg
Feed it into a debug node to make sure it is what you want before connecting to the db node, so you don't accidentally write incorrect data.
When writing to the migrated DB I get following error message in NodeRed
HttpError: failure writing points to database: partial write: field type conflict: input field "value" on measurement "tele/Tasmota_Homeserver/Homeserver_Voltage" is type float, already exists as type string dropped=1
When writing to an empty and new bucket no error message and values show in the data explorer
The script to convert the database so it does work again looks like:
from(bucket: "sensors")
|> range(start: 0) // Start from the beginning of the bucket
|> filter(fn: (r) => r._measurement == "tele/Tasmota_Dehumidifier/Dehumidifier_ApparentPower" and r._field == "value") //needs to be done for every Measurement in the Bucket
|> map(fn: (r) => ({
_time: r._time,
_measurement: r._measurement,
_field: r._field,
_value: float(v: r._value), // Convert the value from string to float
_tags: r._tags
}))
|> to(bucket: "sensorsDB", org: "Homelab") //This is the new Bucket which needs to be created
I hope this helps someone in case they have the same issue