About

The online repository of the Lablink Universal Data Exchange API client includes a simple example demonstrating its use. This example comprises a simple REST API implementing the ERIGrid Universal Data Exchange API (v2.0), which exposes a readable channel (test/channel1) and a writable channel (test/channel2). The readable channel is continuously updated from another data source (a Lablink CSV reader) and its current value (sample) can be retrieved by the user (e.g., using curl from the command prompt). The writable channel can be changed by the user (e.g., using curl from the command prompt). When running the example, both signals are visualized using a plotter.

Prerequisites

MQTT broker

An MQTT broker is required for running the example, for instance Eclipse Mosquitto or EMQ.

Running the example (Windows)

List all available channels

In this example, the Universal API client has two channels:

  • test/channel1 is a read-only channel

  • test/channel2 is a write-only channel

You can retrieve this information directly from the client. There are various ways of retrieving data from REST interfaces, one way is using curl (which is by default already included on recent versions of Windows). Use curl directly from the command prompt (cmd.exe):

curl -i localhost:7000/uapi-test/channels

This will return the API’s response status (200 in case of success) and the list of available signals:

HTTP/1.1 200 OK
Date: Mon, 09 Jan 2023 13:29:51 GMT
Content-type: application/json
Content-length: 222
[{"id":"test/channel2","payload":"samples","datatype":"float","writable":true,"readable":false},{"id":"test/channel1","payload":"samples","datatype":"float","range":{"min":5.0,"max":15.0},"writable":false,"readable":true}]

Retrieve a channel sample

Once the client is running, you can retrieve the latest sample value of channel test/channel1. To do so, you can use curl directly from the command prompt (cmd.exe):

curl -i localhost:7000/uapi-test/channel/test/channel1/sample

This will return the API’s response status (200 in case of success) and the current sample value of test/channel1, for instance:

HTTP/1.1 200 OK
Date: Mon, 09 Jan 2023 13:32:20 GMT
Content-type: application/json
Content-length: 109
{"timestamp":1.673271140676E9,"value":12.034,"validity":"valid","source":"calculated","timesource":"unknown"}

The returned value should agree with the latest value as visualized by the plotter.

Retrieve current value of signal from Universal API client.

Set a sample value

The Universal API client also has a write-only channel called test/channel2. There are various ways of updating data through a REST interfaces, one way is again with the help of curl. Use curl directly from the command prompt (cmd.exe):

curl -i -X PUT -H "Content-Type: application/json" -d "{"""timestamp""":123.456,"""value""":13}" localhost:7000/uapi-test/channel/test/channel2/sample

This will return the API’s response status (200 in case of success):

HTTP/1.1 200 OK
Date: Mon, 09 Jan 2023 13:42:12 GMT
Content-length: 34
Success. Channel has been updated.

The new sample value for test/channel2 should also be visualized by the plotter.

Update of value of signal from Universal API client.