Hello to all of you,
i post this because i am stuck at a point where hours of research didnt help to get any further.
I pull data with telegraf modbus input from my smart energy meter all data that goes straight out to an influxdb is usable and all is fine with that.
But there are two sets of 4 int16 values, that needs to be calculatet like that:
Active energy+ [Wh] = ({register 512} · 2^48 + {register 513} · 2^32 + {register 514} · 2^16 + {register
515}) · 0.1 [Wh]
After some research i think [processor.strarlark] is the one that can do the job. So i followed some examples and tried some time for my own, but all i get is an error starting telegraf:
2021-05-14T12:50:37Z I! Loaded inputs: modbus
2021-05-14T12:50:37Z I! Loaded aggregators:
2021-05-14T12:50:37Z I! Loaded processors: starlark
2021-05-14T12:50:37Z I! Loaded outputs: influxdb
2021-05-14T12:50:37Z I! Tags enabled: host=MultiP
2021-05-14T12:50:37Z I! [agent] Config: Interval:5m0s, Quiet:false, Hostname:“MultiP”, Flush Interval:5m0s
2021-05-14T12:50:37Z E! [telegraf] Error running agent: could not initialize processor starlark: processor.starlark:11:2: got indent, want primary expression
I absolutly have ne clue what the Problem is here. If something is missing or are there language errors,
Or is this totaly the wrong way to handle the needed calculation ? I just want to get only the two calculatet values into the DB not the 8 raw values.
This is my conf:
[[inputs.modbus]]
TCP
controller=“tcp://192.168.2.19:502”
name = “KSEM”
slave_id = 1
timeout = 5
interval = “5m”
flush_interval = “5m”
holding_registers = [
{ name = “Active energy_pos1”, byte_order =“AB”, data_type = “UINT16”, scale=1.0, address = [512]},
{ name = “Active energy_pos2”, byte_order =“AB”, data_type = “UINT16”, scale=1.0, address = [513]},
{ name = “Active energy_pos3”, byte_order =“AB”, data_type = “UINT16”, scale=1.0, address = [514]},
{ name = “Active energy_pos4”, byte_order =“AB”, data_type = “UINT16”, scale=1.0, address = [515]},
{ name = “Active energy_neg1”, byte_order =“AB”, data_type = “UINT16”, scale=1.0, address = [516]},
{ name = “Active energy_neg2”, byte_order =“AB”, data_type = “UINT16”, scale=1.0, address = [517]},
{ name = “Active energy_neg3”, byte_order =“AB”, data_type = “UINT16”, scale=1.0, address = [518]},
{ name = “Active energy_neg4”, byte_order =“AB”, data_type = “UINT16”, scale=1.0, address = [519]},
][[processors.starlark]]
source = ‘’’
def apply(metric):
#Register 512-515 into var
pos1 = int(metric.fields[‘Active energy_pos1’])
pos2 = int(metric.fields[‘Active energy_pos2’])
pos3 = int(metric.fields[‘Active energy_pos3’])
pos4 = int(metric.fields[‘Active energy_pos4’])calc new field
metric.fields[‘Netz_Bezug’] = ((pos1 * 281474976710656) + (pos2 * 4.294.967.296) + (pos3 * 65536) + pos4) / 10000
#Register 516-519 into var
neg1 = int(metric.fields[‘Active energy_neg1’])
neg2 = int(metric.fields[‘Active energy_neg2’])
neg3 = int(metric.fields[‘Active energy_neg3’])
neg4 = int(metric.fields[‘Active energy_neg4’])calc new field
metric.fields[‘Netz_Einspeisung’] = ((neg1 * 281474976710656) + (neg2 * 4.294.967.296) + (neg3 * 65536) + neg4) / 10000
return metric
‘’’
I would be grateful if someone could take a look into it.
Kind regards
Dennis