Manually write data to InfluxDB from UI

Hi, Looking for a way to write data to Influx from UI.

  1. Enter value
  2. Choose the date
  3. Click button to write thae data.
    image

Thx for any suggestion.

What part don't you know how to do?
For writing to influx there are influxdb nodes, search the node red flows web site.

I know how to write to influx but i do not know how to join payloads from two nodes : "date picker" & "numeric" into one payload . Date from "Date Picker" should be my timestamp.

Can you use the ui_form with a submit button?

If not then you can use the Join node in Manual mode set to key/value pairs, after 3 message parts and Every Subsequent Message. Feed the two values and the write button into it, making sure they each have different topics. Look at the result in a debug node and you will see all the values in one message. The topic in that message tells you which input just changed, so add a Switch node set to only pass the button topic and you will get what you need each time the button is pressed.

It would be safer to let the button to create a msg.complete message and use than to complete the join. That way you can change the other fields multiple times but only send when complete.

That depends on the requirement, if the values are both to be entered each time then I agree, and this may well be what is required here. On the other hand, if it would be useful if the fields kept their values so that, for example, just the timestamp could be changed and the value left as is, then I think the solution I posted is better. The reason is that msg.complete empties the Join node's memory.

Hi Colin,

I was trying to use ui_form but faced a problem with date.
image

When choose 06.10.2020 i've got an error about expected numeric value.In addition date showed
in debug indow is wrong (-2h).

it there any way to fix it?

How have you configured the form node? Also which node is generating the error? Click on the node I'd above the error and it should highlight the node.

Hi Colin,

Flow looks like below:
ui-form node has 2 fields (water, time). After inputing these two values and clicking submit button it generates payload (date is not correct, -2h offset).
Error is generated by MQTT out node. Was trying different "Time Precision" but nothing was changed.

What timezone are you in?
What timestamp do you want to put in the database? Is it the start of the day in the local timezone or the start of the day UTC or something else?

The reason for the error is that you are passing the influx node a string whereas it needs a timestamp in milliseconds (or whatever you have configured the precision to be). There are numerous ways to convert it, but one of those is to use a function node containing

msg.payload.date = new Date(msg.payload.date).getTime()
return msg;

That creates a javascript Date object by parsing the string and then converts it to its msec equivalent.

Hi Colin,

Thnak you for your suggestion. Now everything works as expected. Adding funkction node with the following code fixed the timestamp problem. All data are stored correctlly in InfluxDB.

data = msg.payload.time;
time = new Date(data).getTime();
msg.payload = {
    "water":  Number(msg.payload.water),
    "time":  time,
}
return msg;

For strictly correct javascript the variables should be properly declared

const data = ...
const time = ...

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