Skip to content

Commit

Permalink
Merge pull request #4 from industrial-edge/dev-v1.3
Browse files Browse the repository at this point in the history
Updates for V1.3
  • Loading branch information
Boehmi-TB authored Nov 4, 2021
2 parents 651a727 + d9b2580 commit edfb309
Show file tree
Hide file tree
Showing 10 changed files with 339 additions and 57 deletions.
71 changes: 48 additions & 23 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,58 +17,83 @@ This application example contains the source files to build a Databus Ping Pong

## Description

This repository contains the source files to build the Databus Ping Pong application example implemented in C. Please refer to the [Ping Pong in Python repository](https://github.com/industrial-edge/pingpong-python) for more information about this application example.

### Overview

This application example shows how to connect to the IE Databus via MQTT and how to publish and subscribe data using an implementation in C. The IE Flow Creator is used to exchange data between different topics within the IE Databus. This example uses the [Eclipse Paho MQTT C library](https://github.com/eclipse/paho.mqtt.c) to enable the connection to the IE Databus.
This application example shows how to connect to the IE Databus via MQTT and how to publish and subscribe data using an implementation in C.
The IE Flow Creator is used to exchange data between different topics within the IE Databus.

![Use Case](/docs/Overview.png)

It also uses a multi-stage process for building the docker image to keep the image size as small as possible. The two ``FROM`` Statements in the [Dockerfile](src/Dockerfile) separate the build process into two stages. The fist stage is compiling the source code of the application and the paho library which then get copied to the second stage which will be the final image for the application. Please refer to the the [docker documentation](https://docs.docker.com/develop/develop-images/multistage-build/) for more information regarding multi-stage builds.
This implementation example uses the ``ubuntu:20.04`` image as base, the [Eclipse Paho MQTT C library](https://github.com/eclipse/paho.mqtt.c) to enable the connection to the IE Databus and ``cmake`` for building the code.
Here a multi-stage process for building the docker image is used to keep the image size as small as possible. The two ``FROM`` Statements in the [Dockerfile](src/Dockerfile) separate the build process into two stages.
The fist one is compiling the source code to an executable which then gets copied to the second stage. This stage finally creates the application container, where the executable runs. Please refer to the the [docker documentation](https://docs.docker.com/develop/develop-images/multistage-build/) for more information regarding multi-stage builds.

![Use Case](docs/DataFlow.png)
This example also shows two ways of configuring the application:

- configuration via file upload (fix configuration file)
- configuration via system app Configuration Service (custom configuration UI with JSON Forms)

### General task

The application includes a MQTT client to subscribe to one topic of the IE Databus and waits to receive data. When data arrives, it publishes a corresponding answer to a second topic of the IE Databus. If it receives the string "Ping", it will answer with "Pong" and the other way around.

![Use Case](docs/Usecase.png)
![Use Case](/docs/PingPongFlow.png)

The names of the IE Databus topics as well as the credentials used by the application can be configured, otherwise environmental variables included in the docker-compose file are used.
The names of the IE Databus topics as well as the credentials used by the application can be configured via different options, otherwise environmental variables included in the docker-compose file are used.

## Requirements

### Used components

- Industrial Edge Management V1.2.0-36 / V1.2.14
- IE Databus V1.2.16
- IE Databus Configurator V1.2.23
- IE Flow Creator V1.1.2
- Industrial Edge Device V1.2.0-56
- Industrial Edge App Publisher V1.2.7
- Docker Engine V20.10.3
- Industrial Edge Management V1.3.0-58 / V1.4.3
- IE Databus Configurator V1.4.22
- IE Databus V1.4.16
- IE Flow Creator V1.2.2
- IE App Configuration Service V1.0.7
- Industrial Edge Device (IED) V1.3.0-57 or vIED V1.3.1-1-a
- Industrial Edge App Publisher V1.4.3
- Docker Engine V20.10.10
- Docker Compose V1.28.5

### Further requirements

- IE Device is onboarded to a IE Management
- IE Databus Configurator is deployed to the IE Management
- IE Databus is deployed to the IE Device
- IE Flow Creator is deployed to the IE Device
- IED is onboarded to a IEM
- IE Databus Configurator is deployed to the IEM
- IE Configuration Service is deployed to the IEM
- IE Databus is deployed to the IED
- IE Flow Creator is deployed to the IED

## Installation

Please refer to the [Installation](https://github.com/industrial-edge/pingpong-python/blob/main/docs/Installation.md) section of the *Ping Pong in Python* repository on how to build and deploy the application to a Industrial Edge Device.
When creating a configuration for the application in the Industrial Edge Management System, you can use the the [mqtt-config.json](cfg-data/mqtt-config.json) file from this repository.
Please refer to the [Installation](https://github.com/industrial-edge/pingpong-csharp/blob/main/docs/Installation.md#installation) section of the *Ping Pong in C#* repository on how to build and deploy the application to an IED. Just use the source files from this repository and follow the instructions.

- [Build application](https://github.com/industrial-edge/pingpong-csharp/blob/main/docs/Installation.md#build-application)
- [Configuring the Industrial Edge Databus](https://github.com/industrial-edge/pingpong-csharp/blob/main/docs/Installation.md#configuring-the-industrial-edge-databus)
- [Create configuration for the application](https://github.com/industrial-edge/pingpong-csharp/blob/main/docs/Installation.md#create-configuration-for-the-application)
- [Upload the application to the Industrial Edge Management](https://github.com/industrial-edge/pingpong-csharp/blob/main/docs/Installation.md#create-configuration-for-the-application)
- [Configuring and deploying the application to a Industrial Edge Device](https://github.com/industrial-edge/pingpong-csharp/blob/main/docs/Installation.md#configuring-and-deploying-the-application-to-a-industrial-edge-device)
- [Testing the application using Simatic Flow Creator](https://github.com/industrial-edge/pingpong-csharp/blob/main/docs/Installation.md#testing-the-application-using-simatic-flow-creator)

## Usage

Once the application is successfully deployed, it can be tested using the IE Flow Creator.
Once the application is successfully deployed to the IED, it can be tested using the IE Flow Creator.

On the IED restart the PingPong application, to ensure the right configuration is used. Then open the app IE Flow Creator and set it up as following:

- Connect an "inject" node with a "mqtt out" node
- Connect a "mqtt in" node with a "debug" node
- Configure the mqtt-nodes to connect to the databus (mqtt broker, username, password)
- Set the topics of the mqtt-nodes according to the configuration of the application (here: "topic1" to publish to, "topic2" to subscribe to)

Deploy the flow and test by injecting a string payload into the mqtt in node. If the string is "Ping", the application will answer with "Pong". If the string is "Pong" the application will answer with "Ping".

The finished flow is available [here](/src/Flow_Pingpong_Test.json) and can be imported into the IE Flow Creator.

Please refer to the [Testing](https://github.com/industrial-edge/pingpong-python/blob/main/docs/Installation.md#testing-the-application-using-simatic-flow-creator) section of the *Ping Pong in Python* repository on how to use it.
![Flow Creator](/docs/FlowCreator.png)

## Documentation

You can find further documentation and help in the following links
You can find further documentation and help in the following links:

- [Industrial Edge Hub](https://iehub.eu1.edge.siemens.cloud/#/documentation)
- [Industrial Edge Forum](https://www.siemens.com/industrial-edge-forum)
Expand Down
78 changes: 78 additions & 0 deletions cfg-data/json_schema/mqtt-config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
{
"uischema":{
"type": "Group",
"elements": [
{
"type": "Group",
"elements": [
{
"type": "Control",
"scope": "#/properties/MQTT_IP"
},
{
"type": "HorizontalLayout",
"elements": [
{
"type": "Control",
"scope": "#/properties/MQTT_USER"
},
{
"type": "Control",
"scope": "#/properties/MQTT_PASSWORD"
}
]
}
],
"label": "IE Databus credentials"
},
{
"type": "Group",
"elements": [
{
"type": "HorizontalLayout",
"elements":[
{
"type": "Control",
"scope": "#/properties/TOPIC_1"
},
{
"type": "Control",
"scope": "#/properties/TOPIC_2"
}
]
}
],
"label": "IE Databus topics"
}
]
},
"dataschema":{
"type": "object",
"properties": {
"TOPIC_1": {
"title": "Topic 1",
"default": "topic1",
"type": "string"
},
"TOPIC_2": {
"title": "Topic 2",
"default": "topic2",
"type": "string"
},
"MQTT_IP": {
"title": "MQTT Broker",
"default": "ie-databus",
"type": "string"
},
"MQTT_USER": {
"title": "Username",
"type": "string"
},
"MQTT_PASSWORD": {
"title": "Password",
"type": "string"
}
},
"required": ["TOPIC_1", "TOPIC_2", "MQTT_IP", "MQTT_USER", "MQTT_PASSWORD"]
}
}
38 changes: 17 additions & 21 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,27 +1,23 @@
version: '2.4'

services:
pingpong_c:

build:
context: ./src
image: pingpong_c:1.1.0
networks:
- proxy-redirect

environment:
- TOPIC_1=topic1
- TOPIC_2=topic2
- MQTT_USER=edge
- MQTT_PASSWORD=edge
- MQTT_IP=tcp://ie-databus:1883
mem_limit: 100mb

volumes:
- './publish/:/publish/'
- './cfg-data/:/cfg-data/'

#### Network ####
#### pingpong service ####
pingpong_c:
build: ./src
image: pingpong_c:1.3.0
restart: unless-stopped
mem_limit: 100mb
networks:
- proxy-redirect
environment:
- TOPIC_1=topic1
- TOPIC_2=topic2
- MQTT_USER=edge
- MQTT_PASSWORD=edge
- MQTT_IP=tcp://ie-databus:1883
volumes:
- './publish/:/publish/'
- './cfg-data/:/cfg-data/'

networks:
proxy-redirect:
Expand Down
Binary file removed docs/DataFlow.png
Binary file not shown.
Binary file added docs/FlowCreator.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/Overview.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/PingPongFlow.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed docs/Usecase.png
Binary file not shown.
25 changes: 12 additions & 13 deletions src/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,37 +1,36 @@

# ------ STAGE 1 (build container) ---------------------

FROM ubuntu:20.04 as build-env

ENV DEBIAN_FRONTEND=noninteractive
RUN apt update && apt install -y build-essential gcc-9 make cmake libssl-dev libjson-c-dev git

# download mqtt client library
RUN git clone https://github.com/eclipse/paho.mqtt.c.git


#Compile paho library from sources
# compile paho library from sources
RUN cmake -DPAHO_ENABLE_TESTING=FALSE -DPAHO_BUILD_STATIC=TRUE -DPAHO_WITH_SSL=TRUE -DPAHO_BUILD_SAMPLES=FALSE paho.mqtt.c/
RUN cd paho.mqtt.c/ && make install && cd /


# copy source files into filesystem of container
ADD . /src
RUN cd /src && cmake . && make

# build code
RUN cd /src && cmake . && make

FROM ubuntu:20.04

#install the libssl-dev and libjson-c-dev package
RUN apt update && apt install -y libssl-dev libjson-c-dev
#copy the compiled application and library from the build image to the applciation image
COPY --from=build-env /src/paho_pingpong /
COPY --from=build-env /usr/local/lib/libpaho-mqtt3as.so.1 /
# ------ STAGE 2 (application container) -----------------

FROM ubuntu:20.04

#install the libssl-dev and libjson-c-dev package
# install the libssl-dev and libjson-c-dev package
RUN apt update && apt install -y libssl-dev libjson-c-dev

#copy the compiled application and library from the build image to the applciation image
# copy the compiled application and library from the build image to the applciation image
COPY --from=build-env /src/paho_pingpong /
COPY --from=build-env /usr/local/lib/libpaho-mqtt3as.so.1 /usr/local/lib
RUN export LD_LIBRARY_PATH=/usr/local/lib && ldconfig


# run application
CMD ["./paho_pingpong"]
Loading

0 comments on commit edfb309

Please sign in to comment.