Input data to Influxdb

Hi All
I have created a flow to pull data from a solar charge controller and send to MQTT then a String node to select the 'voltage' data from the string. I would like to input this data to Influxdb but im stuck on the code needed in the Function node to change the data into the right format for Influxdb.

Via a debug node the output from my String node is

Mppt/Sunsaver : msg.payload : string[5]

"24.89"

With the Function node how do I input this to Influxdb.

Thanks in advance

Hi,
have you already installed this node?

There is also a good example described.

Hi,
Yes i have, its the coding that i cant work out,
to turn my 'msg.payload: string[5] "24.89" ' into a field and value in influxdb.

In a function node before the influx node, try something like this:

msg.payload={"the name of your field" : your value };
return msg;

This is how I do it when receiving and posting to influx multiple values:

var t=msg.payload;
if(t!=="")
{
k=t.split(':');
for (i = 0; i < k.length; i++)
{
    k[i]=parseInt(k[i]);
}
msg.topic="Analogues";
	if(k[0]&&k[1]&&k[2]&&k[3]&&k[4]&&k[5]&&k[6]&&k[7]&&k[8]&&k[9]&&k[10]&&k[11]&&k[12]&&k[13]&&k[14]&&k[15])
		{
		msg.payload={"AP0":k[0],"AP1":k[1],"AP2":k[2],"AP3":k[3],"BP0":k[4],"BP1":k[5],"BP2":k[6],"BP3":k[7],"CP0":k[8],"CP1":k[9],"CP2":k[10],"CP3":k[11],"DP0":k[12],"DP1":k[13],"DP2":k[14],"DP3":k[15]};
		return msg;

    }
}

What did you have before the string node?

the node before is a MQTT in.

thank you, but would i have to manually write the value each time i want to input?

I meant what does the data look like before the string node, it may be there is a better way.

Ah ok,, , its a string

msg.payload : string[6328]

`

Show us the start of the string, we need to see the structure.

heres an example

> Morningstar SunSaver MPPT Charge Controller Settings
> 
> Choose mode...
> 1. Read
> 2. Write
> 3. Logs
> 4. Write Coils
> 5. Live Reload
> Mode: 
> Attempting to connect to /dev/ttyUSB0
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> Adc_vb_f = 25.01 V (1sec avg)
> Adc_va_f = 30.96 V (1sec avg)
> Adc_vl_f = 24.91 V (1sec avg)
> Adc_ic_f = 0.57 A (1sec avg)
> Adc_il_f = 1.19 A (1sec avg)
> T_hs = 15 °C
> T_batt = 11 °C
> Power_out = 14.15 W
> Vb_min_daily (resets after dark) = 24.15 V
> Vb_max_daily (resets after dark) = 25.36 V
> Ahc_daily (resets after dark) = 0.60 Ah
> Ahl_daily (resets after dark) = 5.10 Ah
> charge_state = 5 (0=start,1=night_check,2=disconnect,3=night,4=fault,5=bulk_charge,6=absorption,7=float,8=equalize)
> Vb_f = 25.05 V (25sec avg)
> Vb_ref = 24.22 V
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> Adc_vb_f = 25.01 V (1sec avg)
> Adc_va_f = 30.97 V (1sec avg)
> Adc_vl_f = 24.90 V (1sec avg)
> Adc_ic_f = 0.57 A (1sec avg)
> Adc_il_f = 1.17 A (1sec avg)
> T_hs = 15 °C
> T_batt = 11 °C
> Power_out = 14.18 W
> Vb_min_daily...

its the Adc_vb_f = that i want to monitor.

It is not clear how you get the values into red-node environment.
Can you post your flow?

You are not making this easy. Feed the mqtt node into a debug node and show us what you get.

Sorry for my confusion, the example above is what i get from a debug node connected to the mqtt in.

this is the 'value copied' from the debug node

Morningstar SunSaver MPPT Charge Controller Settings

Choose mode...

  1. Read
  2. Write
  3. Logs
  4. Write Coils
  5. Live Reload
    Mode:
    Attempting to connect to /dev/ttyUSB0

Adc_vb_f = 25.60 V (1sec avg)
Adc_va_f = 33.89 V (1sec avg)
Adc_vl_f = 25.51 V (1sec avg)
Adc_ic_f = 1.41 A (1sec avg)
Adc_il_f = 1.13 A (1sec avg)
T_hs = 19 °C
T_batt = 11 °C

Adc_vb_f = 25.60 V (1sec avg)
Adc_va_f = 33.89 V (1sec avg)
Adc_vl_f = 25.50 V (1sec avg)
Adc_ic_f = 1.41 A (1sec avg)
Adc_il_f = 1.14 A (1sec avg)
T_hs = 19 °C
T_batt = 11 °C

Adc_vb_f = 25.60 V (1sec avg)
Adc_va_f = 33.89 V (1sec avg)
Adc_vl_f = 25.51 V (1sec avg)
Adc_ic_f = 1.41 A (1sec avg)
Adc_il_f = 1.10 A (1sec avg)
T_hs = 19 °C
T_batt = 11 °C
Power_out = 36.04 W
Vb_min_daily (resets after dark) = 24.15 V
Vb_max_daily (resets after dark) = 26.24 V
Ahc_daily (resets after dark) = 2.10 Ah
Ahl_da...

OK, in that case you will have to extract it using string manipulation, as you are doing. To convert the msg.payload string to a number all you need is a function node containing
msg.payload = Number(msg.payload)
return msg

Thank you, I now have a number,
Can i send this straight to the influxdb out node?

If you want it be in a field called value in the Measurement that you configure in the Influx Out node then yes. The help text for the node describes the payload formats supported.

Your string is 6328 characters and we only have 535 of those to look at, but it's clear that you have multiple lines containing

Adc_vb_f = nn.nn V

I think that your String node to extract the value will only return the first matching line.
Is that OK or do you need all matches?

No its not a problem, the code that pulls the data from the Modbus unit every 5 seconds for 30 seconds, It maybe a bit messy but is accurate enough for what i want.