Autor Thema: Need help modbus specific  (Gelesen 1584 mal)

Offline smarthacker

  • New Member
  • *
  • Beiträge: 19
Need help modbus specific
« am: 31 Januar 2019, 17:21:54 »
Moved the post from here,96588.0.html

Hi All,

I am building writing a custom module to read values from 2 different devices both device communicate over Modbus TCP.

But the problem is both devices have different IP and port I need to write them into one module since I need to achieve PID regulation between these two devices. I need to set values based on the value of the first device.
Here are my conf and module code.

My question is for the first device I want to read only "h40499"  and for the second device only "h1000" and "h1001".

But with the current config, I am getting the temperature, power and power meter values for both devices. I want to separate them.
Once I call the ModbusLD_Initialize it just takes the control to parent module.

can someone please help me with this.

I am following the guidelines from the following link

Additional info :-

I have one power device that gives me the realtime power consumption .
Other device has tempreture and power but based on other devices tempreture value I need to set values for 1st device.
I am not sure how to do it using conf itself and how to fetch current values in conf.
additional how to include the sub routine in conf itself. Hence decided to write everyting in module.
can some one help me with it

defmod powermeter ACT 1 1 TCP
define serial dummy
set serial 1438503

def powermeter1 ACT 1 1 TCP

package  main ;
use strict ;
use warnings ;
use Data::Dumper;

my %parseInfo = (
    "h40499"  =>  {
        reading => "powermeter",
        poll => 1,
        unpack => 'N',
        len => 2,
        expr => 'int($val - Value(\'serial\')'
    "h1000"  =>  {
        reading => "power",
        poll => 1,
    "h1001"  =>  {
        reading => "tempreture",
        poll => 1,
        expr => '$val/10',
        format => '%.1f'

sub ACT_Initialize ($)  {
    my ($modHash) = @_;

    LoadModule "Modbus";
    require "$attr{global}{modpath}/FHEM/";

    $modHash->{parseInfo}  = \%parseInfo;


sub ACT_Define ($$) {
    my  ( $hash,$def)  =  @_ ;
    print Dumper @_;


Offline strategy

  • Jr. Member
  • **
  • Beiträge: 92
Antw:Need help modbus specific
« Antwort #1 am: 29 Mai 2019, 09:56:45 »
Hey smarthacker,

to be honest I'm not an expert in Modbus and especially not in Modbus TCP.
But I do have an environment using Modbus RS485. I do have a single dongle attached to my FHEM system but two clients attached to the bus.
I'm using the module Modbus combined with two instances of the module ModbusAttr. Where Modbus handles the communication via my RS485 dongle and each ModbusAttr instance communicates with one of the attached devices.

Looking into the wiki ( Modbus TCP doesn't require the modbus module. Instead you can define 2 instances of the  ModbusAttr and assign the matching IP-addresses.

When you say you want to combine the data I would suggest to use custom logic in and a dummy.
This seems to be more supportable than building a custom module just for your specific use case.