Java library in Android applications

The icube Java library can be used ''out of the box'' in Android applications. The App icube DMLS demo is a proof of concept. It reads 4 electricity values and the ''clock'' out of a L+G DLMS meter.

icube DLMS demo screenshot
The App opens an HDLC connection, using the ezhdlc library.

Then it establishes an application-association and reads the values using the xmlpdu library. 

The traffic goes through the local port of the meter and uses a Bluetooth optical probe.
The App builds its communication stack on top of the Bluetooth serial profile available in Android.

The libraries greatly simplify the work with the DLMS/COSEM protocols. Essentially, the code to read an attribute out of a DLMS compliant meter is the following:

1 - Create a Request

The request is created as a short xml text snippet. In the example below, ClassId, InstanceId and AttributeId identifie the attribute to read.

    <InvokeIdAndPriority Value="C1" />
      <ClassId Value="0003" />
      <InstanceId Value="0101010800FF" />
      <AttributeId Value="02" />

2- Translate the request to a PDU using xmlpdu

The xml snippet is passed to the xmlpdu library that translates it into a protocol-data-unit (PDU) byte stream. The PDU byte stream is the ''encoding'' of the DLMS service specified in the xml text (GetRequest service in our example).

3 - Pass the resulting byte stream to ezhdlc

The PDU is passed to ezhdlc that sends it to the meter segmented into HDLC frames. The library handles the addressing, the segmentation, the CRC computation a transparent manner. The meter returns its response in the form of HDLC frames which are in turn received and re-assembled. The resulting byte stream is finally the PDU of the response DLMS service, sent by the meter.

4- Pass the returned byte stream to xmlpdu

The library xmlpdu translate the PDU into a xml text snippet:

    <InvokeIdAndPriority Value="C1" />
        <DoubleLongUnsigned Value="000007D3" />

5- Finally, extract the required value from the xml text

In the most simple cases, the required information can be trivially extracted from the xml text using string handling routines. Otherwise, the xml text can be analyzed using the XML classes available in Android. The whole process is described in more details here.

The Android Studio project (source) can be requested at the email address below.

The Bluetooth optical probe (ED Typ: 2515 Bluetooth Infrared Adapter) is available from edvogts. However, the architecture allows to easily adapt any other Bluetooth probe.