Migrated openhab2 IEC 62056 21 Meter Binding

hi thomas,

concerning the installation of librxtx use following command to see what and were the files of the package are installed

dpkg-query -L librxtx-java

you may copy he then the corressponding file to the dependency folder

/peter

Hello Peter,
I tried the new OH2 binding as per your advice (instead of the OH1 binding) but got the following error in the openhab2.log:

at org.eclipse.osgi.framework.eventmgr.EventManager$EventThread.run(EventManager.java:340)[org.eclipse.osgi-3.10.101.v20150820-1432.jar:]
Caused by: java.lang.ClassNotFoundException: org.openhab.binding.iec6205621meter.Iec6205621MeterBindingConstants cannot be found by org.openhab.binding.iec6205621meter_2.1.0.201705170128

See attached full log excerpt for more details. (it is a plain text logfile, but file extension changed to xml to allow uploading here)

What I did:
I just copied the new OH2 binding jar file into /usr/share/openhab2/addons/

In karaf consle the new binding was marked as active then but did obviously not start/load properly. Nothing appeared in PaperUI.

Do I need to do something else?

Thanks,
Jo
openhab2.log_install_iec_binding_error_20170611_excerpt.xml (353.6 KB)

jar file on google drive seems to be ok, download and deployed in my OH2 , everything works ok
i checked , the required class is in the jar.

i case somehting is wrong i uploaded again a version working in my OH2

BR
peter

Hello,
I downloaded jar file again from your link, no change, same error:

Caused by: java.lang.ClassNotFoundException: org.openhab.binding.iec6205621meter.Iec6205621MeterBindingConstants cannot be found by org.openhab.binding.iec6205621meter_2.1.0.201706112205

Serial Binding is installed:

191 | Active   |  80 | 3.12.0.OH             | nrjavaserial
192 | Active   |  80 | 1.9.0                 | openHAB Serial Binding
206 | Active   |  80 | 0.9.0.b4              | YahooWeather Binding
207 | Active   |  80 | 2.0.0                 | Astro Binding
208 | Active   |  75 | 0.9.0.b4              | Eclipse SmartHome Map Transformation Service
209 | Active   |  80 | 0.9.0.b4              | ntp Binding
210 | Active   |  80 | 1.9.0                 | openHAB HTTP Binding
213 | Active   |  75 | 0.9.0.b4              | Eclipse SmartHome RegEx Transformation Service
214 | Active   |  80 | 1.9.0                 | openHAB MQTT Binding
215 | Active   |  80 | 1.9.0                 | openHAB MQTT Transport Bundle
216 | Active   |  80 | 2.1.0.201706112205    | Iec6205621Meter Binding

Regards,
Jo

hi jo ,
no idea what is going wrong here.
some basic thing is not working.
Iec6205621MeterHandlerFactory is accesscing some constants

do you know what the number in brackets ins meaning?
[binding.iec6205621meter(204)
somehow this number is increasing. is this the bundle number?

BR
peter

Yes, I think this is the internal bundle number (216 for the IECā€¦ bundle in my case)

if so then why is this counting up. Do you have multiple files in your /usr/share/openhab2/addons/ ?

BR
Peter

REgarding your question: I just had the old OH1 IEC binding also under the addons directory - but was already removed. I think the counter is just counting up depending on what binding is installed.

I tried now several things:

  • Disabled serial binding in karaf console (openHAB Serial Binding)
  • Disabled nrjavaserial bundle in karaf console
  • uninstalled and reinstalled the new OH2 IEC binding
  • restarted OH2

Then, suddenly it worked :-), at least I see the new IEC binding in OH2 Paper UI and can configure new thing and item.

So I could not really reproduce fully what was the real issue here as after restart I do have similar bundle status - but it worksā€¦

191 | Active   |  80 | 3.12.0.OH             | nrjavaserial
192 | Active   |  80 | 1.9.0                 | openHAB Serial Binding
206 | Active   |  80 | 0.9.0.b4              | YahooWeather Binding
207 | Active   |  80 | 2.0.0                 | Astro Binding
208 | Active   |  75 | 0.9.0.b4              | Eclipse SmartHome Map Transformation Service
209 | Active   |  80 | 0.9.0.b4              | ntp Binding
210 | Active   |  80 | 1.9.0                 | openHAB HTTP Binding
213 | Active   |  75 | 0.9.0.b4              | Eclipse SmartHome RegEx Transformation Service
214 | Active   |  80 | 1.9.0                 | openHAB MQTT Binding
215 | Active   |  80 | 1.9.0                 | openHAB MQTT Transport Bundle
217 | Active   |  80 | 2.1.0.201706112205    | Iec6205621Meter Binding

Now Iā€™m struggling with configuration. I do have Elster AS 1440 Meter but the binding always says (under thing configuration):

Status: OFFLINE - CONFIGURATION_ERROR Could not get data from IEC 62056-21 meter connected to /dev/ttyUSB0

Port is the correct one, I can also connect to the serial port via picocom successfully and connect also to the meter - so serial correction is working. Also the old IEC binding worked with this meter - so not sure how to further debug nowā€¦

ok , great to see that binding is back again
concerning the serial connection.
have you tried to enable the DEBUG to get additional logs in karaf?
There should be some more additional infos in the log if no data are coming.

I checked the datasheet of AS 1440, it should support 62056-21

BR
peter

hi jo,

did you came further on enabling DEBUG on the binding to see where we are struggling during building up the communication to the meter?

if you like to see more you can do the following:

  1. 'ssh -p 8101 openhab@localhost , pw is habopen

  2. ā€˜log:set DEBUG org.openhab.binding.iec6205621meterā€™

  3. log:tail

  4. go to the paperUI and create the meter thing and you should see something like this

    2017-06-28 18:27:33.715 [Iec6205621MeterHandler ] - Initializing IEC 62056-21 handler for ā€˜iec6205621meter:meter:a00100c9ā€™.
    2017-06-28 18:27:33.715 [Iec6205621MeterHandler ] - Initializing IEC 62056-21 handler ā€˜iec6205621meter:meter:a00100c9ā€™ with configuration: port ā€˜/dev/ttyS0ā€™, baudRateChangeDelay 0, echoHandling false , init 20, refresh {}.
    2017-06-28 18:27:37.117 [Iec6205621MeterHandler ] - DataSet: /LGZ4ZMF100AC.M27;;
    2017-06-28 18:27:37.118 [Iec6205621MeterHandler ] - DataSet:oF.F;00;
    2017-06-28 18:27:37.118 [Iec6205621MeterHandler ] - DataSet: 0.0; xxxxx;
    2017-06-28 18:27:37.118 [Iec6205621MeterHandler ] - DataSet: C.1.0;xxxxx;
    2017-06-28 18:27:37.118 [Iec6205621MeterHandler ] - DataSet: C.1.1; ;
    2017-06-28 18:27:37.119 [Iec6205621MeterHandler ] - DataSet: 1.8.1;009651.766;kWh
    2017-06-28 18:27:37.119 [Iec6205621MeterHandler ] - DataSet: 1.8.2;013913.013;kWh
    2017-06-28 18:27:37.119 [Iec6205621MeterHandler ] - DataSet: 2.8.1;000000.000;kWh
    2017-06-28 18:27:37.120 [Iec6205621MeterHandler ] - DataSet: 2.8.2;000000.000;kWh
    2017-06-28 18:27:37.120 [Iec6205621MeterHandler ] - DataSet: 1.8.0;023564.779;kWh
    2017-06-28 18:27:37.120 [Iec6205621MeterHandler ] - DataSet: 2.8.0;000000.000;kWh
    2017-06-28 18:27:37.121 [Iec6205621MeterHandler ] - DataSet: 15.8.0;023564.779;kWh
    2017-06-28 18:27:37.121 [Iec6205621MeterHandler ] - DataSet: C.7.0;0003;
    2017-06-28 18:27:37.121 [Iec6205621MeterHandler ] - DataSet: 32.7;237;V
    2017-06-28 18:27:37.121 [Iec6205621MeterHandler ] - DataSet: 52.7;238;V
    2017-06-28 18:27:37.121 [Iec6205621MeterHandler ] - DataSet: 72.7;238;V
    2017-06-28 18:27:37.122 [Iec6205621MeterHandler ] - DataSet: 31.7;00.450;A
    2017-06-28 18:27:37.122 [Iec6205621MeterHandler ] - DataSet: 51.7;00.214;A
    2017-06-28 18:27:37.122 [Iec6205621MeterHandler ] - DataSet: 71.7;00.318;A
    2017-06-28 18:27:37.122 [Iec6205621MeterHandler ] - DataSet: 82.8.1;0000;
    2017-06-28 18:27:37.122 [Iec6205621MeterHandler ] - DataSet: 82.8.2;0000;
    2017-06-28 18:27:37.122 [Iec6205621MeterHandler ] - DataSet: 0.2.0;M27;
    2017-06-28 18:27:37.123 [Iec6205621MeterHandler ] - DataSet: C.5.0;0401;

In case you do not get access to the port the existing, from java perspective availabel ports are listed in the DEBUG log

i case you have a usb to r232 convertermake sure you set the delaytime

/Peter

Hello Peter,
Thank you for your meter binding.
I have a meter Iskra MT174 connected via RS485 interface (chiness CH341 usb to serial adapter) and Iā€™m realy sure it iec6205621 meter (I have checked it using echo and cat of /dev/ttyUSB0)
Butā€¦ iā€™he got a problem. Your binding always try to open port at a speed 300. itā€™s good for optical interface, but is not for rs485 - every time ā€œtimeoutā€
+++++++++++++++++++++++++++
4.10.1 Local Optical Interface
The local optical interface supports IEC 62056-21 mode C for data reading and parameterisation.
ā€¦
The optical interface handshake starts at 300bps regardless of the setting defined in Table 4-12
Communications Interfaces.
4.10.2 RS-485 Interface
The optional RS-485 interface also conforms to IEC 62056-21 and IEC 62056-61 and enables connection of up to 31 MT174 meters to a single concentrator, e.g. the P2CC communicator.
ā€¦
C must be used for data exchange and the data transmission rate is fixed. The default is 9600bps strong textbut may be configured between 300 and 19200bps depending on the masterā€™s capability and configuration.


Is it possible to make a fork of this binding for rs485 version Iskrra meters.
We does not need to change rate automatically (no no time out of rate change), but manually set it via config (default 9600).
Also will be good configure serial number (/?!) of meter to make ability bind more then one meter in rs485 network (default - empty request /?! )
Unfortunately, Iā€™m not good at Java coding to help you.
Best regards, Gennadiy

Hi,

interisting inside on the protpocol.
Actually the protocol implementation is done based on the https://www.openmuc.org/iec-62056-21/

Not sure if the latest version will fix the issue you report on establishing the baud rate and allow fixedbaud rate.

When i migrated the code from OH1 to OH2 the new library from openmuc has changed the serial library which were not fitting to the OH2 structure.
Thats why did not updated to the latest library.

If you could use the openmuc library and provided command line tool to test if the connection is working and you receive data as a fist starting point would be good.

If it is working we could then investigate to update the openmuc library to that library .

Would that be possible?

/peter

no problem. Iā€™ll try. :slight_smile:
openhab installed on RPi 3 the latest openhabian image.
If you tel me what should i do, I will try.

It may be iskra mt174 is partly follow protocols.

Gennadiy

Iā€™he got some errors trying run reader
~/java/j62056/run-scripts $ ./j62056-reader -p /dev/ttyUSB0 -b 300 -d 100 -t 30000 -v
Could not load lib from jar and from system.
gnu.io.LibLoadException: directory does not exist /libs
at gnu.io.LibraryLoader.loadLib(LibraryLoader.java:65)
at gnu.io.LibraryLoader.loadLibsFromJar(LibraryLoader.java:48)
at gnu.io.LibraryLoader.loadRxtxNative(LibraryLoader.java:29)
at gnu.io.RXTXCommDriver.(RXTXCommDriver.java:85)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:264)
at gnu.io.CommPortIdentifier.(CommPortIdentifier.java:104)
at org.openmuc.jrxtx.JRxTxPort.openSerialPort(JRxTxPort.java:50)
at org.openmuc.jrxtx.SerialPortBuilder.build(SerialPortBuilder.java:166)
at org.openmuc.j62056.Iec21Port.(Iec21Port.java:270)
at org.openmuc.j62056.Iec21Port.(Iec21Port.java:47)
at org.openmuc.j62056.Iec21Port$Builder.buildAndOpen(Iec21Port.java:243)
at org.openmuc.j62056.app.Reader.main(Reader.java:73)
java.lang.UnsatisfiedLinkError: no rxtxSerial in java.library.path thrown while loading gnu.io.RXTXCommDriver
Could not load lib from jar and from system.
gnu.io.LibLoadException: directory does not exist /libs
at gnu.io.LibraryLoader.loadLib(LibraryLoader.java:65)
at gnu.io.LibraryLoader.loadLibsFromJar(LibraryLoader.java:48)
at gnu.io.LibraryLoader.loadRxtxNative(LibraryLoader.java:29)
at gnu.io.CommPortIdentifier.(CommPortIdentifier.java:118)
at org.openmuc.jrxtx.JRxTxPort.openSerialPort(JRxTxPort.java:50)
at org.openmuc.jrxtx.SerialPortBuilder.build(SerialPortBuilder.java:166)
at org.openmuc.j62056.Iec21Port.(Iec21Port.java:270)
at org.openmuc.j62056.Iec21Port.(Iec21Port.java:47)
at org.openmuc.j62056.Iec21Port$Builder.buildAndOpen(Iec21Port.java:243)
at org.openmuc.j62056.app.Reader.main(Reader.java:73)
Exception in thread ā€œmainā€ java.lang.UnsatisfiedLinkError: no rxtxSerial in java.library.path
at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1867)
at java.lang.Runtime.loadLibrary0(Runtime.java:870)
at java.lang.System.loadLibrary(System.java:1122)
at gnu.io.LibraryLoader.loadRxtxNative(LibraryLoader.java:32)
at gnu.io.CommPortIdentifier.(CommPortIdentifier.java:118)
at org.openmuc.jrxtx.JRxTxPort.openSerialPort(JRxTxPort.java:50)
at org.openmuc.jrxtx.SerialPortBuilder.build(SerialPortBuilder.java:166)
at org.openmuc.j62056.Iec21Port.(Iec21Port.java:270)
at org.openmuc.j62056.Iec21Port.(Iec21Port.java:47)
at org.openmuc.j62056.Iec21Port$Builder.buildAndOpen(Iec21Port.java:243)
at org.openmuc.j62056.app.Reader.main(Reader.java:73)

HI,

have download and run the script on my ubuntu server.
I also installed librxtx-java with apt to get the libray installed on the system.
Unfortunately i do not get the commucniation up and running for my meter. Maybe that was the reason i did not more to the latest version of the openmuc.
here the output i get.
sudo ./j62056-reader -p /dev/ttyS0 -b 300 -v
DEBUG: Sending {ā€œrequest messageā€: {ā€œdevice addressā€: ā€œā€}}
IOException while trying to read: Expected carriage return character not received

can you try to install the librxtx-java on the openhabian?

Hello Peter
Iā€™forced to start script slightly modifying j62056-reader to add SYSPROPS="-Djava.library.path=/usr/lib/jni"
and :/usr/share/java/*.jar to CLASSPATH

Results here
First with baudrate 300 was not success :frowning:
sudo ./j62056-reader -p /dev/ttyUSB0 -b 300 -d 100 -t 5000 -v
DEBUG: Sending {ā€œrequest messageā€: {ā€œdevice addressā€: ā€œā€}}
Read attempt timed out.

Next with baudrate 9600 and change ability
sudo ./j62056-reader -p /dev/ttyUSB0 -b 9600 -d 100 -t 5000 -v
DEBUG: Sending {ā€œrequest messageā€: {ā€œdevice addressā€: ā€œā€}}
DEBUG: Received {ā€œidentification messageā€: {ā€œmanufacturer IDā€: ā€œISkā€, ā€œprotocol modeā€: ā€œCā€, ā€œbaud rateā€: 9600, ā€œmeter IDā€: ā€œMT174-0001ā€, ā€œenhanced ID/capabilityā€: ā€œā€}}
DEBUG: Sending {ā€œacknowledge messageā€: {ā€œprotocol control characterā€: ā€œNORMALā€, ā€œbaud rateā€: 9600, ā€œacknowledge modeā€: ā€œDATA_READOUTā€}}
DEBUG: Sleeping for : 100ms before changing the baud rate
DEBUG: Changing baud rate from 9600 to 9600
DEBUG: Received data message.
Received
{
ā€œdata messageā€: {
ā€œmanufacturer IDā€: ā€œISkā€,
ā€œmeter IDā€: ā€œMT174-0001ā€,
ā€œenhanced ID/capabilityā€: ā€œā€,
ā€œdata blockā€: {
ā€œdata setā€: {ā€œaddressā€: ā€œ1-0:0.9.1255", ā€œvalueā€: ā€œ200437ā€, ā€œunitā€: ā€œā€},
ā€œdata setā€: {ā€œaddressā€: "1-0:0.9.2
255ā€, ā€œvalueā€: ā€œ0171105ā€, ā€œunitā€: ā€œā€},
ā€œdata setā€: {ā€œaddressā€: ā€œ1-0:0.9.4*255ā€, ā€œvalueā€: ā€œ0171105200437ā€, ā€œunitā€: ā€œā€},

ā€¦

                    "data set": {"address": "1-0:2.8.3*14", "value": "", "unit": ""},
                    "data set": {"address": "1-0:2.8.3*15", "value": "", "unit": ""}
            }
    }

}

Last one - baudrate 9600 and fix rate
sudo ./j62056-reader -p /dev/ttyUSB0 -b 9600 -f -t 5000 -v
DEBUG: Sending {ā€œrequest messageā€: {ā€œdevice addressā€: ā€œā€}}
DEBUG: Received {ā€œidentification messageā€: {ā€œmanufacturer IDā€: ā€œISkā€, ā€œprotocol modeā€: ā€œCā€, ā€œbaud rateā€: 9600, ā€œmeter IDā€: ā€œMT174-0001ā€, ā€œenhanced ID/capabilityā€: ā€œā€}}
DEBUG: Sending {ā€œacknowledge messageā€: {ā€œprotocol control characterā€: ā€œNORMALā€, ā€œbaud rateā€: 9600, ā€œacknowledge modeā€: ā€œDATA_READOUTā€}}
DEBUG: Received data message.
Received
{
ā€œdata messageā€: {
ā€œmanufacturer IDā€: ā€œISkā€,
ā€œmeter IDā€: ā€œMT174-0001ā€,
ā€œenhanced ID/capabilityā€: ā€œā€,
ā€œdata blockā€: {

As you see baudrate 9600 gives good answer from my meter

great to see that the library is working for your meter.

I have started load the source into eclipse project to start investigating the issue i had on my meter.
Will keep you updated.

To the others in the thread. Is else somebody could look into the new version of the libray to gain experciences in the new version.

hi

finally have code from openmuc up and running.
Had to add also the jrtxt library.

The issue on my meter seems to be in the initlal request which i fixed on the old library (1.2)
So basically it is just work to be done to also get my meter connecting with the latest version of the library. It would also be good if others using the current binding to verify if the new library is working for them.

When done the i need to also migrate the current binding to the latest version of the library.
So this will require some time to do that.

BR
peter

Ok, finally got latest library version 2.1.0 running with my meter.
somehow my meter send some strange bytes .
Anyway, had to modify the code to deal with getting initial identification message and data requests.
I have created a new library which you can download here
https://drive.google.com/file/d/0B76ZUH63aPGQc2lWMGI4RG9hSDA/view?usp=sharing

Could you please verify if my modifications also do not impact loading data from your meter?

Thx