Kategorien
Allgemein

Telegraf einrichten

Heute zeig ich euch, wie ihr Telegraf einrichtet, um die Daten vom Wechselrichter abzufragen und in die Datenbank eingetragen werden.

Mit folgendem Befehl laden wir uns Telegraf herunter und installieren es direkt im Anschluss.

wget https://dl.influxdata.com/telegraf/releases/telegraf_1.15.3-1_amd64.deb
sudo dpkg -i telegraf_1.15.3-1_amd64.deb

Nachdem Telegraf installiert ist, kommen wir zur Konfiguration. Diese befindet sich in /etc/telegraf/telegraf.conf

Hier definieren wir im Abschnitt [[outputs.influxdb]] wo unsere gesammelten Daten vom Wechselrichter gespeichert werden sollen.

[[outputs.influxdb]]
  ## The full HTTP or UDP URL for your InfluxDB instance.
  ##
  ## Multiple URLs can be specified for a single cluster, only ONE of the
  ## urls will be written to each interval.
  # urls = ["unix:///var/run/influxdb.sock"]
  # urls = ["udp://127.0.0.1:8089"]
  urls = ["http://localhost:8086"]

  ## The target database for metrics; will be created as needed.
  ## For UDP url endpoint database needs to be configured on server side.
  database = "inverters"

  ## HTTP Basic Auth
  username = "telegraf"
  password = "<password>"

Zeilen die mit einer Raute (#) anfangen sind Kommentare und werden ignoriert. Ich habe den Abschnitt auch auf das wesentliche gekürzt. Die Daten sind die gleichen, die wir beim Einrichten von InfluxDB definiert haben (https://josefliedl.de/influxdb-auf-raspberry-installieren/).

Jetzt kommen wir zu dem Teil, wo wir die Daten vom Wechselrichter abfragen. Telegraf liest nicht nur die Konfigurationsdatei von oben, sondern auch alle Dateien die im Unterordner „/etc/telegraf/telegraf.d“. Hier legen wir eine neue Datei modbus.config an:

# Retrieve data from MODBUS slave devices
[[inputs.modbus]]
 ## Connection Configuration
 ##
 ## The plugin supports connections to PLCs via MODBUS/TCP or
 ## via serial line communication in binary (RTU) or readable (ASCII) encoding
 ##
 ## Device name
 name = "Huawei 33KTL-A"
 name_override = "huawei33ktla"

 ## Slave ID - addresses a MODBUS device on the bus
 ## Range: 0 - 255 [0 = broadcast; 248 - 255 = reserved]
 slave_id = 2

 ## Timeout for each request
 timeout = "1s"
#
#  # TCP - connect via Modbus/TCP
#  controller = "tcp://localhost:502"
#
 # Serial (RS485; RS232)
 controller = "file:///dev/serial0"
 baud_rate = 9600
 data_bits = 8
 parity = "N"
 stop_bits = 1
 transmission_mode = "RTU"


#  ## Measurements
#  ##
#
#  ## Digital Variables, Discrete Inputs and Coils
#  ## name    - the variable name
#  ## address - variable address
#
#  discrete_inputs = [
#    { name = "start",          address = [0]},
#    { name = "stop",           address = [1]},
#    { name = "reset",          address = [2]},
#    { name = "emergency_stop",  address = [3]},
#  ]
#  coils = [
#    { name = "motor1_run",     address = [0]},
#    { name = "motor1_jog",     address = [1]},
#    { name = "motor1_stop",    address = [2]},
#  ]
#
#  ## Analog Variables, Input Registers and Holding Registers
#  ## name       - the variable name
#  ## byte_order - the ordering of bytes
#  ##  |---AB, ABCD   - Big Endian
#  ##  |---BA, DCBA   - Little Endian
#  ##  |---BADC       - Mid-Big Endian
#  ##  |---CDAB       - Mid-Little Endian
#  ## data_type  - UINT16, INT16, INT32, UINT32, FLOAT32, FLOAT32-IEEE (the IEEE 754 binary representation)
#  ## scale      - the final numeric variable representation
#  ## address    - variable address
#
# input_registers = [
 holding_registers = [
   { name = "pv1voltage",   byte_order = "AB",   data_type = "INT16",   scale=1.0,     address = [32262]},
   { name = "pv1current",   byte_order = "AB",   data_type = "INT16",   scale=1.0,     address = [32263]},
   { name = "pv2voltage",   byte_order = "AB",   data_type = "INT16",   scale=1.0,     address = [32264]},
   { name = "pv2current",   byte_order = "AB",   data_type = "INT16",   scale=1.0,     address = [32265]},
   { name = "pv3voltage",   byte_order = "AB",   data_type = "INT16",   scale=1.0,     address = [32266]},
   { name = "pv3current",   byte_order = "AB",   data_type = "INT16",   scale=1.0,     address = [32267]},
   { name = "pv4voltage",   byte_order = "AB",   data_type = "INT16",   scale=1.0,     address = [32268]},
   { name = "pv4current",   byte_order = "AB",   data_type = "INT16",   scale=1.0,     address = [32269]},
   { name = "pv5voltage",   byte_order = "AB",   data_type = "INT16",   scale=1.0,     address = [32270]},
   { name = "pv5current",   byte_order = "AB",   data_type = "INT16",   scale=1.0,     address = [32271]},
   { name = "pv6voltage",   byte_order = "AB",   data_type = "INT16",   scale=1.0,     address = [32272]},
   { name = "pv6current",   byte_order = "AB",   data_type = "INT16",   scale=1.0,     address = [32273]},
   { name = "pv7voltage",   byte_order = "AB",   data_type = "INT16",   scale=1.0,     address = [32314]},
   { name = "pv7current",   byte_order = "AB",   data_type = "INT16",   scale=1.0,     address = [32315]},
   { name = "pv8voltage",   byte_order = "AB",   data_type = "INT16",   scale=1.0,     address = [32316]},
   { name = "pv8current",   byte_order = "AB",   data_type = "INT16",   scale=1.0,     address = [32317]},
   { name = "uab",   byte_order = "AB",   data_type = "UINT16",   scale=1.0,     address = [32274]},
   { name = "ubc",   byte_order = "AB",   data_type = "UINT16",   scale=1.0,     address = [32275]},
   { name = "uca",   byte_order = "AB",   data_type = "UINT16",   scale=1.0,     address = [32276]},
   { name = "ua",   byte_order = "AB",   data_type = "UINT16",   scale=1.0,     address = [32277]},
   { name = "ub",   byte_order = "AB",   data_type = "UINT16",   scale=1.0,     address = [32278]},
   { name = "uc",   byte_order = "AB",   data_type = "UINT16",   scale=1.0,     address = [32279]},
   { name = "ia",   byte_order = "AB",   data_type = "UINT16",   scale=1.0,     address = [32280]},
   { name = "ib",   byte_order = "AB",   data_type = "UINT16",   scale=1.0,     address = [32281]},
   { name = "ic",   byte_order = "AB",   data_type = "UINT16",   scale=1.0,     address = [32282]},
   { name = "frequency",   byte_order = "AB",   data_type = "UINT16",   scale=1.0,     address = [32283]},
   { name = "power_factor",   byte_order = "AB",   data_type = "INT16",   scale=1.0,     address = [32284]},
   { name = "efficiency",   byte_order = "AB",   data_type = "UINT16",   scale=1.0,     address = [32285]},
   { name = "temperature",   byte_order = "AB",   data_type = "INT16",   scale=1.0,     address = [32286]},
   { name = "status",   byte_order = "AB",   data_type = "UINT16",   scale=1.0,     address = [32287]},
   { name = "power_peak_day",   byte_order = "ABCD",   data_type = "INT32",   scale=1.0,     address = [32288,32289]},
   { name = "power",   byte_order = "ABCD",   data_type = "INT32",   scale=1.0,     address = [32290,32291]},
   { name = "power_reactive",   byte_order = "ABCD",   data_type = "INT32",   scale=1.0,     address = [32292,32293]},
   { name = "power_total",   byte_order = "ABCD",   data_type = "UINT32",   scale=1.0,     address = [32294,32295]},
   { name = "e_hour",   byte_order = "ABCD",   data_type = "UINT32",   scale=1.0,     address = [32298,32299]},
   { name = "e_day",   byte_order = "ABCD",   data_type = "UINT32",   scale=1.0,     address = [32300,32301]},
   { name = "e_month",   byte_order = "ABCD",   data_type = "UINT32",   scale=1.0,     address = [32302,32303]},
   { name = "e_year",   byte_order = "ABCD",   data_type = "UINT32",   scale=1.0,     address = [32304,32305]},
   { name = "e_total",   byte_order = "ABCD",   data_type = "UINT32",   scale=1.0,     address = [32306,32307]},
   { name = "locking",   byte_order = "AB",   data_type = "UINT16",   scale=1.0,     address = [32320]},
   { name = "protection_status",   byte_order = "AB",   data_type = "UINT16",   scale=1.0,     address = [32321]},
   { name = "inverter_on_grid",   byte_order = "AB",   data_type = "UINT16",   scale=1.0,     address = [32322]},
   { name = "insulation_resistance",   byte_order = "AB",   data_type = "UINT16",   scale=1.0,     address = [32323]},
   { name = "power_total_mppt1",   byte_order = "ABCD",   data_type = "UINT32",   scale=1.0,     address = [33022, 33023]},
   { name = "power_total_mppt2",   byte_order = "ABCD",   data_type = "UINT32",   scale=1.0,     address = [33024, 33025]},
   { name = "power_total_mppt3",   byte_order = "ABCD",   data_type = "UINT32",   scale=1.0,     address = [33026, 33027]},
   { name = "power_total_mppt4",   byte_order = "ABCD",   data_type = "UINT32",   scale=1.0,     address = [33070, 33071]},

 ]

Hier müsst ihr evtl. noch den Parameter controller anpassen. Dies ist die serielle Schnittstelle, wo euer Huawei angeschlossen ist.

Nach einem Neustart von Telegraf, sollten nun die Daten in eure InfluxDB-Datenbank geschrieben werden.

Falls es bei euch nicht klappt oder ihr noch Fragen habt, könnt ihr diese gern in die Kommentare schreiben.

Schreibe einen Kommentar

Deine E-Mail-Adresse wird nicht veröffentlicht. Erforderliche Felder sind mit * markiert.

Diese Website verwendet Akismet, um Spam zu reduzieren. Erfahre mehr darüber, wie deine Kommentardaten verarbeitet werden.