Modbus to MQTT

In this example we write a simple DFS which reads energy data from a modbus-tcp device periodically and publishes to an mqtt broker.

def device_id = 255
def modbus_ip = ''
def mqtt_broker = ''

%% not the default port here
%% we read the values every second

%% we read 3 values 
.function('coils', 'hregs', 'iregs')
%% start addresses
.from(2127, 3008, 104)
%% amount of data for each value
.count(1, 2, 2)
%% we want these resulting fieldnames
.as('ActiveEnergyConsumption', 'MaximalCurrentValue', 'BlindEnergyDelivered') 

%% add some default values to each message

.fields('id', 'vs', 'df')
.field_values('my_id_string', 1, '01.010')

%% publish to mqtt broker