2019-12-22 15:39:16 +00:00
|
|
|
#!/usr/bin/perl
|
2022-01-03 11:20:18 +00:00
|
|
|
#
|
|
|
|
package main;
|
|
|
|
|
2019-12-22 15:39:16 +00:00
|
|
|
use strict;
|
|
|
|
use warnings;
|
|
|
|
|
2022-01-03 11:20:18 +00:00
|
|
|
use Path::Tiny;
|
|
|
|
use IO::Socket::INET;
|
|
|
|
|
2022-02-01 16:06:07 +00:00
|
|
|
BEGIN {
|
|
|
|
push @INC, "./lib";
|
|
|
|
}
|
2022-01-03 11:20:18 +00:00
|
|
|
|
2022-02-01 16:06:07 +00:00
|
|
|
use iec1107;
|
2022-01-03 11:20:18 +00:00
|
|
|
|
|
|
|
my $port = Device::SerialPort->new(
|
|
|
|
"/dev/serial/by-id/usb-FTDI_FT232R_USB_UART_AK072UA9-if00-port0")
|
|
|
|
or die "$! \n";
|
2020-01-09 13:17:46 +00:00
|
|
|
|
2019-12-22 15:39:16 +00:00
|
|
|
$port->baudrate(9600);
|
|
|
|
$port->databits(7);
|
|
|
|
$port->parity("even");
|
|
|
|
$port->stopbits(1);
|
|
|
|
$port->handshake("none");
|
|
|
|
$port->write_settings;
|
2022-01-03 11:20:18 +00:00
|
|
|
|
2019-12-22 15:39:16 +00:00
|
|
|
$port->purge_all();
|
2020-01-10 16:42:09 +00:00
|
|
|
$port->read_char_time(0);
|
2022-01-03 11:20:18 +00:00
|
|
|
$port->read_const_time(150); #was 100ms previously, this lead to race conditions
|
|
|
|
|
|
|
|
my $dir = path("$workdir/sensors"); # Config Directory there find the id-file
|
|
|
|
|
|
|
|
my $file = $dir->child("id.list");
|
|
|
|
|
|
|
|
# Read in the entire contents of a file
|
|
|
|
my $content = $file->slurp();
|
|
|
|
|
|
|
|
# openr() returns an IO::File object to read from
|
|
|
|
my $file_handle = $file->openr();
|
|
|
|
|
2019-12-22 15:39:16 +00:00
|
|
|
# It is possible to find out the device id of a single device on RS-485 9600@7E1 by sending "/?!\r\n"
|
2020-01-10 16:42:09 +00:00
|
|
|
# It does not work with more than one device on the same bus, it results in garbage!
|
2022-01-03 11:20:18 +00:00
|
|
|
my $passwd = "00000000"; # Standard password 0 over 8-digits
|
2020-01-07 21:29:35 +00:00
|
|
|
|
2022-01-03 11:20:18 +00:00
|
|
|
my $fhemDummy = 'Meter_';
|
2020-01-07 21:29:35 +00:00
|
|
|
|
2022-01-03 11:20:18 +00:00
|
|
|
my $HOSTNAME = "localhost";
|
|
|
|
my $HOSTPORT = "7072";
|
|
|
|
my $socket = IO::Socket::INET->new(
|
|
|
|
'PeerAddr' => $HOSTNAME,
|
|
|
|
'PeerPort' => $HOSTPORT,
|
|
|
|
'Proto' => 'tcp'
|
|
|
|
) or die "Cant\'t connect to FHEM Instance \n";
|
2020-01-07 21:29:35 +00:00
|
|
|
|
2022-01-03 11:20:18 +00:00
|
|
|
while ( my $id = $file_handle->getline() ) {
|
|
|
|
chomp $id;
|
|
|
|
my $drs110m =
|
|
|
|
iec1107->new( "port" => $port, "id" => $id, "passwd" => $passwd );
|
2020-01-10 16:42:09 +00:00
|
|
|
|
2022-01-03 11:20:18 +00:00
|
|
|
$drs110m->set_clock();
|
2020-01-10 16:42:09 +00:00
|
|
|
|
2022-01-03 11:20:18 +00:00
|
|
|
my $values = $drs110m->get_values();
|
2021-12-28 11:24:02 +00:00
|
|
|
|
2022-01-03 11:20:18 +00:00
|
|
|
next if ( ref($values) ne 'HASH' );
|
2020-01-10 08:33:12 +00:00
|
|
|
|
2022-01-03 11:20:18 +00:00
|
|
|
while ( my ( $reg, $val ) = each( %{$values} ) ) {
|
|
|
|
$socket->print(
|
|
|
|
'setreading ' . $fhemDummy . $id . ' ' . $reg . ' ' . $val . "\n" );
|
|
|
|
}
|
2020-01-07 21:29:35 +00:00
|
|
|
}
|
|
|
|
|
2022-01-03 11:20:18 +00:00
|
|
|
$socket->close;
|
2022-01-18 18:13:00 +00:00
|
|
|
|
|
|
|
exit;
|