energy management information system web service for remote... · energy management information...

35
ENERGY MANAGEMENT INFORMATION SYSTEM EMIS Web Service for Remote Readings and Bills Issue 2019-07-25

Upload: others

Post on 28-Sep-2020

0 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: ENERGY MANAGEMENT INFORMATION SYSTEM Web Service for Remote... · ENERGY MANAGEMENT INFORMATION SYSTEM EMIS Web Service for Remote Readings and Bills ... of EMIS model, IDs of records

ENERGY MANAGEMENT

INFORMATION SYSTEM

EMIS Web Service for Remote Readings and Bills

Issue 2019-07-25

Page 2: ENERGY MANAGEMENT INFORMATION SYSTEM Web Service for Remote... · ENERGY MANAGEMENT INFORMATION SYSTEM EMIS Web Service for Remote Readings and Bills ... of EMIS model, IDs of records

EMIS Web Service for Remote Readings and Bills

1

CONTENTS 1 Preface: Data Structure ........................................................................................................................................ 3

1.1 Remote bills .................................................................................................................................................. 3

1.2 Remote readings ........................................................................................................................................... 4

2 Web Service Data Exchange ................................................................................................................................. 5

2.1 Overview ....................................................................................................................................................... 5

2.2 Connecting to the REST Web Service ........................................................................................................... 5

2.3 Authentication .............................................................................................................................................. 5

2.3.1 Authentication Example ....................................................................................................................... 6

2.4 Echo Method ................................................................................................................................................ 6

2.4.1 Echo Request ........................................................................................................................................ 6

2.4.2 Echo Response ...................................................................................................................................... 6

2.4.3 Examples ............................................................................................................................................... 7

2.5 Batch Sending Method ................................................................................................................................. 8

2.5.1 Batch Request Structure ....................................................................................................................... 8

2.5.2 Batch Response Structure..................................................................................................................... 9

2.5.3 Batch-Contained Objects Structure ...................................................................................................... 9

2.6 Query Methods for Remote Readings ........................................................................................................ 19

2.6.1 Meters Query ...................................................................................................................................... 19

2.6.2 Readings Query ................................................................................................................................... 21

2.7 Service Response Codes ............................................................................................................................. 24

3 Command-Line Client ......................................................................................................................................... 26

3.1 Installing the Client ..................................................................................................................................... 26

3.2 Configuring the Client ................................................................................................................................. 26

3.2.1 Quick Start .......................................................................................................................................... 26

3.2.2 Configuration Parameters .................................................................................................................. 27

3.2.3 Passing Parameters in Command Line................................................................................................ 28

3.2.4 Getting a Help Cheat-Sheet ................................................................................................................ 28

3.2.5 Encrypting a Password ........................................................................................................................ 28

3.2.6 Default Configuration File Locations .................................................................................................. 28

3.2.7 Using the Client behind a Web Proxy ................................................................................................. 28

3.3 Return Codes .............................................................................................................................................. 29

3.4 Scheduling Batches ..................................................................................................................................... 29

4 Simple Client Example in Java ............................................................................................................................. 30

Page 3: ENERGY MANAGEMENT INFORMATION SYSTEM Web Service for Remote... · ENERGY MANAGEMENT INFORMATION SYSTEM EMIS Web Service for Remote Readings and Bills ... of EMIS model, IDs of records

EMIS Web Service for Remote Readings and Bills

2

5 DataSupplier Web Interface ............................................................................................................................... 32

Page 4: ENERGY MANAGEMENT INFORMATION SYSTEM Web Service for Remote... · ENERGY MANAGEMENT INFORMATION SYSTEM EMIS Web Service for Remote Readings and Bills ... of EMIS model, IDs of records

EMIS Web Service for Remote Readings and Bills

3

1 PREFACE: DATA STRUCTURE

1.1 Remote bills

In order to use the Web Service, the data model structure will be explained first.

This is data model for sending of remote bills. This model is independent from structure and primary/foreign keys

of EMIS model, IDs of records in this model are defined by data supplier, and only after the data is sent to EMIS, it

will be processed and mapped to EMIS IDs.

Bills

Bill DataBILL_ID

Metering Points

METER_ID

Vendors

Tariffs

TARIFF_ID

ENERGENT_ID

VENDOR_ID

Energy Carrier Fields

BILLITEM_ID

ENERGENT_IDENERGENT_IDENERGENT_ID

Energy Carriers

VENDOR_ID

1. Vendors – Vendors provide one or more energy products. A vendor can issue one more types of bills for

one energy products. These usually make a fixed registry that seldom changes.

2. Energy Carriers – Also referred to as “energy products”, such as electrical energy, natural gas and so on.

Energy carriers also make a fixed registry.

3. Energy Carrier Fields – Each energy product can have several fields that are specified on a bill (amount,

fee, lump sum, interest etc.). Energy Carrier Fields make a registry that does not change often.

4. Tariff – Tariffs usually appear in case of electrical energy, but they can also be found in cases of other

energy products. They are internally used in EMIS group bill field entries, specify different billing rates etc.

There must be at least one tariff per energy carrier registered. Tariffs are also seldom changed.

5. Metering Points – Metering point (for which the bill is sent) is a location for which the bill is issued. It is

not necessarily identical to metering point that reads the consumption. For instance, in cases of electrical

energy, water or gas, the bill is issued to the metering point even when e.g. water consumption is

calculated per number of occupants in a flat (the bill is issued on the flat so there is a virtual billing and

metering point.)

In cases such as central heating where radiators have heat meters, each meter is a metering point (as far

as reading is concerned) but the bill is issued for a flat. Although such situation can be discussed with Data

Supplier, the flat is a fictitious billing and metering point (receives the bill, does not need readings as

well). The flat ID is an identifier of the metering point to which the bill is issued. The metering point ID is

NOT a customer’s ID because the customer can change and the flat/geographical location does not

Page 5: ENERGY MANAGEMENT INFORMATION SYSTEM Web Service for Remote... · ENERGY MANAGEMENT INFORMATION SYSTEM EMIS Web Service for Remote Readings and Bills ... of EMIS model, IDs of records

EMIS Web Service for Remote Readings and Bills

4

change.

Other synonyms for metering point are also: “meter” and “metering location”.

Each of the above objects must have an identifier that is unique throughout a data supplier domain.

1.2 Remote readings

This is data model for remote readings. Metering points are assigned to your DataSupplier account by EMIS

administrator, so you can send only readings for assigned meters.

Metering Points(defined in EMIS, and assigned to you, not

editable by web service, use this ID’s when sending readings)

Readings

METER_ID

6. Readings – For each metering point, data suppliers can periodically or continuously send remote

readings. Unlike other objects previously described, readings are referring to EMIS Metering Point IDs

(available through end-user GUI), rather than using data-supplier assigned IDs.

Please note that a “metering point” is not the same as a “metering device”! When sending readings you

are referring to metering points. If a metering device is changed, and counter values are reset, new

metering device must be created through EMIS user interface – it is not possible to create new metering

device through web service.

Page 6: ENERGY MANAGEMENT INFORMATION SYSTEM Web Service for Remote... · ENERGY MANAGEMENT INFORMATION SYSTEM EMIS Web Service for Remote Readings and Bills ... of EMIS model, IDs of records

EMIS Web Service for Remote Readings and Bills

5

2 WEB SERVICE DATA EXCHANGE

2.1 Overview

Data from the external applications can be delivered to the EMIS by a REST Web Service. Messages can be in

either XML or JSON format, sent by HTTP protocol to the URL of the web service method. The HTTP message

header should contain a sender’s username and a security MAC (Message Authentication Code) value, calculated

as a hash of the sent data and the secret pre-shared key.

The following data can be exchanged this way:

A) For billing companies that send remote bills:

1. Energy Carrier Vendors

2. Energy Carriers

3. Tariffs

4. Metering Points

5. Bills

B) For companies that manage metering devices, their SCADA systems, and are responsible for sending of

hourly remote readings:

1. Readings

A single batch-message contains lists of data that should be deleted or inserted. After a successful execution a list

of processed objects will be returned (only ID fields will be kept, while others will be omitted), together with the

timestamp. In case of an error, an object with the original fields, together with error code and error description

will be returned.

2.2 Connecting to the REST Web Service

HTTP traffic between a client and the URI of the web service must be allowed. In further text “{SERVICE_URI}”

specifies the base URI of the web service.

The messages can be in either XML or JSON format. Base URI for JSON communication will be specified as

“{SERVICE_URI}/json”, and URI for XML communication will be specified as “{SERVICE_URI}/xml”.

All the messages should be UTF-8 encoded.

2.3 Authentication

The HTTP-Header section of each request must contain the following:

Parameter Description

X-Ekonerg-Login Data-Supplier username

X-Ekonerg-MAC MAC (Message Authentication Code) of the HTTP-Body. Calculated as a SHA-256 digest of the message body combined with a secret pre-shared key, username and method URI (described below)

The MAC must be calculated as follows:

1. Instantiate an SHA-256 digest object and initialize with the following bytes:

(httpMethod + "\n" + methodUri + "\n" + username + "\n" + password).getBytes(Utils.UTF8)

2. Calculate digest of the HTTP body using UTF-8 encoding.

3. Encode the digest result as Base64 and set it as a HTTP-Header parameter named “X-Ekonerg-MAC “

Page 7: ENERGY MANAGEMENT INFORMATION SYSTEM Web Service for Remote... · ENERGY MANAGEMENT INFORMATION SYSTEM EMIS Web Service for Remote Readings and Bills ... of EMIS model, IDs of records

EMIS Web Service for Remote Readings and Bills

6

httpMethod = GET, POST, DELETE, …

methodUri = part of the URI after application base path and without request parameters

o Example: if URI is http://localhost:8080/em-remote-service/sensors/json/readings/sensor/1564564?fromDate=2018-02-06T13:00:00&toDate=2018-02-06T13:30:00

methodUri would be /sensors/json/readings/sensor/1564564

“\n” is chr(10) only (no chr(13) here)

2.3.1 Authentication Example

Method URL: https://www.isge.hr/em-remote-service/batch/json/echo

HTTP method: POST

Username: TEST_USER

Password: superSecRet

Message payload: {"value" : "Äteritsiputeritsipuolilautatsijänkä"}

Create an SHA-256 digest object and feed the following string (UTF-8 encoded bytes):

POST\n/em-remote-service/batch/json/echo\nTEST_USER\nsuperSecRet{"value" :

"Äteritsiputeritsipuolilautatsijänkä"}

NOTES:

\n is LineFeed (decimal code 10);

There is no \n between the password and the message payload.

Now take the digest result and encode it as Base64. The result should be:

eKr7YQPvj8sb0uACfirKKFUaGROA4kyYAmDJOER+tNo=

That is the value you should set as your X-Ekonerg-MAC header value, together with the X-Ekonerg-Login set to

TEST_USER.

2.3.2 Debugging of MAC calculation:

You can use it for ANY web service method (like this one for deleting sensor readings)

Instead of using your own login use X-Ekonerg-Login:“AUTHTUTORIAL” (leave X-Ekonerg-MAC empty, it is

ignored)

Server will return you 401 Unauthorized error, but in errDesc field (in JSON body response) will return you

an example how to calculate MAC for the specific demo user AUTHTUTORIAL, and its demo key.

You can’t do anything with this user because it always fails with Unauthorized exception, but it always

gives you explanation of MAC calculation, and expected value.

2.4 Echo Method

The echo method is used for integration/authentication testing.

2.4.1 Echo Request

Echo Request Properties

Name Type Info Description

value Text Any string The contents of this string will be returned by the service

2.4.2 Echo Response

Echo Response Properties

Page 8: ENERGY MANAGEMENT INFORMATION SYSTEM Web Service for Remote... · ENERGY MANAGEMENT INFORMATION SYSTEM EMIS Web Service for Remote Readings and Bills ... of EMIS model, IDs of records

EMIS Web Service for Remote Readings and Bills

7

Name Type Info Description

status Number HTTP response code Standard HTTP response code

statusDesc Text HTTP response description

Standard HTTP response description

ts Timestamp YYYY-MM-DD’T’HH:mm:ss.SSS

Response timestamp

value Text Any text The same value from the echo request

serviceURL Text HTTP/S link URL of the service (copied from request)

dataSupplierId Text userID User ID

dataSupplierLogin Text userLogin User Login

2.4.3 Examples

Echo Example – Successful0F

1

JSON Request JSON Response POST http://<EMIS-service-url>/batch/json/echo Request Headers: Content-Type: application/json X-Ekonerg-Login: test X-Ekonerg-MAC: 0zsztndLpk9XxuQetmo9uGWTnNtFu7xHjiWPUQ26iFA= Content-Length: 27 Host: <EMIS-service-url> {"value" : "Hello, World!"}

{"status":200,"statusDesc":"OK","ts":"2016-09-30T15:15:31.215","value":"Hello, World!"}

XML Request XML Response POST http://<EMIS-service-url>/batch/xml/echo Request Headers: Content-Type: application/xml X-Ekonerg-Login: test X-Ekonerg-MAC: FZ8NABKpId04g8p07lX3v/edG3+YIXiyvsxMYVSSeoY= Content-Length: 109 Host: <EMIS-service-url> <?xml version='1.0' encoding='utf-8'?> <echo xmlns="http://www.ekonerg.hr/em/bills" value="Hello, World!" />

<response xmlns="http://www.ekonerg.hr/em/bills" status="200" statusDesc="OK" ts="2016-09-30T15:13:22.609" value="Hello, World!"/>

Echo Example – Failed Authentication

JSON Request JSON Response POST http://<EMIS-service-url>/batch/json/echo Request Headers: Content-Type: application/json X-Ekonerg-Login: test X-Ekonerg-MAC: abcd Content-Length: 27 Host: <EMIS-service-url> {"value" : "Hello, World!"}

{"status":401,"statusDesc":"Unauthorized","ts":"2016-09-30T15:26:29.926","err":"AuthorizationException","errDesc":"Invalid MAC"}

XML Request XML Response POST http://<EMIS-service-url>/batch/xml/echo Request Headers: Content-Type: application/xml X-Ekonerg-Login: test X-Ekonerg-MAC: abcd Content-Length: 109 Host: <EMIS-service-url>

<response xmlns="http://www.ekonerg.hr/em/bills" status="401" statusDesc="Unauthorized" ts="2016-09-30T15:29:23.664" err="AuthorizationException" errDesc="Invalid MAC"/>

1 HTTP request headers are written in italic.

Page 9: ENERGY MANAGEMENT INFORMATION SYSTEM Web Service for Remote... · ENERGY MANAGEMENT INFORMATION SYSTEM EMIS Web Service for Remote Readings and Bills ... of EMIS model, IDs of records

EMIS Web Service for Remote Readings and Bills

8

<?xml version='1.0' encoding='utf-8'?> <echo xmlns="http://www.ekonerg.hr/em/bills" value="Hello, World!" />

2.5 Batch Sending Method

This method is used for sending both remote bills and remote readings. It depends of your contract with

customer which set of data will you be sending.

A request contains information about objects that should be added or removed from the system. In order to

minimize overhead, one request can (and should) contain as many objects as possible. I.e., using two consecutive

web-method calls for adding two objects, or adding one and removing another, is strongly discouraged. Since one

request usually contains many objects, we’ll refer to it as “Request Batch” from now on.

Each request contains in the HTTP Header section the appropriate Data Supplier ID and a MAC signature used to

verify the authenticity of the message.

A response contains list of processed objects (just their type and IDs) and a list of failed objects, together with the

error description.

2.5.1 Batch Request Structure

A batch contains the following entries:

1. List of objects for deletion (“delete” for JSON or <delete> for XML)

2. List of Metering Points to unregister (“unregister” for JSON or <unregister> for XML)

3. List of objects for insertion (“insert” for JSON or <insert> for XML)

Each of the lists contains a list of objects (described above), except the “unregister” list that can contain only

objects of type (“meter”).

The entries in the request will always be processed in the order listed above – deletion first, meters unregistering

second, and finally insertion.

Optionally, a batch can also contain the following fields:

“id” - identifier

“ts” – Timestamp in YYYY-MM-DD’T’HH:mm:ss.SSS format

Return batches may also include the following fields:

“err” – Error name (exception class name)

“errDesc” – Error description (detailed description)

The following are the types of available objects contained in the “delete” and/or “insert” list:

“vendor” – Energy carrier vendor

“energyCarrier” – Energy carrier

“energyCarrierField” – Bill field for an energy carrier

“tariff” – Energy carrier tariff

“meter” – Metering point

“bill” – Bill with the corresponding entries contained within

“reading” – Metering point readings

Processing order for deletion will be bottom-up, and the order of inserts will always be top-down.

Structure of the listed objects will be specified in the following chapters.

Page 10: ENERGY MANAGEMENT INFORMATION SYSTEM Web Service for Remote... · ENERGY MANAGEMENT INFORMATION SYSTEM EMIS Web Service for Remote Readings and Bills ... of EMIS model, IDs of records

EMIS Web Service for Remote Readings and Bills

9

2.5.1.1 Inserting vs. Deleting (or Unregistering)

Objects listed for insertion must contain all the required fields, while objects listed for deletion or unregistering

should contain only the bare minimum of fields required for identification (i.e. only the fields that make part of a

primary key).

2.5.2 Batch Response Structure

A response contains two sections, containing a batch with the processed and a batch with the failed objects:

“succeeded” – with the batch containing operations and objects that were successfully processed

(deleted, unregistered or inserted). Each succeeded object will be minimized just to its ID, plus a “ts”

containing the processing timestamp.

“failed” – with the batch containing objects that failed. Objects in this batch will contain all the original

fields, together with the corresponding error description, plus a “ts” containing the processing

timestamp.

After receiving a response, a caller should always check the “failed” section for entries that might have failed,

correct the errors (if any), and retry sending of those entries. Exception to this rule is sending Bills, where you

have to rectify and recreate the whole bill, since in case of an error in single BillData entry, the whole bill will be

rejected, but only the field that caused the error will be returned.

The response also contains serviceURL, dataSupplierId and dataSupplierLogin fields, as described in 2.4.1.2 Echo

Response.

2.5.3 Batch-Contained Objects Structure

The following chapters describe objects contained in a batch.

a) After a successful processing, the service will return a collection of objects, reduced just to their Primary

Key fields, while the others will be omitted

b) In case of a failure, the entire object will be returned, together with the corresponding error description.

In both cases an additional “ts” field will be added, containing the processing timestamp.

NOTE:

When inserting an object, all the mandatory fields must be present.

When deleting an object, or unregistering a Meter, only the Primary Key field(s) must be present.

2.5.3.1 Sending of remote bills

2.5.3.1.1 Object “vendor”

Vendor Properties

Name Type Info Description

id Text Primary Key, Mandatory

Data Supplier’s Vendor ID

name Text Mandatory Vendor name

ignoreExisting Boolean Optional (“true” or “false”, omitted -> “false”)

If true, no exception will be thrown when inserting an entry with the same ID, so the new entry will be ignored, and the existing entry WILL NOT BE UPDATED! An existing entry can not be chaned in any way.

Page 11: ENERGY MANAGEMENT INFORMATION SYSTEM Web Service for Remote... · ENERGY MANAGEMENT INFORMATION SYSTEM EMIS Web Service for Remote Readings and Bills ... of EMIS model, IDs of records

EMIS Web Service for Remote Readings and Bills

10

Vendor Example (Fragment)

JSON XML { "id" : "AP", "name" : "Austin Powers Ltd." }

<vendor id="AP" name="Austin Powers Ltd."/>

2.5.3.1.2 Object “energyCarrier”

Energy Carrier Properties

Name Type Info Description

id Text Primary Key, Mandatory

Data Supplier’s Energy Carrier ID

name Text Mandatory Energy Carrier name

ignoreExisting Boolean Optional (“true” or “false”, omitted -> “false”)

If true, no exception will be thrown when inserting an entry with the same ID, so the new entry will be ignored, and the existing entry WILL NOT BE UPDATED! An existing entry can not be chaned in any way.

Energy Carrier Example (Fragment)

JSON XML { "id" : "MOJO", "name" : "Mojo Energy" }

<energyCarrier id="MOJO" name="Mojo Energy"/>

2.5.3.1.3 Object “energyCarrierField”

Energy Carrier Field Properties

Name Type Info Description

id Text Primary Key, Mandatory

Data Supplier’s Bill Field ID

energyCarrierId Text Primary Key, Mandatory

Data Supplier’s Energy Carrier ID

name Text Mandatory Bill item name with unit of measure

consumption Boolean Optional (omitted -> false)

Allowed values are “true” (for bill items representing consumption) and “false”.

ignoreExisting Boolean Optional (“true” or “false”, omitted -> “false”)

If true, no exception will be thrown when inserting an entry with the same ID, so the new entry will be ignored, and the existing entry WILL NOT BE UPDATED! An existing entry can not be chaned in any way.

Energy Carrier Field Example (Fragment)

JSON XML { "id" : "HOT", "energyCarrierId" : "MOJO", "name" : "Hot Mojo" }

<energyCarrierField id="HOT" energyCarrierId="MOJO" name="Hot Mojo"/>

Page 12: ENERGY MANAGEMENT INFORMATION SYSTEM Web Service for Remote... · ENERGY MANAGEMENT INFORMATION SYSTEM EMIS Web Service for Remote Readings and Bills ... of EMIS model, IDs of records

EMIS Web Service for Remote Readings and Bills

11

2.5.3.1.4 Object “tariff”

Tariff Properties

Name Type Info Description

id Text Primary Key, Mandatory

Data Supplier’s Tariff ID

energyCarrierId Text Mandatory Data Supplier’s Energy Carrier ID

vendorId Text Mandatory Data Supplier’s Vendor ID

name Text Mandatory Tariff name

ignoreExisting Boolean Optional (“true” or “false”, omitted -> “false”)

If true, no exception will be thrown when inserting an entry with the same ID, so the new entry will be ignored, and the existing entry WILL NOT BE UPDATED! An existing entry can not be chaned in any way.

Tariff Example (Fragment)

JSON XML { "id":"MOJO_MAIN", "energyCarrierId":"MOJO", "vendorId":"AP", "name":"Main Mojo Tariffa" }

<tariff id="MOJO_MAIN" energyCarrierId="MOJO" vendorId="AP" name="Main Mojo Tariff"/>

2.5.3.1.5 Object “meter”

Meter Properties

Name Type Info Description

id Text Primary Key, Mandatory Data Supplier’s Metering point ID

serialNumber Text Mandatory, Updateable Meter serial number

description Text Optional, Updateable Meter description

address Complex Optional, Updateable Meter address

buildingName Text Optional, Updateable Facility name

ownerName Text Optional, Updateable Owner name

ownerExternalId Text Optional, Updateable Owner’s Tax ID (OIB)

energyCarrierId Text Mandatory Data Supplier’s Energy Carrier ID

unregisterDate Date YYYY-MM-DD Only for unregistering

Date since DataSupplier is no longer obliged to send bills for a metering point because the contract with the user of this metering point expired.

unregisterComment Text Only for unregistering Comment (e.g. number of contract, or name of new vendor)

When registering a meter with ID that is already registered, the system will update data and will NOT raise a

primary key exception, and it will update the following fields: serialNumber, description, address (address, city,

zip), buildingName, ownerName, and ownerExternalId. Field energyCarrierId is not updateable. Fields

unregisterDate and unregisterComment are ignored when registering a meter!

Unregistering a meter serves to mark that DataSupplier is no longer obliged to send bills for a metering point

because the contract with the user of this metering point expired.

Note: This doesn’t prevent DataSupplier from still sending bills for any reason, but it serves as information to

users of EMIS system that vendor has been changed.

Page 13: ENERGY MANAGEMENT INFORMATION SYSTEM Web Service for Remote... · ENERGY MANAGEMENT INFORMATION SYSTEM EMIS Web Service for Remote Readings and Bills ... of EMIS model, IDs of records

EMIS Web Service for Remote Readings and Bills

12

To unregister a meter see chapter 2.5.1 (Batch Request Structure), and send only fields id, unregisterDate and

unregisterComment.

Address Properties

Name Type Info Description

address Text Optional Street name with house number

city Text Optional City name

zip Text Optional Zip code

Meter Example (Fragment)

JSON XML { "id" : "METER1", "serialNumber" : "M-1-SER", "description" : "Mojo Meter One ", "address" : { "address" : "Elm Street 1", "city" : "London", "zip" : "WC2N" }, "buildingName" : "Headquarters", "ownerName" : "Dr. Evil", "energyCarrierId" : "MOJO" }

<meter id="METER1" serialNumber="M-1-SER" description="Mojo Meter One" buildingName="Headquarters" ownerName="Dr. Evil" energyCarrierId="MOJO> <address address="Elm Street 1" city="London" zip="WC2N"/> </meter>

2.5.3.1.6 Object “bill”

Bill with its contained BillData entries are processed in a transaction, meaning that if a single BillData entry is

invalid, the entire Bill will be rejected, and all the previous BillData entries (if any) contained in that Bill will be

ignored. In that case, the service response will contain in its “failed” section the corresponding “bill” object with

all its original attributes, containing only the first BillData element that failed, together with the error description.

Bill Properties

Name Type Info Description

id Text Primary Key, Mandatory

Data Supplier’s Bill ID

serialNumber Text Mandatory Serial number printed on the bill

total Decimal Optional Total amount of bill with VAT. Used for accuracy check of all entered items.

month Number Optional Month for which the bill is issued

year Number Optional Year for which the bill is issued

billData List of Complex “BillData”

Optional Bill entries

BillData Properties

Name Type Info Description

energyCarrierId Text UK* Data Supplier’s Energy Carrier ID

meterId Text UK* Meter ID

Page 14: ENERGY MANAGEMENT INFORMATION SYSTEM Web Service for Remote... · ENERGY MANAGEMENT INFORMATION SYSTEM EMIS Web Service for Remote Readings and Bills ... of EMIS model, IDs of records

EMIS Web Service for Remote Readings and Bills

13

vendorId Text UK* Vendor ID

tariffID Text UK* Tariff/group of bills ID

dateFrom Date UK*, Mandatory Date from

dateTo Date UK*, Mandatory Date until

energyCarrierFieldId Text UK*, Mandatory Energy Carrier Field ID

quantity Decimal Mandatory Amount

unitCost Decimal Mandatory Unit price

taxPercentage Decimal Mandatory Tax rate (%)

* Fields marked with UK must be unique. It means that on the same bill one item can appear only once on a metering point from the same

vendor in a specific from-to period, for a specific tariff. Null (empty) fields are also included in uniqueness check. This limitations has been

added due to the fact to prevent double sending of the same item of the bill and the aim is to make it flexible enough to function in

different scenarios. If meterId is not null, then also vendorId, tariffId and energyCarrierId must be not null.

Bill Example (Fragment)

JSON XML { "id" : "INT-0002", "serialNumber" : "AP-2016-0002", "total" : 1234.56, "month" : 1, "year" : 2016, "billData" : [{ "energyCarrierId" : "MOJO", "meterId" : "METER1", "vendorId" : "AP", "tariffId" : "MOJO_MAIN", "dateFrom" : "2016-01-01", "dateTo" : "2016-02-01", "energyCarrierFieldId" : "HOT", "quantity" : 10.0, "unitCost" : 123.0, "taxPercentage" : 25.0, }, { "energyCarrierId" : "MOJO", "meterId" : "METER2", "vendorId" : "AP", "tariffId" : "MOJO_MAIN", "dateFrom" : "2016-01-01", "dateTo" : "2016-01-02", "energyCarrierFieldId" : "COOL", "quantity" : 100.0, "unitCost" : 95.0, "taxPercentage" : 25.0, } ] }

<bill id="INT-0002" serialNumber="AP-2016-0002" total="1234.56" month="1" year="2016" > <billData energyCarrierId="MOJO" meterId="METER1" vendorId="AP" tariffId="MOJO_MAIN" dateFrom="2016-01-01" dateTo="2016-02-01" vendorId="AP" energyCarrierFieldId="HOT" quantity="10.0" unitCost="123.0" taxPercentage="25.0"/> <billData energyCarrierId="MOJO" meterId="METER2" vendorId="AP" tariffId="MOJO_MAIN" dateFrom="2016-01-01" dateTo="2016-02-01" vendorId="AP" energyCarrierFieldId="COOL" quantity="100.0" unitCost="95.0" taxPercentage="25.0"/> </bill>

Bill Example – Successful (complete)

JSON Request JSON Response POST http://<EMIS-service-url>/batch/json/send Request Headers: Content-Type: application/json X-Ekonerg-Login: test X-Ekonerg-MAC: yoHi5qZsqfPM0pkmKiudSIIsXTVFaYT/cdsZ/ZK0S2I= Content-Length: 886 Host: <EMIS-service-url> { "insert" : { "bills" : [{ "id" : "INT-0001", "serialNumber" : "AP-2015-0001", "total" : 1234.56, "month" : 1, "year" : 2015, "billData" : [{ "energyCarrierId" : "MOJO", "meterId" : "METER1",

{ "status" : 200, "statusDesc" : "OK", "ts" : "2016-09-14T10:34:13.296", "serviceURL" : "http://<EMIS-service-url>/batch/json/send ", "succeeded" : { "ts" : "2016-09-14T10:34:13.308", "insert" : { "bills" : [{ "id" : "INT-0001", "ts" : "2016-09-14T10:34:13.308" } ] } } "dataSupplierId" : "test" "dataSupplierLogin" : "test" }

Page 15: ENERGY MANAGEMENT INFORMATION SYSTEM Web Service for Remote... · ENERGY MANAGEMENT INFORMATION SYSTEM EMIS Web Service for Remote Readings and Bills ... of EMIS model, IDs of records

EMIS Web Service for Remote Readings and Bills

14

"vendorId" : "AP", "tariffId" : "MOJO_MAIN", "dateFrom" : "2015-01-01", "dateTo" : "2015-02-01", "energyCarrierFieldId" : "HOT", "quantity" : 10.0, "unitCost" : 123.0, "taxPercentage" : 25.0 }, { "energyCarrierId" : "MOJO", "meterId" : "METER2", "vendorId" : "AP", "tariffId" : "MOJO_MAIN", "dateFrom" : "2015-01-01", "dateTo" : "2015-01-01", "energyCarrierFieldId" : "COOL", "quantity" : 100.0, "unitCost" : 95.0, "taxPercentage" : 25.0 } ] } ] } }

XML Request XML Response POST http://<EMIS-service-url>/batch/xml/send Request Headers: Content-Type: application/xml X-Ekonerg-Login: test X-Ekonerg-MAC: yoHi5qZsqfPM0pkmKiudSIIsXTVFaYT/cdsZ/ZK0S2I= Content-Length: 736 Host: <EMIS-service-url> <?xml version='1.0' encoding='UTF-8'?> <batch xmlns="http://www.ekonerg.hr/em/bills" ts="2016-09-14T12:15:20.224"> <insert> <bill id="INT-0001" serialNumber="AP-2015-0001" year="2015" month="1" total="1234.56"> <billData energyCarrierId="MOJO" meterId="METER1" vendorId="AP" tariffId="MOJO_MAIN" dateFrom="2015-01-01" dateTo="2015-02-01" energyCarrierFieldId="HOT" quantity="10.0" unitCost="123.0" taxPercentage="25.0"/> <billData energyCarrierId="MOJO" meterId="METER2" vendorId="AP" tariffId="MOJO_MAIN" dateFrom="2015-01-01" dateTo="2015-02-01" energyCarrierFieldId="COOL" quantity="100.0" unitCost="95.0" taxPercentage="25.0"/> </bill> </insert> </batch>

<response xmlns="http://www.ekonerg.hr/em/bills" status="200" statusDesc="OK" ts="2016-09-14T12:18:10.358" serviceURL="http://<EMIS-service-url>/batch/xml/send " dataSupplierId="test" dataSupplierLogin="test"> <succeeded ts="2016-09-14T12:18:10.373"> <insert> <bill id="INT-0001" ts="2016-09-14T12:18:10.373"/> </insert> </succeeded> </response>

Page 16: ENERGY MANAGEMENT INFORMATION SYSTEM Web Service for Remote... · ENERGY MANAGEMENT INFORMATION SYSTEM EMIS Web Service for Remote Readings and Bills ... of EMIS model, IDs of records

EMIS Web Service for Remote Readings and Bills

15

In the following example, an unknown meterId is being delivered in the second entry of the BillData list. The

service returns a “failed” list containing a partial copy of the original batch only one BillData entry – the one that

was invalid. The “err” and “errDesc” fields contain details about the error, and are contained in both BillData

entry and the Bill object. As a result of the operation, the entire Bill is rejected.

Bill Example – Failed (complete)

JSON Request JSON Response POST http://<EMIS-service-url>/batch/json/send Request Headers: Connection: keep-alive Content-Type: application/json X-Ekonerg-Login: test X-Ekonerg-MAC: yoHi5qZsqfPM0pkmKiudSIIsXTVFaYT/cdsZ/ZK0S2I= Content-Length: 887 Host: <EMIS-service-url> User-Agent: Apache-HttpClient/4.2.6 (java 1.5) { "insert" : { "bills" : [{ "id" : "INT-0001", "serialNumber" : "AP-2015-0001", "total" : 1234.56, "month" : 1, "year" : 2015, "billData" : [{ "energyCarrierId" : "MOJO", "meterId" : "METER1", "vendorId" : "AP", "tariffId" : "MOJO_MAIN", "dateFrom" : "2015-01-01", "dateTo" : "2015-02-01", "energyCarrierFieldId" : "HOT", "quantity" : 10.0, "unitCost" : 123.0, "taxPercentage" : 25.0 }, { "energyCarrierId" : "MOJO", "meterId" : "METER2x", "vendorId" : "AP", "tariffId" : "MOJO_MAIN", "dateFrom" : "2015-01-01", "dateTo" : "2015-02-01", "energyCarrierFieldId" : "COOL", "quantity" : 100.0, "unitCost" : 95.0, "taxPercentage" : 25.0 } ] } ] } }

{ "status" : 200, "statusDesc" : "OK", "ts" : "2016-09-14T12:21:08.403", "failed" : { "ts" : "2016-09-14T12:21:08.420", "serviceURL" : "http://<EMIS-service-url>/batch/json/send ", "insert" : { "bills" : [{ "id" : "INT-0001", "serialNumber" : "AP-2015-0001", "year" : 2015, "month" : 1, "billData" : [{ "ts" : "2016-09-14T12:21:08.419", "err" : "ForeignKeyException", "errDesc" : "PreparedStatementCallback; SQL [call REMOTEBILLS_BACK.BILL_SEND_FIELD(?,?,?,?,?,?,?,?,?,?,?,?,?)]; ORA-02291: integrity constraint (EMIS.TREMOTE_ADV_BILLDATA_MTR_FK) violated - parent key not found\nORA-06512: at \"EMIS.REMOTEBILLS_BACK\", line 298\n; nested exception is java.sql.SQLIntegrityConstraintViolationException: ORA-02291: integrity constraint (EMIS.TREMOTE_ADV_BILLDATA_MTR_FK) violated - parent key not found\nORA-06512: at \"EMIS.REMOTEBILLS_BACK\", line 298\n", "energyCarrierId" : "MOJO", "meterId" : "METER2x", "vendorId" : "AP", "tariffId" : "MOJO_MAIN", "dateFrom" : "2015-01-01", "dateTo" : "2015-02-01", "energyCarrierFieldId" : "COOL", "quantity" : 100.0, "unitCost" : 95.0, "taxPercentage" : 25.0 } ], "err" : "ForeignKeyException", "errDesc" : "PreparedStatementCallback; SQL [call REMOTEBILLS_BACK.BILL_SEND_FIELD(?,?,?,?,?,?,?,?,?,?,?,?,?)]; ORA-02291: integrity constraint (EMIS.TREMOTE_ADV_BILLDATA_MTR_FK) violated - parent key not found\nORA-06512: at \"EMIS.REMOTEBILLS_BACK\", line 298\n; nested exception is java.sql.SQLIntegrityConstraintViolationException: ORA-02291: integrity constraint (EMIS.TREMOTE_ADV_BILLDATA_MTR_FK) violated - parent key not found\nORA-06512: at \"EMIS.REMOTEBILLS_BACK\", line 298\n", "total" : 1234.56, "ts" : "2016-09-14T12:21:08.420" } ] } } "dataSupplierId" : "test" "dataSupplierLogin" : "test" }

XML Request XML Response POST http://<EMIS-service-url>/batch/xml/send Request Headers: Connection: keep-alive Content-Type: application/xml X-Ekonerg-Login: test X-Ekonerg-MAC: yoHi5qZsqfPM0pkmKiudSIIsXTVFaYT/cdsZ/ZK0S2I= Content-Length: 737 Host: <EMIS-service-url> User-Agent: Apache-HttpClient/4.2.6 (java 1.5) <?xml version='1.0' encoding='UTF-8'?> <batch xmlns="http://www.ekonerg.hr/em/bills" ts="2016-09-14T12:15:20.224"> <insert> <bill id="INT-0001" serialNumber="AP-2015-0001" year="2015" month="1" total="1234.56">

<response xmlns="http://www.ekonerg.hr/em/bills" status="200" statusDesc="OK" ts="2016-09-14T12:28:55.396" serviceURL="http://<EMIS-service-url>/batch/xml/send " dataSupplierId="test" dataSupplierLogin="test"> <failed ts="2016-09-14T12:28:55.403"> <insert> <bill id="INT-0001" serialNumber="AP-2015-0001" year="2015" month="1" err="ForeignKeyException" errDesc="PreparedStatementCallback; SQL [call REMOTEBILLS_BACK.BILL_SEND_FIELD(?,?,?,?,?,?,?,?,?,?,?,?,?)]; ORA-02291: integrity constraint (EMIS.TREMOTE_ADV_BILLDATA_MTR_FK) violated - parent key not found&#xa;ORA-06512: at &quot;EMIS.REMOTEBILLS_BACK&quot;, line 298&#xa;; nested exception is java.sql.SQLIntegrityConstraintViolationException: ORA-02291: integrity constraint (EMIS.TREMOTE_ADV_BILLDATA_MTR_FK) violated - parent key not found&#xa;ORA-06512: at &quot;EMIS.REMOTEBILLS_BACK&quot;, line 298&#xa;" total="1234.56" ts="2016-09-14T12:28:55.403"> <billData ts="2016-09-14T12:28:55.402" err="ForeignKeyException" errDesc="PreparedStatementCallback; SQL [call REMOTEBILLS_BACK.BILL_SEND_FIELD(?,?,?,?,?,?,?,?,?,?,?,?,?)]; ORA-02291: integrity

Page 17: ENERGY MANAGEMENT INFORMATION SYSTEM Web Service for Remote... · ENERGY MANAGEMENT INFORMATION SYSTEM EMIS Web Service for Remote Readings and Bills ... of EMIS model, IDs of records

EMIS Web Service for Remote Readings and Bills

16

<billData energyCarrierId="MOJO" meterId="METER1" vendorId="AP" tariffId="MOJO_MAIN" dateFrom="2015-01-01" dateTo="2015-02-01" energyCarrierFieldId="HOT" quantity="10.0" unitCost="123.0" taxPercentage="25.0"/> <billData energyCarrierId="MOJO" meterId="METER2x" vendorId="AP" tariffId="MOJO_MAIN" dateFrom="2015-01-01" dateTo="2015-02-01" energyCarrierFieldId="COOL" quantity="100.0" unitCost="95.0" taxPercentage="25.0"/> </bill> </insert> </batch>

constraint (EMIS.TREMOTE_ADV_BILLDATA_MTR_FK) violated - parent key not found&#xa;ORA-06512: at &quot;EMIS.REMOTEBILLS_BACK&quot;, line 298&#xa;; nested exception is java.sql.SQLIntegrityConstraintViolationException: ORA-02291: integrity constraint (EMIS.TREMOTE_ADV_BILLDATA_MTR_FK) violated - parent key not found&#xa;ORA-06512: at &quot;EMIS.REMOTEBILLS_BACK&quot;, line 298&#xa;" energyCarrierId="MOJO" meterId="METER2x" vendorId="AP" tariffId="MOJO_MAIN" dateFrom="2015-01-01" dateTo="2015-02-01" energyCarrierFieldId="COOL" quantity="100.0" unitCost="95.0" taxPercentage="25.0"/> </bill> </insert> </failed> </response>

2.5.3.2 Sending of Remote Readings

Readings are referenced to internal EMIS identifier of a related meter – not the data supplier meter identifier.

These identifier values will be specified in a contract with each data supplier, but assigned meter IDs can also be

retrieved as described in chapter 5. DataSupplier Web Interface, and chapter 2.6. Query Methods for Remote

Readings.

When sending readings all monitored counter values have to be sent.

Important: When sending an already existing reading, the system will throw an exception. It is expected from

data supplier to track which data has already been sent. In case of sending changes to readings, you must first

delete the existing readings and then send new ones.

2.5.3.2.1 Object “reading”

The following sections describes format of remote readings.

Reading Properties

Name Type Info Description

meterId Text UK, Mandatory, Foreign key

EMIS Meter ID

date DateTime UK, Mandatory Reading date

dateTo DateTime Optional Used only to delete a time-range of readings. You can delete all readings of a given meterId by specifying start and end date (date and dateTo fields). In that case, you must specify only:

meterId – meter whose readings are to be deleted

date – readings start date-time

dateTo – readings end date-time (inclusive!)

c1 Decimal Optional Counter 1 value

c2 Decimal Optional Counter 2 value

c3 Decimal Optional Counter 3 value

c4 Decimal Optional Counter 4 value

c5 Decimal Optional Counter 5 value

tempIn Decimal Optional Inside temperature in °C

tempOut Decimal Optional Outside temperature in °C

people Number Optional Number of occupants

internalId Text UK, Optional Internal Data Supplier’s reading ID

id Text Return value Record ID in EMIS database

NOTE: If a request contains the “internalId” value, then “meterId” and “date” will be removed from the response

after a successful operation. If the “internalId” is omitted, then these two values will be kept in the confirmation

response.

Page 18: ENERGY MANAGEMENT INFORMATION SYSTEM Web Service for Remote... · ENERGY MANAGEMENT INFORMATION SYSTEM EMIS Web Service for Remote Readings and Bills ... of EMIS model, IDs of records

EMIS Web Service for Remote Readings and Bills

17

Reading Example (successful)

JSON Request JSON Response POST http://<EMIS-service-url>/batch/json/send Request Headers: Connection: keep-alive Content-Type: application/json X-Ekonerg-Login: ARSEN X-Ekonerg-MAC: SJdtDN3ZiY5AUl5ub74CR2GntrdJg1p7F1UKcQ2ktu8= Content-Length: 260 Host: <EMIS-service-url> User-Agent: Apache-HttpClient/4.2.6 (java 1.5) { "insert" : { "readings" : [{ "meterId" : "2186653", "date" : "2016-01-15T02:02:00", "c1" : "209002", "internalId" : "19625" }, { "meterId" : "2186653", "date" : "2016-01-15T02:03:00", "c1" : "209003" } ] } }

{ "status" : 200, "statusDesc" : "OK", "ts" : "2016-09-14T14:42:00.601", "serviceURL" : "http://<EMIS-service-url>/batch/json/send ", "succeeded" : { "ts" : "2016-09-14T14:42:00.675", "insert" : { "readings" : [{ "ts" : "2016-09-14T14:42:00.649", "id" : "200271268", "internalId" : "19625" }, { "ts" : "2016-09-14T14:42:00.674", "id" : "200271269", "meterId" : "2186653", "date" : "2016-01-15T02:03:00" } ] } } "dataSupplierId" : "test" "dataSupplierLogin" : "test" }

XML Request XML Response POST http://<EMIS-service-url>/batch/xml/send Request Headers: Connection: keep-alive Content-Type: application/xml X-Ekonerg-Login: ARSEN X-Ekonerg-MAC: SJdtDN3ZiY5AUl5ub74CR2GntrdJg1p7F1UKcQ2ktu8= Content-Length: 315 Host: <EMIS-service-url> User-Agent: Apache-HttpClient/4.2.6 (java 1.5) <?xml version='1.0' encoding='UTF-8'?> <batch xmlns="http://www.ekonerg.hr/em/bills" ts="2016-09-14T14:42:00.558"> <insert> <reading meterId="2186653" date="2016-01-15T02:02:00" c1="209002.0" internalId="19625"/> <reading meterId="2186653" date="2016-01-15T02:03:00" c1="209003.0"/> </insert> </batch>

<response xmlns="http://www.ekonerg.hr/em/bills" status="200" statusDesc="OK" ts="2016-09-14T14:42:00.601" serviceURL="http://<EMIS-service-url>/batch/xml/send " dataSupplierId="test" dataSupplierLogin="test"> <succeeded ts="2016-09-14T14:42:00.675"> <insert> <reading ts="2016-09-14T14:42:00.649" id="200271268" internalId="19625"/> <reading ts="2016-09-14T14:42:00.674" id="200271269" meterId="2186653" date="2016-01-15T02:03:00"/> </insert> </succeeded> </response>

Reading Example (partially successful)

JSON Request JSON Response POST http://<EMIS-service-url>/batch/json/send Request Headers: Connection: keep-alive Content-Type: application/json X-Ekonerg-Login: ARSEN X-Ekonerg-MAC: SJdtDN3ZiY5AUl5ub74CR2GntrdJg1p7F1UKcQ2ktu8= Content-Length: 260 Host: <EMIS-service-url> User-Agent: Apache-HttpClient/4.2.6 (java 1.5) { "insert" : { "readings" : [{ "meterId" : "2186653", "date" : "2016-01-15T02:04:00", "c1" : "209004", "internalId" : "19631" }, { "meterId" : "2186653",

{ "status" : 200, "statusDesc" : "OK", "ts" : "2016-09-14T14:54:23.123", "serviceURL" : "http://<EMIS-service-url>/batch/json/send ", "succeeded" : { "ts" : "2016-09-14T14:54:23.285", "insert" : { "readings" : [{ "ts" : "2016-09-14T14:54:23.165", "id" : "200271270", "internalId" : "19631" } ] } }, "failed" : { "ts" : "2016-09-14T14:54:23.285", "insert" : { "readings" : [{ "ts" : "2016-09-14T14:54:23.283",

Page 19: ENERGY MANAGEMENT INFORMATION SYSTEM Web Service for Remote... · ENERGY MANAGEMENT INFORMATION SYSTEM EMIS Web Service for Remote Readings and Bills ... of EMIS model, IDs of records

EMIS Web Service for Remote Readings and Bills

18

"date" : "2016-01-15T02:03:00", "c1" : "209005" } ] } }

"err" : "BusinessException", "errDesc" : "ERR-20243:ORA-20243: READING_LARGER_THAN_NEXT - Reading on one of the counters is larger then one next reading. This is not allowed for cummulative meters. Next counters: c1:209004/c2:/c3:/c4:/c5: Param1:2186653\nORA-06512: at \"EMIS.REMOTE\", line 60\nORA-06512: at \"EMIS.REMOTE\", line 392\nORA-06512: at line 1\n", "meterId" : "2186653", "date" : "2016-01-15T02:03:00", "c1" : 209005.0 } ] } } "dataSupplierId" : "test" "dataSupplierLogin" : "test" }

XML Request XML Response POST http://<EMIS-service-url>/batch/xml/send Request Headers: Connection: keep-alive Content-Type: application/xml X-Ekonerg-Login: ARSEN X-Ekonerg-MAC: SJdtDN3ZiY5AUl5ub74CR2GntrdJg1p7F1UKcQ2ktu8= Content-Length: 315 Host: <EMIS-service-url> User-Agent: Apache-HttpClient/4.2.6 (java 1.5) <?xml version='1.0' encoding='UTF-8'?> <batch xmlns="http://www.ekonerg.hr/em/bills" ts="2016-09-14T14:54:23.113"> <insert> <reading meterId="2186653" date="2016-01-15T02:04:00" c1="209004.0" internalId="19631"/> <reading meterId="2186653" date="2016-01-15T02:03:00" c1="209005.0"/> </insert> </batch>

<response xmlns="http://www.ekonerg.hr/em/bills" status="200" statusDesc="OK" ts="2016-09-14T14:54:23.123" serviceURL="http://<EMIS-service-url>/batch/xml/send " dataSupplierId="test" dataSupplierLogin="test"> <succeeded ts="2016-09-14T14:54:23.285"> <insert> <reading ts="2016-09-14T14:54:23.165" id="200271270" internalId="19631"/> </insert> </succeeded> <failed ts="2016-09-14T14:54:23.285"> <insert> <reading ts="2016-09-14T14:54:23.283" err="BusinessException" errDesc="ERR-20243:ORA-20243: READING_LARGER_THAN_NEXT - Reading on one of the counters is larger then one next reading. This is not allowed for cummulative meters. Next counters: c1:209004/c2:/c3:/c4:/c5: Param1:2186653&#xa;ORA-06512: at &quot;EMIS.REMOTE&quot;, line 60&#xa;ORA-06512: at &quot;EMIS.REMOTE&quot;, line 392&#xa;ORA-06512: at line 1&#xa;" meterId="2186653" date="2016-01-15T02:03:00" c1="209005.0"/> </insert> </failed> </response>

2.5.3.2.2 Mass deleting of readings

All the readings of a specified meterId in a given period can be deleted by sending a batch with one or more

“reading” objects in a “delete” section.

Each “reading” entry must contain the following properties:

Reading Properties (for deleting)

Name Type Info Description

meterId Text UK, Mandatory, Foreign key

EMIS Meter ID

date DateTime UK, Mandatory Reading date

dateTo DateTime Optional Used only to delete a time-range of readings. You can delete all readings of a given meterId by specifying start and end date (date and dateTo fields). In that case, you must specify only:

meterId – meter whose readings are to be deleted

date – readings start date-time

dateTo – readings end date-time (inclusive!)

For each reading “range” entry, the service returns a number of readings that were actually deleted.

Reading Interval Delete Example (successful)

JSON Request JSON Response POST http://<EMIS-service-url>/batch/json/send Request Headers: Connection: keep-alive Content-Type: application/json

{ "status" : 200, "statusDesc" : "OK", "ts" : "2016-09-14T14:42:00.601", "serviceURL" : "http://<EMIS-service-url>/batch/json/send ",

Page 20: ENERGY MANAGEMENT INFORMATION SYSTEM Web Service for Remote... · ENERGY MANAGEMENT INFORMATION SYSTEM EMIS Web Service for Remote Readings and Bills ... of EMIS model, IDs of records

EMIS Web Service for Remote Readings and Bills

19

X-Ekonerg-Login: ARSEN X-Ekonerg-MAC: SJdtDN3ZiY5AUl5ub74CR2GntrdJg1p7F1UKcQ2ktu8= Content-Length: 260 Host: <EMIS-service-url> User-Agent: Apache-HttpClient/4.2.6 (java 1.5) { "delete" : { "readings" : [{ "meterId" : "2186653", "date" : "2016-01-15T02:02:00", "dateTo" : "2016-01-29T23:59:59", } ] } }

"succeeded": { "ts": "2016-09-14T14:42:00.655", "delete": { "readings": [{ "ts": "2016-09-14T14:42:00.652", "processedEntries": 6, "meterId": "2186653", "date": "2016-01-15T02:02:00", "dateTo": "2016-01-29T23:59:59" } ], "count": 1 } }, "dataSupplierId" : "test" "dataSupplierLogin" : "test" }

XML Request XML Response POST http://<EMIS-service-url>/batch/xml/send Request Headers: Connection: keep-alive Content-Type: application/xml X-Ekonerg-Login: ARSEN X-Ekonerg-MAC: SJdtDN3ZiY5AUl5ub74CR2GntrdJg1p7F1UKcQ2ktu8= Content-Length: 315 Host: <EMIS-service-url> User-Agent: Apache-HttpClient/4.2.6 (java 1.5) <?xml version='1.0' encoding='UTF-8'?> <batch xmlns="http://www.ekonerg.hr/em/bills" ts="2016-09-14T14:42:00.558"> <delete> <reading meterId="2186653" date="2016-01-15T02:02:00" dateTo="2016-01-29T23:59:59"/> </delete> </batch>

<response xmlns="http://www.ekonerg.hr/em/bills" status="200" statusDesc="OK" ts="2016-09-14T14:42:00.601" serviceURL="http://<EMIS-service-url>/batch/xml/send " dataSupplierId="test" dataSupplierLogin="test"> <succeeded ts="2016-09-14T14:42:00.655"> <delete> <reading ts="2016-09-14T14:42:00.652" processedEntries="6" meterId="2186653" date="2016-01-15T00:00:00" dateTo="2016-01-15T23:59:59"/> </delete> </succeeded> </response>

2.6 Query Methods for Remote Readings

The following methods are used for querying Meters and Readings that a data supplier has sent.

All meters include “Counters” object which contains a list of counters which are enabled on a meter.

2.6.1 Meters Query

This method is used for getting a list of all the meters that a data supplier previously sent.

It is a REST GET method with no parameters. It comes in JSON and XML flavors.

2.6.1.1 Meters Query Request

Meters Request Properties <EMIS-service-url>/query/[xml|json]/meters

Name Type Info Description

- - - No parameters are required, except for the MAC authorization in HTTP header.

2.6.1.2 Meters Query Response

Meters Response Properties

Name Type Info Description

status Number HTTP response code Standard HTTP response code

statusDesc Text HTTP response description

Standard HTTP response description

Page 21: ENERGY MANAGEMENT INFORMATION SYSTEM Web Service for Remote... · ENERGY MANAGEMENT INFORMATION SYSTEM EMIS Web Service for Remote Readings and Bills ... of EMIS model, IDs of records

EMIS Web Service for Remote Readings and Bills

20

ts Timestamp YYYY-MM-DD’T’HH:mm:ss.SSS

Response timestamp

serviceURL Text HTTP/S link URL of the service (copied from request)

dataSupplierId Text userID User ID

dataSupplierLogin Text userLogin User Login

meters List List of objects List of Meter objects

meter (zero or more entries)

meterId Long Primary key EMIS meter ID

meterSerialNumber Text Meter serial number

meterShortDescription Text Short description of the meter

meterDescription Text Additonal comment

objectName Text Object name

emisCode Text EMIS code of the object

energent Text Energy carrier name

energentId Text Foreign key – Energent Energy carrier ID

counters Array See “Counters” object List of counters on meter

Counters Object

Name Type Info Description

counter Number Counter number

name Text Counter name and UOM

2.6.1.3 Examples

Meters Request Example

JSON Request JSON Response GET http://localhost:8080/em-remote-service/query/json/meters Request Headers: Content-Type: application/json X-Ekonerg-Login: test X-Ekonerg-MAC: 0zsztndLpk9XxuQetmo9uGWTnNtFu7xHjiWPUQ26iFA= Host: localhost:8080

{ "status": 200, "statusDesc": "OK", "ts": "2017-11-23T14:29:55.687", "meters": [{ "meterId": 1122976, "meterSerialNumber": "NN1122334455", "meterShortDescription": null, "meterDescription": null, "objectName": "Gradski kotar Sirobuja", "isgeCode": "HR-21000-0122-1", "energent": "Električna energija", "energentId": "Electricity", "counters": [{ "counter": 1, "name": "RVT [kWh]" } ] }, { "meterId": 1122982, "meterSerialNumber": "NNxxxxxx", "meterShortDescription": null, "meterDescription": null, "objectName": "Osnovna Škola Miroslava krleže Čepin", "isgeCode": "HR-31431-0007-1", "energent": "Električna energija", "energentId": "Electricity", "counters": [{ "counter": 1, "name": "RVT [kWh]" }, { "counter": 2, "name": "RNT [kWh]" }, ]

Page 22: ENERGY MANAGEMENT INFORMATION SYSTEM Web Service for Remote... · ENERGY MANAGEMENT INFORMATION SYSTEM EMIS Web Service for Remote Readings and Bills ... of EMIS model, IDs of records

EMIS Web Service for Remote Readings and Bills

21

} ], "serviceURL": "http://localhost:8080/em-remote-service/query/json/meters", "dataSupplierId": "TEST", "dataSupplierLogin": "test" }

XML Request XML Response GET http://localhost:8080/em-remote-service/query/xml/meters Request Headers: Content-Type: application/xml X-Ekonerg-Login: test X-Ekonerg-MAC: FZ8NABKpId04g8p07lX3v/edG3+YIXiyvsxMYVSSeoY= Host: <EMIS-service-url>

<response xmlns="http://www.ekonerg.hr/em/bills" status="200" statusDesc="OK" ts="2017-11-23T13:25:03.012" serviceURL="http://localhost:8080/em-remote-service/query/xml/meters" dataSupplierId="TEST" dataSupplierLogin="test"> <meters> <meter> <meterId>1122976</meterId> <meterSerialNumber>NN1122334455</meterSerialNumber> <meterShortDescription/> <meterDescription/> <objectName>Gradski kotar Sirobuja</objectName> <isgeCode>HR-21000-0122-1</isgeCode> <energent>Električna energija</energent> <energentId>Electricity</energentId> <counters> <counter> <counter>1</counter> <name>RVT [kWh]</name> </counter> </counters> </meter> <meter> <meterId>1122982</meterId> <meterSerialNumber>NNxxxxxx</meterSerialNumber> <meterShortDescription/> <meterDescription/> <objectName>Osnovna Škola Miroslava krleže Čepin</objectName> <isgeCode>HR-31431-0007-1</isgeCode> <energent>Električna energija</energent> <energentId>Electricity</energentId> <counters> <counter> <counter>1</counter> <name>RVT [kWh]</name> </counter> <counter> <counter>2</counter> <name>RNT [kWh]</name> </counter> </counters> </meter> </meters> </response>

2.6.2 Readings Query

This method is used for getting a list of all the readings that a data supplier previously sent for a specific meter

and a given year/month.

It is a REST GET method with no parameters. It comes in JSON and XML flavors.

2.6.2.1 Readings Query Request

Readings Request Properties <EMIS-service-url>/query/[xml|json]/readings/<meterId>/<year>/<month>

Name Type Info Description

meterId Number - Meter ID

year Number - Year

month Number - Month

2.6.2.2 Readings Query Response

Readings Response Properties

Name Type Info Description

status Number HTTP response code Standard HTTP response code

Page 23: ENERGY MANAGEMENT INFORMATION SYSTEM Web Service for Remote... · ENERGY MANAGEMENT INFORMATION SYSTEM EMIS Web Service for Remote Readings and Bills ... of EMIS model, IDs of records

EMIS Web Service for Remote Readings and Bills

22

statusDesc Text HTTP response description

Standard HTTP response description

ts Timestamp YYYY-MM-DD’T’HH:mm:ss.SSS

Response timestamp

serviceURL Text HTTP/S link URL of the service (copied from request)

dataSupplierId Text userID User ID

dataSupplierLogin Text userLogin User Login

readings List List of Objects List of Reading objects

reading (zero or more entries) – as described in chapter 2.5.3.2.1 Object “reading”

2.6.2.3 Examples

Readings Request Example

JSON Request JSON Response GET http://localhost:8080/em-remote-service/query/json/readings/1123580/2015/1 Request Headers: Content-Type: application/json X-Ekonerg-Login: test X-Ekonerg-MAC: 0zsztndLpk9XxuQetmo9uGWTnNtFu7xHjiWPUQ26iFA= Host: localhost:8080

{ "status": 200, "statusDesc": "OK", "ts": "2017-11-23T15:47:55.906", "readings": [{ "serviceURL": null, "id": "23", "meterId": "1123580", "date": "2015-01-18T00:00:00", "c1": 511.0, "c2": 500.0, "c3": 500.0, "c4": 500.0, "internalId": "17" }, { "serviceURL": null, "id": "19", "meterId": "1123580", "date": "2015-01-17T00:00:00", "c1": 510.0, "c2": 500.0, "c3": 500.0, "c4": 500.0, "internalId": "17" }, { "serviceURL": null, "id": "22", "meterId": "1123580", "date": "2015-01-16T00:00:00", "c1": 509.0, "c2": 500.0, "c3": 500.0, "c4": 500.0, "internalId": "17" }, { "serviceURL": null, "id": "20", "meterId": "1123580", "date": "2015-01-15T00:00:00", "c1": 508.0, "c2": 500.0, "c3": 500.0, "c4": 500.0, "internalId": "17" }, { "serviceURL": null, "id": "21", "meterId": "1123580", "date": "2015-01-14T00:00:00", "c1": 500.0, "c2": 500.0, "c3": 500.0, "c4": 500.0, "internalId": "17" } ], "serviceURL": "http://localhost:8080/em-remote-service/query/json/readings/1123580/2015/1", "dataSupplierId": "TEST", "dataSupplierLogin": "test" }

Page 24: ENERGY MANAGEMENT INFORMATION SYSTEM Web Service for Remote... · ENERGY MANAGEMENT INFORMATION SYSTEM EMIS Web Service for Remote Readings and Bills ... of EMIS model, IDs of records

EMIS Web Service for Remote Readings and Bills

23

XML Request XML Response GET http://localhost:8080/em-remote-service/query/xml/readings/1123580/2015/1 Request Headers: Content-Type: application/xml X-Ekonerg-Login: test X-Ekonerg-MAC: FZ8NABKpId04g8p07lX3v/edG3+YIXiyvsxMYVSSeoY= Host: <EMIS-service-url>

<response xmlns="http://www.ekonerg.hr/em/bills" status="200" statusDesc="OK" ts="2017-11-23T15:47:56.009" serviceURL="http://localhost:8080/em-remote-service/query/xml/readings/1123580/2015/1" dataSupplierId="TEST" dataSupplierLogin="test"> <readings> <reading id="23" meterId="1123580" date="2015-01-18T00:00:00" c1="511.0" c2="500.0" c3="500.0" c4="500.0" internalId="17"/> <reading id="19" meterId="1123580" date="2015-01-17T00:00:00" c1="510.0" c2="500.0" c3="500.0" c4="500.0" internalId="17"/> <reading id="22" meterId="1123580" date="2015-01-16T00:00:00" c1="509.0" c2="500.0" c3="500.0" c4="500.0" internalId="17"/> <reading id="20" meterId="1123580" date="2015-01-15T00:00:00" c1="508.0" c2="500.0" c3="500.0" c4="500.0" internalId="17"/> <reading id="21" meterId="1123580" date="2015-01-14T00:00:00" c1="500.0" c2="500.0" c3="500.0" c4="500.0" internalId="17"/> </readings> </response>

2.6.3 List of OIB-s (OIB – Personal identification number/Osobni identifikacijski broj)

Returns a list of OIBs of institutions for which datasuppliers must send bills. If you are a datasupplier which sends

bills to EMIS application you can fetch a list OIBs with this query.

2.6.3.1 OIB Query Request

OIB Request GET <EMIS-service-url>/query/[xml|json]/institutions/oib

2.6.3.2 OIB Query Response

Readings Response Properties

Name Type Info Description

status Number HTTP response code Standard HTTP response code

statusDesc Text HTTP response description

Standard HTTP response description

ts Timestamp YYYY-MM-DD’T’HH:mm:ss.SSS

Response timestamp

serviceURL Text HTTP/S link URL of the service (copied from request)

dataSupplierId Text userID User ID

dataSupplierLogin Text userLogin User Login

oibs List List of Strings List of OIB strings

Page 25: ENERGY MANAGEMENT INFORMATION SYSTEM Web Service for Remote... · ENERGY MANAGEMENT INFORMATION SYSTEM EMIS Web Service for Remote Readings and Bills ... of EMIS model, IDs of records

EMIS Web Service for Remote Readings and Bills

24

2.6.3.3 Examples

OIB Request Example

JSON Request JSON Response GET http://localhost:8080/em-remote-service/query/json/institutions/oib Request Headers: Content-Type: application/json X-Ekonerg-Timestamp: 2019-07-25T11:13:03.085Z X-Ekonerg-MAC: axMfZeb3ESq9gwfdHAEBBowswHIEe9ZpO6GZq2tFPo8= X-Ekonerg-Login: test Host: localhost:8080

{ "status": 200, "statusDesc": "OK", "ts": "2019-07-25T13:13:03.127", "serviceMethod": "GET", "serviceURL": "http://localhost:8080/em-remote-service/query/json/institutions/oib", "dataSupplierId": "TEST", "dataSupplierLogin": "test", "oibs": [ "22339633428","75534548941","57318345822","72370493845",… ] }

XML Request XML Response GET /em-remote-service/query/xml/institutions/oib X-Ekonerg-Timestamp: 2019-07-25T11:15:33.420Z X-Ekonerg-MAC: Bym4+GeIIAPGI6TLczMzbMbi8/wbbWHz3usQ0du6U1Q= X-Ekonerg-Login: test Content-Type: application/xml Host: localhost:8080

<response xmlns="http://www.ekonerg.hr/em/bills" status="200" statusDesc="OK" ts="2019-07-25T13:15:33.479" serviceMethod="GET" serviceURL="http://localhost:8080/em-remote-service/query/xml/institutions/oib" dataSupplierId="TEST" dataSupplierLogin="test"> <oibs> <oib>22339633428</oib> <oib>75534548941</oib> <oib>57318345822</oib> <oib>72370493845</oib> <oib>02717359814</oib> <oib>26353705868</oib> <oib>52399386537</oib> … </oibs> </response>

2.7 Service Response Codes

These are standard HTTP responses that the service may return in its “status” and “statusDesc”:

Service Response Codes

Code Text Description

200 OK Request was successfully processed

207 Multi-Status Some or all items could not have been processed due to some business reasons

400 Bad Request Malformed request

401 Unauthorized The MAC or username were invalid

500 Internal Server Error An error on the server side occurred

In case of an error, the service returns a HTTP response code as specified above, and the body of the HTTP

response contains a service response object, with the exception of errors returned by layers other than the

service (e.g. firewalls or connection timeouts), where the response object cannot be returned.

Error Response Example1F

2

JSON Response XML Response HTTP/1.1 401 Unauthorized Server: nginx Date: Mon, 30 Sep 2016 15:26:29 CEST Content-Type: text/html; charset=UTF-8 Cache-Control: no-cache Pragma: no-cache

HTTP/1.1 401 Unauthorized Server: nginx Date: Mon, 30 Sep 2016 15:26:29 CEST Content-Type: text/html; charset=UTF-8 Cache-Control: no-cache Pragma: no-cache

2 HTTP response header is marked italic.

Page 26: ENERGY MANAGEMENT INFORMATION SYSTEM Web Service for Remote... · ENERGY MANAGEMENT INFORMATION SYSTEM EMIS Web Service for Remote Readings and Bills ... of EMIS model, IDs of records

EMIS Web Service for Remote Readings and Bills

25

{"status":401,"statusDesc":"Unauthorized","ts":"2016-09-30T15:26:29.926","err":"AuthorizationException","errDesc":"Invalid MAC", "serviceURL ":"http://<EMIS-service-url>/batch/xml/send" dataSupplierId="test" dataSupplierLogin="test"}

<response xmlns="http://www.ekonerg.hr/em/bills" status="401" statusDesc="Unauthorized" ts="2016-09-30T15:29:23.664" err="AuthorizationException" errDesc="Invalid MAC" serviceURL="http://<EMIS-service-url>/batch/xml/send " dataSupplierId="test" dataSupplierLogin="test"/>

Page 27: ENERGY MANAGEMENT INFORMATION SYSTEM Web Service for Remote... · ENERGY MANAGEMENT INFORMATION SYSTEM EMIS Web Service for Remote Readings and Bills ... of EMIS model, IDs of records

EMIS Web Service for Remote Readings and Bills

26

3 COMMAND-LINE CLIENT A simple Java command-line client application called “em-remote-client” allows data-suppliers to easily send XML

and/or JSON batches to the service. The application runs on any platform capable of running Java 5 or later. It can

be triggered either manually, or automatically by a task scheduler. It sends all XML and JSON batch files found in a

specific directory, returning a response code “0” for successful, or specific non-zero values for various failures in

the process. The files will be moved to two different directories for successful and failed attempts, together with

a matching response from the service.

3.1 Installing the Client

In order to use the application, a Java 5 or later Runtime Environment, or a Java Development Kit should be

installed on a machine running the application.

1. Go to http://www.oracle.com/technetwork/java/javase/downloads/index.html and download the latest

Java JRE. Using a JDK is an overkill in this case and not required to run the application.

2. Install the Java following the on-screen instructions.

This completes the Java installation part. Now install the Client application:

3. Go to https://www.isge.hr/upute/ and download the latest “EMIS WS Client for Remote Readings and

Bills”.

4. Copy the downloaded em-remote-client-X.X.X.jar application to a directory of choice. Let’s call it

{CLIENT_HOME}.

5. Set the permissions so the system would be able to read it.

3.2 Configuring the Client

The client has several parameters that can be configured. They can be set through a configuration file or

overridden as command line parameters.

3.2.1 Quick Start

The following steps apply to Windows environments, but they can be also applied to Linux if you use appropriate

directory separators “/” and directory/drive mapping names.

1. Be sure that your EMIS administrators provided you with your username, password and EMIS web service

URL.

2. Let’s say that the working directory is “C:\EmisWS\”

3. Download the “em-remote-client.jar” and place it in the working directory (see chapter 3.1).

4. You need to create a configuration file “em-remote-client.properties” in that directory using Notepad or

another plain text editor of your choice.

5. Put the following content in the em-remote-client.properties file:

usr=<your username (without the “DS!“ prefix, if one existed)>

pwd=<your password in clear text (no space before or after>

url=<EMIS web service URL, as received from EMIS administrators>

charset=utf-8

NOTE: When entering actual values into the fields described above, you should omit the < and >

characters!

This ends the client configuration. Now let’s send some data:

6. Create a directory “input” inside the “C:\EmisWS\”.

7. Create “my-echo.xml” file in your input folder (file names are irrelevant, but the extension is important):

Page 28: ENERGY MANAGEMENT INFORMATION SYSTEM Web Service for Remote... · ENERGY MANAGEMENT INFORMATION SYSTEM EMIS Web Service for Remote Readings and Bills ... of EMIS model, IDs of records

EMIS Web Service for Remote Readings and Bills

27

<?xml version='1.0' encoding='utf-8'?>

<echo xmlns="http://www.ekonerg.hr/em/bills" value="Hello, World!" />

8. Alternatively, you can create an echo.json file:

{"value" : "Hello, World!"}

9. Open console and place it in the working directory “C:\EmisWS\”

10. Run the client with the “-action ECHO” argument:

java -jar em-remote-client.jar -action ECHO

11. The console should say:

1 file found in directory: C:\EmisWS\input

Sending: my-echo.xml >>> https://...../batch/xml/echo [OK]

Successfuly sent files: 1

You should now have a new directory called “C:\EmisWS\processed” with a response file called “my-echo-

res.xml” (and/or “my-echo-res.json”) with the successful response:

<response xmlns="http://www.ekonerg.hr/em/bills" status="200" statusDesc="OK" ts="2016-11-10T15:15:21.059"

value="Hello, World!"/>

Also, the original my-echo.xml file will also be moved from the input directory, to the processed directory.

In case of an error, the two files should be placed in another directory called “failed”. Open the “my-echo-

res.xml” to see what caused the error.

3.2.2 Configuration Parameters

The following are the available configuration parameters, with their default values. Please note that the default

values can be overridden using a configuration file, as described in chapter 3.2.6.

Configuration Parameters

Name Default Description

data

“input” XML or JSON file to be sent, or directory containing the files. When specifying a directory, the application will look only for JSON or XML files (case-insensitive).

base Current directory Default base directory for data, processed, or failed files. If “data”, “proc” or “failed” parameters are specified as a non-absolute path, this value will be used as a base directory.

proc “processed” Directory for saving successfully processed files. It can be either an absolute or a relative path (see “base” parameter). After successful processing a file will be moved to this directory, keeping the same file name. The service response will be saved as a file with the same name and type, with the “-res” appended at the end.

failed “failed” Directory for saving failed files. It can be either an absolute or a relative path (see “base” parameter). After a failure in processing a file will be moved to this directory, keeping the same file name. The service response will be saved as a file with the same name and type, with the “-res” appended at the end.

url “http://localhost:8080” Service base URL. Usually something like “http://server.domain:8080” (the exact URL will be sent to each Data-Supplier together with its username and password). DO NOT USE DEFAULT VALUE, SERVER IS NOT ON YOUR LOCALHOST! THIS IS JUST DEFAULT, USE THE URL WHICH YOU HAVE RECEIVED IN DOCUMENT/EMAIL WITH YOUR LOGIN AND PASSWORD.

action BATCH Web Service action (BATCH, ECHO). BATCH is used for sending batches, and ECHO is used just for connection testing purposes.

usr null Data Supplier user-name.

Page 29: ENERGY MANAGEMENT INFORMATION SYSTEM Web Service for Remote... · ENERGY MANAGEMENT INFORMATION SYSTEM EMIS Web Service for Remote Readings and Bills ... of EMIS model, IDs of records

EMIS Web Service for Remote Readings and Bills

28

pwd null Data Supplier password in clear or encrypted format. Encrypted passwords start with “{aes}”. See “3.2.5 Encrypting a Password” for details about encrypting a password.

charset System default Local file encoding. This is encoding used locally for storing batches and service responses. It will generally be a system default, but you can specify any other encoding such as UTF-8, UTF-16, CP1250 and so on.

config As described in chapter 3.2.6 Configuration file. If omitted, a configuration file will be searched on default locations as described in chapter “3.2.6 Default Configuration File Locations”.

debug false Turns on some debugging output, like MAC calculation source and result

3.2.3 Passing Parameters in Command Line

The application can be executed from a command line as follows:

java -jar em-remote-client.jar [data] [-base <base>] [-processed <proc>] [-failed <failed>]

[-url <url>] [-usr <name>] [-pwd <password>] [-charset <charset>]

3.2.4 Getting a Help Cheat-Sheet

The following will display help for all the options, with the default values for each parameter:

java -jar em-remote-client.jar [-h | -help]

3.2.5 Encrypting a Password

The following will encrypt and output a given password for safer storing in a configuration file:

java -jar em-remote-client.jar [-encrypt <password>]

Encrypted passwords have an “{aes}” prefix. Copy the output and use it in a configuration file or command line

rather than a plain text.

NOTE: The password is encrypted with and internal AES-128 key that is hard, but not impossible to get.

3.2.6 Default Configuration File Locations

The application tries to find configuration parameters in the following order:

1. Command Line

2. “em-remote-client.properties” in current directory

3. “.em-remote-client” in current directory

4. “em-remote-client.properties” in user home directory

5. “.em-remote-client” in user home directory

3.2.7 Using the Client behind a Web Proxy

If your system uses a web proxy, then you must add the following parameters to all java calls of the em-remote-

client.jar:

a) If the service URL is https, then use

Page 30: ENERGY MANAGEMENT INFORMATION SYSTEM Web Service for Remote... · ENERGY MANAGEMENT INFORMATION SYSTEM EMIS Web Service for Remote Readings and Bills ... of EMIS model, IDs of records

EMIS Web Service for Remote Readings and Bills

29

java –Dhttps.proxyHost=<proxyHostURL> –Dhttps.proxyPort=<proxyPort> -jar em-remote-

client.jar …

b) If the service URL is http, then use java –Dhttp.proxyHost=<proxyHostURL> –Dhttp.proxyPort=<proxyPort> -jar em-remote-

client.jar …

<proxyHostURL> and <proxyPort> should be replaced with actual Proxy URL and Port values, without the “<” and

“>” characters.

For example:

java –Dhttps.proxyHost=proxy.mycompany.com –Dhttps.proxyPort=8080 -jar em-remote-client.jar …

…or:

java –Dhttp.proxyHost=proxy.mycompany.com –Dhttp.proxyPort=8080 -jar em-remote-client.jar …

3.3 Return Codes

The application returns the following codes

Shell Return Codes

Code Description

0 All the batches were successfully processed. A batch is considered successfully processed only if there was not a single failure in the batch, i.e. all the entries were successfully processed.

1 Partial success – there were both successful and unsuccessful files.

2 Total failiure – all the files failed

100 Failure due to invalid parameters.

3.4 Scheduling Batches

Sending a batch using the client can be either triggered manually when required, or scheduled using a crontab (on

*nix) or Task Scheduler (on Windows) machines.

A good practice is to put all the files in a single directory and then call the client application to send all the files.

If calling the client application is scheduled, you must ensure that all the XML and JSON files in the outgoing

directory are completed and ready for sending. The easiest way to ensure that is to use a “.tmp” extension for

files that are currently being created or copied, and then change the extension to XML or JSON when completed.

Page 31: ENERGY MANAGEMENT INFORMATION SYSTEM Web Service for Remote... · ENERGY MANAGEMENT INFORMATION SYSTEM EMIS Web Service for Remote Readings and Bills ... of EMIS model, IDs of records

EMIS Web Service for Remote Readings and Bills

30

4 SIMPLE CLIENT EXAMPLE IN JAVA The following is a simple client application in Java:

package hr.ekonerg.emis.remote.client;

import java.io.Closeable;

import java.io.IOException;

import java.io.InputStream;

import java.io.InputStreamReader;

import java.io.OutputStream;

import java.io.OutputStreamWriter;

import java.net.HttpURLConnection;

import java.net.URL;

import java.security.MessageDigest;

import java.security.NoSuchAlgorithmException;

import java.util.Base64;

import java.util.Date;

public class TestClient {

public static final Charset UTF8 = Charset.forName("UTF-8");

public static void main(String[] args) throws Exception {

String username = "TEST";

String password = "Secret123";

String payload = "{\"value\":\"It is now " + new Date() + "\"}";

String response = echo(username, password, payload);

System.out.println(response);

}

/**

* Calls echo method and returns service response.

*

* @param username

* assigned web service user name

* @param password

* assigned web service password

* @param payload

* request message body

* @return response message body

* @throws IOException

* in case of an I/O exception in communication with the service

*/

public static String echo(String username, String password, String payload) throws IOException {

return wsMethod("POST", "/batch/json/echo", username, password, payload);

}

/**

* Generic call to a REST Web Service method. Internally calculates MAC and sets all required

* HTTP headers.

*

* @param httpMethod

* HTTP method (POST, GET, UPDATE, DELETE...)

* @param methodSubUri

* Web Service method URI. This is the part of the URL behind the server name, port,

* and application context (it should start with a "/").

*

* @param username

* assigned web service user name

* @param password

* assigned web service password

* @param payload

* request message body

* @return response message body

* @throws IOException

Page 32: ENERGY MANAGEMENT INFORMATION SYSTEM Web Service for Remote... · ENERGY MANAGEMENT INFORMATION SYSTEM EMIS Web Service for Remote Readings and Bills ... of EMIS model, IDs of records

EMIS Web Service for Remote Readings and Bills

31

* in case of an I/O exception in communication with the service

*/

protected static String wsMethod(String httpMethod, String methodSubUri, String username,

String password, String payload) throws IOException {

URL url = new URL("http://<EMIS-service-url>" + methodSubUri); // replace with proper URL

OutputStream os = null;

InputStream is = null;

try {

HttpURLConnection conn = (HttpURLConnection) url.openConnection();

conn.setRequestMethod(httpMethod);

conn.setRequestProperty("Content-Type", "application/json");

conn.setRequestProperty("X-Ekonerg-Login", username);

conn.setRequestProperty("X-Ekonerg-MAC", getMac(httpMethod, url,

username, password, payload));

conn.setDoOutput(true);

os = conn.getOutputStream();

OutputStreamWriter osw = new OutputStreamWriter(os, UTF8);

osw.write(payload);

osw.flush();

osw.close();

try {

is = conn.getInputStream();

} catch (Exception e) {

closeSilently(is);

is = conn.getErrorStream();

}

InputStreamReader isr = new InputStreamReader(is, UTF8);

char[] cbuf = new char[1024];

StringBuilder sb = new StringBuilder();

int len = 0;

while ((len = isr.read(cbuf)) > 0) {

sb.append(cbuf, 0, len);

}

isr.close();

return sb.toString();

} finally {

closeSilently(is);

closeSilently(os);

}

}

/**

* Calculates message digest salt from the given parameters.

*

* @param httpMethod

* HTTP method (POST, GET, UPDATE, DELETE...)

* @param methodUri

* Web Service method URI. This is the part of the URI behind the server name and port.

* @param username

* assigned web service user name

* @param password

* assigned web service password

* @return byte array used to initialize the SHA-256 digester

*/

protected static byte[] getSalt(String httpMethod, String methodUri, String username,

String password) {

String str = httpMethod + "\n" + methodUri + "\n" + username + "\n" + password;

return str.getBytes(UTF8);

Page 33: ENERGY MANAGEMENT INFORMATION SYSTEM Web Service for Remote... · ENERGY MANAGEMENT INFORMATION SYSTEM EMIS Web Service for Remote Readings and Bills ... of EMIS model, IDs of records

EMIS Web Service for Remote Readings and Bills

32

}

/**

* Calculates message MAC.

*

* @param httpMethod

* HTTP method (POST, GET, UPDATE, DELETE...)

* @param methodUrl

* Full method URL

* @param username

* assigned web service user name

* @param password

* assigned web service password

* @param payload

* message body

* @return Base64 encoded message MAC

*/

public static String getMac(String httpMethod, URL methodUrl, String username, String password,

String payload) {

try {

MessageDigest md = MessageDigest.getInstance("SHA-256");

byte[] salt = getSalt(httpMethod, methodUrl.getPath(), username, password);

md.update(salt);

if (payload != null)

md.update(payload.getBytes());

return Base64.getEncoder().encodeToString(md.digest());

} catch (NoSuchAlgorithmException e) {

throw new RuntimeException(e);

}

}

protected static void closeSilently(Closeable c) {

try {

if (c != null)

c.close();

} catch (Exception e) {

}

}

}

5 DATASUPPLIER WEB INTERFACE In order to review sent data, and to check setup of remote meters, a data supplier can access the EMIS web

application using his login and key.

1. Go to EMIS web application login page.

2. Login is: DS!<datasupplier login>

3. Password is: <datasupplier key>

E.g. if a data supplier login is TEST, and data supplier key is test123, then web page login is “DS!TEST” and

password is “test123”.

You can review your logins, for remote readings:

List of energy carriers,

Energy carrier counters

Meters (a list of meters for which you can send readings)

Counters on meters (which you must send with each reading)

Page 34: ENERGY MANAGEMENT INFORMATION SYSTEM Web Service for Remote... · ENERGY MANAGEMENT INFORMATION SYSTEM EMIS Web Service for Remote Readings and Bills ... of EMIS model, IDs of records

EMIS Web Service for Remote Readings and Bills

33

Metering devices (for information only, to be able to map device serial number with metering location

serial number if needed)

Log of sent readings

List of accepted readings

Errors in last 24h

Errors in last 24h – detailed

For remote bills:

Sent energy carriers

Sent energy bill field names

Sent vendors

Sent tariffs

Sent meters

Sent bills

Sent bill items

All these tables can also be exported to Excel.

Page 35: ENERGY MANAGEMENT INFORMATION SYSTEM Web Service for Remote... · ENERGY MANAGEMENT INFORMATION SYSTEM EMIS Web Service for Remote Readings and Bills ... of EMIS model, IDs of records

EMIS Web Service for Remote Readings and Bills

34

Change Log

2017-05-05 - Bugfix in source code in “Simple Client Example in Java”.

2017-05-10 - Added Change log;

- Doc fix: type of “tempOut” field in object “Reading” changed to “Decimal” (was “Text”);

- Doc fix: field “billDataList” in “Bill Properties” table changed to “billData”.

2017-09-14 - serviceURL, dataSupplierId and dataSupplierLogin to service responses

- added note to energyCarrierField name

- added instructions for using the Client behind a proxy

2017-11-23 - added meters and readings query methods

2018-01-23 - changed mandatory / optional fields in BillData

2018-03-16 - minor changes in chapter names

2018-04-26 - added Authentication Example

- added “debug” parameter into the Command-Line Client application

2018-10-09 - Fixed error in example XML for bills in chapter 2.5.3.1.6 Object “bill”.

- Fixed several typos in the text

2019-04-19 - added authentication debugging in chapter 2.3

2019-04-25 - added better explanation of unregistering meter in chapter 2.5.3.1.5

2019-04-30 - Added more details about response on Meters query in chapter 2.6.1 (response contains a list of

counters)

2019-07-22 - chapter 3.2.2 added red text to not use default URL

2019-07-25 - added chapter 2.6.3