Astarte.Flow.Blocks.ModbusTCPSource (astarte_flow v0.1.0)

An Astarte Flow source that produces data by polling a Modbus device. This block is built to poll a single Modbus slave, if you want to poll multiple slaves you must instantiate multiple flows changing the slave id.

The message contains these fields:

  • key contains the name defined in the configuration
  • data contains the data read from the Modbus device, converted with the format indicated in the configuration.
  • type depends on the format indicated in the configuration.
  • metadata contains the static metadata indicated in the configuration.
  • timestamp contains the timestamp (in microseconds) the message was polled on.

Since polling happens at regular intervals while Flow works in a demand-driven way, this block implements a queue to buffer incoming messages while waiting for consumer demand.

Link to this section Summary

Functions

Starts the ModbusTCPSource.

Link to this section Functions

Link to this function

start_link(opts)

@spec start_link(opts) :: GenServer.on_start()
when opts: [opt],
     opt:
       {:host, String.t()}
       | {:port, integer()}
       | {:slave_id, integer()}
       | {:targets, [map(), ...]}

Starts the ModbusTCPSource.

options

Options

  • host (required): the IP address of the Modbus master this block will connect to.
  • slave_id (required): the slave id that will be polled.
  • targets (required): an array of maps representing the polling targets. See the section below for the structure of the map.
  • port: the TCP port. Defaults to 502, which is the standard Modbus TCP port.

target-map

Target map

Each map in the targets option must have this keys, with string keys:

  • name (required): the name of the measured quantity. This will be used as key in the resulting Flow Message
  • base_address (required): the address where the data starts. Depending on format, one or more registers will be read starting from this address.
  • format (required): one of :int16, :uint16, :float32be, :float32le, :boolean. The be and le suffix in float32 format indicates the endianness, i.e. the order of the two 16 bits halves.
  • modbus_type (required): one of :coil, :discrete_input, :input_register, :holding_register.
  • polling_interval_ms (required): the interval between two polling on this target. Must be
    1. Caveat: currently this block only supports setting the same polling_interval_ms for all targets, this limitation will be removed in a future release.
  • static_metadata: a map containing some static metadata that will be added to the message in the metadata field. It can be used to add information (e.g. units of measurement).