[vz-users] [vz-dev] iskra mt171

Henry van Gestel henry.van.gestel at gmail.com
Tue Jan 8 14:40:09 CET 2013


Thanks for your reply.


I attached the perlscript which fuctions for my MT171 iskra meters.( 
borrowed from http://knx-user-forum.de/225383-post148.html)
read_char_time was the key for me.
These meters (i have 2) will be replaced this month by probably 2 * 
Iskra Mt382, reason decimals , mt171 gives only integers and provider 
will or can not change that.

I will try the alternatives you gave me and let you know.

Questions:
1)
Do you know what the datamodel is (name of fields and format) , what 
schould I sent : timestamp, used KW, produced kw, PV generated KW?
my output from the script before filtering is:
-------------------------------------------------------------
Values for ttyUSB1
  0-0:C.1.0*255(47231330)
1-0:0.0.0*255(47231330)
1-0:0.2.0*255(V1.0)
1-0:1.8.0*255(006213 kWh)
1-0:1.8.1*255(000000 kWh)
1-0:1.8.2*255(006213 kWh)
1-0:2.8.0*255(007874 kWh)
1-0:2.8.1*255(000000 kWh)
1-0:2.8.2*255(007874 kWh)
FF(00000000)
!
------------------------------------------------------------------------------
2)
Where is the calculating taking place as I sent only status values at 
that time (every 5 minutes)?

Henry


Op 1/8/2013 8:41 AM, Thorben Thuermer schreef:
> Hello,
>
> so you want to use the middleware/frontend to store/visualize your data,
> but can't use vzlogger to import it.
> (the prefered fix would ofcourse be to fix vzlogger to work with your
>   meter! maybe if you give us the details of how you made it work,
>   i.e. which timings are critical etc., we can fix hat for you...)
>
> but there are two alternatives:
> - send the data to the middleware API from your script.
>    the api is quite simple, and documented:
>    http://wiki.volkszaehler.org/development/api/reference
>    (in german, if that's a problem, please complain!)
>    basically all you need is:
>    http://.../middleware.php/data/<uuid>.json?operation=add&value=<value>
>
> - insert the data directly into the middleware's database,
>    no need to put it into an intermediate database first.
>    the format is relativey simple, just look at the database
>    after installing the middleware (and maybe loading the test data).
>
> - T.
>
> On Tue, 8 Jan 2013 00:35:41 +0100
> Henry van Gestel <henry.van.gestel at gmail.com> wrote:
>> Maybe somebody can help me.
>> I am strugling now how to continue , I am be able to get the data from 2
>> Iskra MT171 meters .
>>
>>> I also can put the data in a Mysql DB wondering what data model is used.
>>> e.g timestamp, actual value used , actual generated , PV_collected.
>> A) I wonder where various values like  the avg, max , min is calculated?
>>
>> B) Maybe somebody can give me a hint or a detailed description of vzlogger
>> where and what it is doing.
>>
>> Or
>>
>> How to let vzlogger get the data from sql stored data or a file.
>>
>> Configuration:
>> I have 2 ir heads (from Udo) connected to Rpi, a perl script reads the 2
>> heads every 5 minutes, puts data in a mysql dB e.g  fields are (Timestamp,
>> headnr, PV_produced, normal_tarrif_used, norma_tarrif_produced).
>>
>> Rgrds

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://volkszaehler.org/pipermail/volkszaehler-users/attachments/20130108/d59407a7/attachment-0001.html>
-------------- next part --------------
#!/usr/bin/perl

# Zaehlerabfrage fuer Zaehler nach Protokoll IEC 62056-21 / OBIS
# Ein Anfrage-Telegramm ist mit 300 Baud, 7 Bit, 1 Stoppbit
# und gerader Paritaet zu senden. Das ist der Initialmodus von Geraeten,
# die das Protokoll IEC 62056-21 implementieren.
# Ein Wechsel der Geschwindigkeit ist möglich, in diesem Script aber noch nicht umgesetzt.

# !!! Wiederholung nur alle 3 Minuten da der Zaehler nach Ende des Scriptes weiter sendet !!!

# Basis des Scripts von volkszaehler.org / Autor: Andreas Schulze & Bugfix: Eric Schanze
# DPT9 sub: makki / www.knx-user-forum.de
# In dieser Version keine Anbindung an den KNX-Bus
# Erweiterung um RRD,KNX-Anbindung und gezielte Wertsuche auf Wiregate: 
# JuMi2006 / www.knx-user-forum.de
# Version: 0.1.3
# Datum: 23.04.2012
# edited by H v Gestel 1-1-2013

use warnings;
use strict;
use Device::SerialPort;
use RRDs;
use Data::Dumper;
use DBI;

my $dbh = DBI->connect('DBI:mysql:power_usage:127.0.0.1', 'root', 'marbella'
               ) || die "Could not connect to database: $DBI::errstr";



### KONFIGURATION ###
my $device = "/dev/ttyUSB1";		#Port
my $rrdpath = "/var/www/rrd";		#Pfad für RRDs
my $counterid = "Zaehler_HZ";		#Grundname für RRDs
my %obis=(	"16.7"=>6,		#Obis-Zahl => Anzahl der Stellen z.B.: 6 = 123.45
		"32.7"=>3,
		"52.7"=>3,
		"31.7"=>6,
		"51.7"=>6,
		"71.7"=>6,
		"72.7"=>3,
		"1.8.1"=>10,		#!!!COUNTER!!!
		"1.8.0"=>10);

my %countermode=("1.8.0"=>24);		#Obiscode für Zaehlerstaende
					#RRD gibt Verbrauch pro Tag aus (beta)



### ENDE KONFIGURATION ###
my $endsign = "!";			#Letztes Zeichen im Protokoll vom Zaehler

### Seriellen Port initialisieren

####START 300baud
my $port = new Device::SerialPort($device) || die "can't open $device: $!";
$port->baudrate(300)      || die 'fail setting baudrate';
$port->databits(7)        || die 'fail setting databits';
$port->stopbits(1)        || die 'fail setting stopbits';
$port->parity("even")     || die 'fail setting parity';
$port->dtr_active(0);
$port->rts_active(0);
$port->read_char_time(006);     # 0.5 seconds for each character
#$port->read_const_time(400);   # 1 second per unfulfilled "read" call
$port->write_settings     || die 'fail write settings';


### Anforderungstelegramm senden
my $data="2F3F210D0A";				#Anfrage als HEX "/?!<CR><LF>"
my $request = pack('H*',$data);
						
my $num_out = $port->write($request);
die "write failed\n" unless ($num_out);
die "write inclomplete\n" unless ($num_out == length($request));

### Warte auf Zaehlerkennung

select(undef, undef, undef, 0.5); # 1.5 Sekunden warten


### Telegramm mit ACK und neuer Geschwindigkeit senden

my $data2="063030300D0A";	#ACK und neue Geschwindigkeit in HEX "<ACK>040<CR><LF>"
my $baudwechsel = pack('H*',$data2);	# 000 = 300baud, 040 = 4800baud


my $read = $port->read(25);
#print "ontvangen van tty =\n $read\n";

select(undef, undef, undef, 0.1); # 0.5 Sekunden warten

my $num_out2 = $port->write($baudwechsel);
#print "baudwecksel= $baudwechsel\n";
die "write failed\n" unless ($num_out2);
die "write inclomplete\n" unless ($num_out2 == length($baudwechsel));
#print "2nd $num_out2 Bytes written\n";


my $read2 = $port->read(25);
#print "ontvangen van tty = $read2";
my $read3 = $port->read(10);
#print "ontvangen van tty = $read3";

### AUSLESEN

#my $STALL_DEFAULT=5; # how many seconds to wait for new input
my $STALL_DEFAULT=0.2; # how many seconds to wait for new input
my $timeout=$STALL_DEFAULT; 
my $chars=0;
my $buffer="";

while ($timeout>0) {
        my ($count,$saw)=$port->read(25); 	# Liest 25 Zeichen je Durchlauf aus
        if ($count > 0) {
                $chars+=$count;
                $buffer.=$saw;
		#print ($buffer,"\n");		# Ausgabe der eingelesenen Daten


### FILTER FOR END

if ($buffer =~ /\Q$endsign\E/)			# \Q \E entwertet alle Sonderzeichen dazwischen
{	
$port->close || die "can't close $device: $!";	# Port schlieen
last;						# Schleife verlassen
}




### ENDE FILTER FOR END
}
        else {
                $timeout--;
        }
}

if ($timeout<=0) {
$port->close || die "can't close $device: $!";        
print "Waited $STALL_DEFAULT seconds and never saw what I wanted\n";
		}
print "Values for ttyUSB1\n $buffer \n";		#Nur zur Kontrolle


### FILTER FOR DATA

my $debug = 0;

my($meterno,$htu,$htp);
my @lines = split("\n", $buffer);
print Dumper @lines if ($debug == 1);
foreach my $line (@lines) {
    if($line =~ /0-0:C.1.0/) {
        # Set meterno
        $line =~ s/0-0:C.1.0\*255\(//;
        $line =~ s/\)//;
        $meterno = $line;
        print "meterno: " . $line . "\n" if ($debug == 1);
   }    if($line =~ /1-0:1.8.0/) {
        # Set High tarrif used
        $line =~ s/1-0:1.8.0\*255\(//;
        $line =~ s/kWh\)//;
        $htu = $line;
        print "high tarrif used: " . $line . "\n" if ($debug == 1);
    } elsif ($line =~ /1-0:2.8.0/) {
        # Set high tarrif produced
        $line =~ s/1-0:2.8.0\*255\(//;
        $line =~ s/kWh\)//;
        $htp = $line;
        print "high tarrif produced: " . $line . "\n" if ($debug == 1);
    } else {
        next;
    }
}
#print "meterno= $meterno";
#print "htu= $htu";
#print "htp= $htp";



# write to MySql db 
#my $sql = "insert into iskra_meter (meterno, high_tarrif_used, high_tarrif_produced) values (?,?,?)";
#my $sth = $dbh->prepare($sql);
#$sth->execute($meterno,$htu,$htp);
#}
#$dbh->disconnect();
#


More information about the volkszaehler-users mailing list