Reading the IR port of an IEC 62056-21 Smart Meter

Forum about Smart meters for Energy, Gas and Water and all related
Darius
Starting Member
Starting Member
Posts: 4
Joined: Tue Nov 19, 2013 3:25 am

Re: Reading the IR port of an IEC 62056-21 Smart Meter

Post by Darius »

Thanks very much for this post it is very informative and a lot cheaper than buying from IEC ;)

I have been writing some code in Python (so I can read it on OSX & Linux) and I can elicit a response but it is not reliable. I think it must come down to some timing issue as the test1107.exe programs works 100% of the time (and so I know it's not a hardware issue).

The sample program gives me..
==> /?!<0D><0A>
<== /ACE5SMLCD
==> <06>050<0D><0A>
<== -- STX --
<== C.1(12880041.0(22:48 18-11-13)
<== 1.8.1(0000000597*Wh)
<== 1.8.2(0000000000*Wh)
<== 1.8.3(0000264460*Wh)
<== 1.8.0(0000265057*Wh)
<== 2.8.0(0000511354*Wh)
<== !
<== -- ETX --
<== -- BCC --

but it doesn't say what delays are involved. Does anyone have a full working program they can show me the source for?

Also, with regards to delays - I don't understand why it is necessary to wait 200msec after sending the 'change baud' command.

Thanks.
alias
Member
Member
Posts: 65
Joined: Fri May 06, 2011 5:51 pm
Location: Apeldoorn / Netherlands

Re: Reading the IR port of an IEC 62056-21 Smart Meter

Post by alias »

Hi Darius,

At the beginning of this thread there's some sample code in C# and VB.Net.
If that doesn't help you out, I can have a look at your Python code if you like?

Regards,
Ronald
dutchandre
Starting Member
Starting Member
Posts: 6
Joined: Sun Nov 10, 2013 7:58 pm

Re: Reading the IR port of an IEC 62056-21 Smart Meter

Post by dutchandre »

No one reads this but I'll just try it once more ;)
I've bought the Volkszaehler usb head and installed it's driver on my laptop with XP.
With the iec1107 test programm I can let my Ampy 5227 respond, just like with the above pcb.
This program doesn't see the data the Ampy sends out with it's red led.
Using Hterminal just like Puffin I send a textfile with /?! and 000 in it but the terminal doesn't get any useful data back.
I suppose the Hterminal only has to be set to 300baud, 7 bits and even parity.
When I use a blank sheet of paper the tekst is echoed back so the usb head seems to work fine.
What's going wrong here, the usb head responds when I send codes with an ir remote but it doesn't see the Ampy :(
Darius
Starting Member
Starting Member
Posts: 4
Joined: Tue Nov 19, 2013 3:25 am

Re: Reading the IR port of an IEC 62056-21 Smart Meter

Post by Darius »

alias wrote: At the beginning of this thread there's some sample code in C# and VB.Net.
If that doesn't help you out, I can have a look at your Python code if you like?
I realised what my problem was - I was reading fixed sizes instead of using readline. This meant the timing was off and the meter would reject the request.
The following code works for me in python (tested on OSX but I expect it to work anywhere you have pyserial available)

Code: Select all

import exceptions
import serial

class Error(exceptions.BaseException):
    pass

def readmeter(portname):
    s = serial.Serial(portname, baudrate = 300, bytesize = 7, parity = 'E', stopbits = 1)
    s.timeout = 1.5

    # Send ident message
    s.write('/?!\r\n')

    rtn = s.readline()
    if len(rtn) < 6 or rtn[0] != '/' or rtn[-1] != '\n' or rtn[-2] != '\r':
        raise Error('Invalid line "%s"' % (rtn))

    # ACK meter and ask for data
    s.write('\x06000\x0d\x0a')
    s.timeout = 2

    lines = []
    cksum = 0

    line = s.readline()
    if len(line) == 0 or line[0] != '\x02':
        raise Error('No reply to query or invalid reply \"%s\"' % (line))
    else:
        cksum ^= reduce(lambda x, y: x ^ y, map(ord, line[1:]))
        lines.append(line[1:].strip())
    while True:
        line = s.readline()
        cksum ^= reduce(lambda x, y: x ^ y, map(ord, line))
        line = line.strip()
        if len(line) == 0:
            raise Error('Timeout during message')
        if line == '!':
            break
        lines.append(line)
    fin = s.read(2)
    if len(fin) != 2:
        raise Error('Timeout reading trailer')
    if fin[0] != '\x03':
        raise Error('Trailer malformed, expected 0x03, got 0x%02x' % (ord(fin[0])))

    cksum ^= ord(fin[0])
    if cksum != ord(fin[1]):
        raise Error('Checksum mismatch, expected 0x%02x, got 0x%02x' % (cksum, ord(fin[1])))
    return lines
I get the following output

Code: Select all

In [26]: iec1107.readmeter('/dev/cu.usbserial-AM01Z7UC')
Out[26]:
['C.1(12880041.0(09:04 20-11-13)',
 '1.8.1(0000000597*Wh)',
 '1.8.2(0000000000*Wh)',
 '1.8.3(0000281053*Wh)',
 '1.8.0(0000281650*Wh)',
 '2.8.0(0000535712*Wh)']
I am using a variant of the Elektor circuit, however mine uses an FTDI USB dongle.

I suppose now I should try changing the baud rate :)
Darius
Starting Member
Starting Member
Posts: 4
Joined: Tue Nov 19, 2013 3:25 am

Re: Reading the IR port of an IEC 62056-21 Smart Meter

Post by Darius »

dutchandre wrote:No one reads this but I'll just try it once more ;)
I've bought the Volkszaehler usb head and installed it's driver on my laptop with XP.
With the iec1107 test programm I can let my Ampy 5227 respond, just like with the above pcb.
This program doesn't see the data the Ampy sends out with it's red led.
Using Hterminal just like Puffin I send a textfile with /?! and 000 in it but the terminal doesn't get any useful data back.
I suppose the Hterminal only has to be set to 300baud, 7 bits and even parity.
When I use a blank sheet of paper the tekst is echoed back so the usb head seems to work fine.
What's going wrong here, the usb head responds when I send codes with an ir remote but it doesn't see the Ampy :(
What do you mean exactly? Does the test1107.exe program read anything out at all? Can you post the log from it?

I believe that the communications is done at infrared, so you won't actually see it. The meter I have does flash a red LED every Watt hour, but that is separate to the IR part.
Darius
Starting Member
Starting Member
Posts: 4
Joined: Tue Nov 19, 2013 3:25 am

Re: Reading the IR port of an IEC 62056-21 Smart Meter

Post by Darius »

If anyone is interested my code is at http://www.dons.net.au/%7Edarius/hgwebdir.cgi/iec1107/
dutchandre
Starting Member
Starting Member
Posts: 6
Joined: Sun Nov 10, 2013 7:58 pm

Re: Reading the IR port of an IEC 62056-21 Smart Meter

Post by dutchandre »

Darius wrote:
dutchandre wrote:No one reads this but I'll just try it once more ;)
I've bought the Volkszaehler usb head and installed it's driver on my laptop with XP.
With the iec1107 test programm I can let my Ampy 5227 respond, just like with the above pcb.
This program doesn't see the data the Ampy sends out with it's red led.
Using Hterminal just like Puffin I send a textfile with /?! and 000 in it but the terminal doesn't get any useful data back.
I suppose the Hterminal only has to be set to 300baud, 7 bits and even parity.
When I use a blank sheet of paper the tekst is echoed back so the usb head seems to work fine.
What's going wrong here, the usb head responds when I send codes with an ir remote but it doesn't see the Ampy :(
What do you mean exactly? Does the test1107.exe program read anything out at all? Can you post the log from it?

I believe that the communications is done at infrared, so you won't actually see it. The meter I have does flash a red LED every Watt hour, but that is separate to the IR part.
The log shows this:
==> /?! <0D><0A>
<== -- Tout --

Not all meters send at infrared, this Ampy shows the data in red after request (burst of 1 sec after it gets /?! ).
The funny thing is that Puffin gets it to work with hterminal and I can't.
For now it seems that both my sensors can't detect red light.
The pcb I posted above could be limited to 1200bd but if Puffin's story is right the Ampy talks back with 300bd.
Maybe he has a different fototransistor?
dutchandre
Starting Member
Starting Member
Posts: 6
Joined: Sun Nov 10, 2013 7:58 pm

Re: Reading the IR port of an IEC 62056-21 Smart Meter

Post by dutchandre »

To comment myself, I found out that red ranges from 620 to 750nm and the SFH309FA in Udo's usb head ranges from 730 to 1120nm.
There also exists a standard SFH309 ranging from 380 to 1150nm which would fit far better for detecting red light.
My pcb may also have the same mismatching color range.
dutchandre
Starting Member
Starting Member
Posts: 6
Joined: Sun Nov 10, 2013 7:58 pm

Re: Reading the IR port of an IEC 62056-21 Smart Meter

Post by dutchandre »

The ir receiver came today, not bad :)
I've replaced it and now my Ampy 5227 at least responses to the requests of iec1107 tester!
It's log looks like this:

==> /?!<0D><0A>
<== /?!
<== --- 0x2F ---
<== --- 0x41 ---
<== --- 0x4D ---
<== --- 0x50 ---
<== --- 0x34 ---
<== --- 0x35 ---
<== --- 0x32 ---
<== --- 0x32 ---
<== --- 0x37 ---
<== --- 0x2D ---
<== --- 0x30 ---
<== --- 0x36 ---
<== --- 0x31 ---
<== --- 0x34 ---
<== --- 0x0D ---
<== --- 0x0A ---
<== -- Tout --

When I translate this to characters it says Ampy45227-614, just like I read earlier in this topic.
Next is getting more data using Hterm and here something goes wrong.
I've tried to send textfiles like Udo suggests but the Ampy doesn't respond to this.
The only thing I see is ' ' ' every time the Ampy led flashes (normal operation).
So I think my textfile has the wrong information or a wrong format.
Can someone tell how it has to look and what the Hterm settings should be?

Image
Puffin
Starting Member
Starting Member
Posts: 6
Joined: Wed Oct 10, 2012 3:36 pm

Re: Reading the IR port of an IEC 62056-21 Smart Meter

Post by Puffin »

Just now noticed activity, sorry for the late response.

As IR receiver I use the BPW40 = BPW96 (Conrad itemno: 184055), sensitive in the range 620-980 nm.
And Iam using HyperTerminal, a Microsoft terminal program in windows XP, not the Hterm.
Hyper terminal main setting are 300 bit per second, 7 data bits (not 8), even parity, one stop bit and CR LF at line end
Have attached the settings file and an text file I upload trough “Transfer” ->> “Send text File” in Hyper terminal, both inside the AMP5227.zip
AMP5227.zip
Hyper terminal settings
& Read at 300 bd
(768 Bytes) Downloaded 818 times
After receiving the meter “ identification message” at 300 baud you can send the "acknowledgement/option"
<06>000<0D><0A> requesting: normal protocol procedure, baudrate “0” = 300 baud, read data.
or
<06>040<0D><0A> requesting: normal protocol procedure, baudrate “4” = 4800 baud, read data.
To make sure the request is send after receiving the meter ID, I used an line delay of 1000 ms set in the HyperTerminal.

The maximum baud rate for the requested data of the AMP 5227 is “4” = 4800 baud,
which is used and requested by the "IEC 1107 meter test",
so best to set the transmit baudrate to “auto” in this software.

Folkert
dutchandre
Starting Member
Starting Member
Posts: 6
Joined: Sun Nov 10, 2013 7:58 pm

Re: Reading the IR port of an IEC 62056-21 Smart Meter

Post by dutchandre »

ImageImage

Thanks for the files, now it works!!
Metertest didn't see any data after the identification last time but now I've added a usb hub and I alligned the r/w head better.
Next for me is adding a led to the r/w head to enable my Wattcher again.
This led will simply show the data received by the r/w head.
The Wattcher can show the momentary used power and my Homewizard logs this data.
I know that the Wattcher sees the difference between power use and supply but it's still useful information ;)
Finally I'll try to log the data with my Rasberry pi and push it to pvoutput.
Last edited by dutchandre on Tue Mar 17, 2015 11:00 am, edited 1 time in total.
eDsuB
Starting Member
Starting Member
Posts: 33
Joined: Mon Jan 11, 2010 1:25 pm
Contact:

Re: Reading the IR port of an IEC 62056-21 Smart Meter

Post by eDsuB »

It has been some time I have visited this forum, but in case anyone is interested I have a few datalogger scripts ready made for a number of utility meters (Electricity and Heat). All programmed in Python3 and (under a CC license) free to use, please see http://www.smartmeterdashboard.nl under downloads.
The scripts use serial communication as is available when using the IR readout head that is supplied by http://www.volkszaehler.org / Udo
Post Reply

Return to “Smart Metering Forum”