PulseSensor – Eclipse Kura configuration
Eclipse Kura
This sub-chapter is about how to configure our Eclipse Kura™ framework to connect with both the Eclipse Kapua™ platform as well as with the openHAB3 Broker.
Configuring the Cloud connection to the Eclipse Kapua™ platform
An important task is to connect our Eclipse Kura™ framework with the Eclipse Kapua™ platform. There are three entities to configure. The CloudService as such the DataService and the MQTTDataTransport Service.
Configuring the CloudService
For configuring the CloudService, we go to [Cloud Connections] and select the [CloudService] tab.
| Attribute | Value | Note |
| Device Display-Name | custom | allows for own name |
| Device Custom-Name | Natrix-Gateway-PulseSensor-Maker-Project | |
| Topic Control-Prefix | $EDC | Default value |
| Encode gzip | true | Default value |
| Republish Mqtt Birth Cert On Gps Lock | false | Default value |
| Republish Mqtt Birth Cert On Modem Detect | false | Default value |
| Enable Default Subscriptions | true | Default value |
| Birth Cert Policy | Publish birth on connect and reconnect | Default value |
| Payload Encoding | Kura Protobuf | Default value |
Push the configuration by [Apply] the configuration changes.
Configuring the DataService
For configuring the DataService, we go to [Cloud Connections] and select the [DataService] tab.
| Attribute | Value | Note |
| Connect Auto-on-startup | true | |
| Connect Retry-interval | 60 | Default value |
| Enable Recovery On Connection Failure | false | Default value |
| Connection Recovery Max Failures | 10 | Default value |
| Disconnect Quiesce-timeout | 10 | Default value |
| Store DB Service PID | org.eclipse.kura.db.H2DbService | Default value |
| Store Housekeeper-interval | true | Default value |
| Store Housekeeper-interval | 900 | Default value |
| Store Purge-age | 60 | Default value |
| Store Capacity | 1000 | Default value |
| In-flight-messages Republish-on-new-session | True | Default value |
| In-flight-messages Max-number | 9 | Default value |
| In-flight-messages Congestion-timeout | 0 | Default value |
| Enable Rate Limit | true | Default value |
| Rate Limit Average | 1 | Default value |
| Rate Limit Time Unit | Seconds | Default value |
| Rate Limit Burst Size | 1 | Default value |
Push the configuration by [Apply] the configuration changes.
Configuring the MQTTDataTransport Service
For configuring the MQTTDataTransport Service, we go to [Cloud Connections] and select the [MQTTDataTransport] tab.
| Attribute | Value | Note |
| Broker-url | mqtt://[Eclipse-Kapua-Server]:1883/ | This is our Eclipse Kapua server on port 1883 |
| Topic Context Account-Name | Derry-Hospital | Creating a new Child Account |
| Username | Physician-1 | Creating a new User and assign it to the new account |
| Password | <<your password here >> | Creating a new User and assign it to the new account |
| Client-ID | Natrix-Gateway-PulseSensor-Maker-Project | Let’s use the custom name for it |
| Keep-Alive | 30 | Default value |
| Timeout | 20 | Default value |
| Clean-session | true | Default value |
| LWT Topic | $EDC/#account-name/#client-id/MQTT/LWT | Default value |
| LWT Payload | Default value | |
| LWT Qos | 0 | Default value |
| LWT Retain | true | Default value |
| In-flight Persistence | Memory | Default value |
| Protocol-version | 3.1.1 | Default value |
| SSL Default Protocol | 1 | Default value |
| SSL Hostname Verification | Rely on SSL Manager Service configuration | Default value |
| SSL Default Cipher Suites | Default value | |
| SSL Certificate Alias | Default value |
Push the configuration by [Apply] the configuration changes.
Checking connectivity status to Eclipse Kapua™ platform
We have to places where we can check the successful connection status between Eclipse Kura™ and Eclipse Kapua™.
After applying all configuration parameters in Eclipse Kura™, the connection status is displayed at the top of the configuration page:

In Eclipse Kapua™ we see our Natrix Gateway connected under the Client-ID as configured (Natrix-Gateway-PulseSensor-Maker-Project) and with the user Physician-1.

Adding a Publisher and Subscriber Service for the PulseSensor project
Because we publish our PulseSensor Telemetry data to Eclipse Kapua™, we need to configure a Publisher Service in Eclipse Kura™. Although we don’t need a Subscription service yet in our project, for the sake of completeness we also add a Subscriber Service.
We go to [Cloud Connections]->[New Pub/Sub] , select the factory org.eclipse.kura.cloud.publisher.CloudPublisher add a Publisher Service with the name ‘KuraPublisher’.
Same we do with the Subscriber Service, adding a Service ‘KuraSubscriber’ and assign it to the factory org.eclipse.kura.cloud.subscriber.CloudSubscriber.

Adding a Publisher and Subscriber Service for the PulseSensor project
Deploying the PulseSensor Deployment Package
Most of the configuration is done using the configuration settings of our PulseSensor project. So, the first step is to deploy the PulseSensor Deployment Package to the Eclipse Kura™ framework.
The PulseSensor Deployment Package is available for download from the Natrix Project GitHub account. (NatrixProject(1), 2021)

We need to download the ‘PulseSensorMQTT.dp’ file to your local PC.
Once we have done this, let’s open the Eclipse Kura™ Administration pages under http://[ip-address-of our-gateway]:80.
Navigate to [Packages]->[Install/Upgrade]

and choose the ‘PulseSensorMQTT.dp’ file from the location on your PC where you downloaded it.

Push [Submit] and we will see that the package has been successfully deployed into the Eclipse Kura™ framework.

Configuring the PulseSensor Plug-in
After the deployment of the package, the PulseSensorMQTT plug-in (bundle) appears in the active bundle list. With a click on it, the configuration section of the PulseSensor bundle opens on the right-hand site of the Administration page.

The following parameters need to be configured for the attributes provided by the PulseSensor bundle:
| Attribute | Value | Note |
| BPM Multiplying factor | 1 | Disables value manipulation |
| CloudPublisher Target Filter | (kura.service.pid=KuraPublisher) | Available as target |
| CloudSubscriber Target Filter | (kura.service.pid=KuraSubscriber) | Available as target |
| Data Collection (true/false) | true | |
| MQTT Publishing (true/false) | true | |
| MQTT Publishing to 3rd party broker (true/false) | true | |
| Serial Interface | /dev/ttyACM0 | Arduino-Natrix-Gateway serial connection |
| Time out [ms] | 2000 | |
| Sampling rate [ms] | 10000 | |
| baud rate [Bytes/s] | 115200 | |
| 3rd Party MQTT Broker | tcp://127.0.0.1:1883 | Local Mosquitto Broker |
| MQTT topic Publish | cmnd/pulsesensor/Alarm | see here |
| MQTT topic Subscribe | stat/pulsesensor/Alarm | see here |
| MQTT topic for metrics Publish | /topic/pulsesensor/metrics | |
| MQTT topic for metrics Subscribe | /topic/pulsesensor/metrics | |
| MQTT payload for Alarm=’ON‘ | OFF | Payload when sending Alarm=on |
| MQTT payload for Alarm=’OFF‘ | ON | Payload when sending Alarm=off |
| Setting alarm for min.BPM [beats/minute] | 40 | Low threshold for Pulse alarm |
| Setting alarm for max. BPM [beats/minute] | 120 | High threshold for Pulse alarm |
| Setting filter for BPM false measures [beats/minute] | 180 | Everything above =false measure |
| Setting filter for InterBeatIntervall false measures [ms] | 1200 | Everything above =false measure |
| Setting filter for Sample Rate false measures [mV] | 1000 | Everything above =false measure |
| gpio.service.pid | org.eclipse.kura.gpio.GPIOService | |
| gpio.input.read.mode | PIN_STATUS_LISTENER | |
| gpio.pins | GPIO_GEN4,GPIO_GEN5 | The two Pins of our project |
| gpio.directions | Both, init output | |
| gpio.modes | Default | |
| gpio.triggers | Default |
Push the configuration by [Apply] the configuration changes.
If everything works smoothly, we see our first data arriving in Eclipse Kapua™ when connecting the PulseSensor to our fingertips.

Changing the Eclipse Kura™ log-parameters
As we want to have all PulseSensor Project related logfiles separated from the standard Kura log-files, we need to adjust the log4j.xml file in the directory /opt/eclipse/kura/user.
We have a dedicated logger for each module of the PulseSensor Project -> PulseSensorMQTT, SerialInterface, openHABMQTT and GPIOComponent. For each new logger we also require a dedicated Appender (RollingFileAppender).
nano /opt/eclipse/kura/user/log4j.xml
<?xml version="1.0" encoding="UTF-8"?>
<!--
#
# Copyright (c) 2018, 2019 Eurotech and/or its affiliates
#
# All rights reserved. This program and the accompanying materials
# are made available under the terms of the Eclipse Public License v1.0
# which accompanies this distribution, and is available at
# http://www.eclipse.org/legal/epl-v10.html
#
# Contributors:
# Eurotech
#
-->
<Configuration status="warn" strict="true" name="KuraConfig" monitorInterval="30">
<Properties>
<Property name="filename">/var/log/kura/kura</Property>
</Properties>
<Filter type="ThresholdFilter" level="trace"/>
<Appenders>
<RollingFile name="RollingFile" fileName="${filename}.log" filePattern="${filename}-%d{MM-dd-yy-HH-mm-ss}-%i.log.gz">
<PatternLayout>
<Pattern>%d{ISO8601} [%t] %-5p %c{1.} - %m%n%throwable{full}</Pattern>
</PatternLayout>
<Policies>
<SizeBasedTriggeringPolicy size="20 MB"/>
</Policies>
<DefaultRolloverStrategy max="10"/>
</RollingFile>
<RollingFile name="PulseSensorMQTT" fileName="/var/log/kura/PulseSensorMQTT.log" filePattern="/var/log/kura/PulseSensorMQTT-%d{MM-dd-yy-HH-mm-ss}-%i.log.gz">
<PatternLayout>
<Pattern>%d{ISO8601} [%t] %-5p %c{1.} - %m%n%throwable{full}</Pattern>
</PatternLayout>
<Policies>
<SizeBasedTriggeringPolicy size="20 MB"/>
</Policies>
<DefaultRolloverStrategy max="10"/>
</RollingFile>
<RollingFile name="SerialInterface" fileName="/var/log/kura/SerialInterface.log" filePattern="/var/log/kura/SerialInterface-%d{MM-dd-yy-HH-mm-ss}-%i.log.gz">
<PatternLayout>
<Pattern>%d{ISO8601} [%t] %-5p %c{1.} - %m%n%throwable{full}</Pattern>
</PatternLayout>
<Policies>
<SizeBasedTriggeringPolicy size="20 MB"/>
</Policies>
<DefaultRolloverStrategy max="10"/>
</RollingFile>
<RollingFile name="ThirdPartyBroker" fileName="/var/log/kura/ThirdPartyBroker.log" filePattern="/var/log/kura/ThirdPartyBroker-%d{MM-dd-yy-HH-mm-ss}-%i.log.gz">
<PatternLayout>
<Pattern>%d{ISO8601} [%t] %-5p %c{1.} - %m%n%throwable{full}</Pattern>
</PatternLayout>
<Policies>
<SizeBasedTriggeringPolicy size="20 MB"/>
</Policies>
<DefaultRolloverStrategy max="10"/>
</RollingFile>
<RollingFile name="GpioComponent" fileName="/var/log/kura/GpioOperations.log" filePattern="/var/log/kura/GpioOperations-%d{MM-dd-yy-HH-mm-ss}-%i.log.gz">
<PatternLayout>
<Pattern>%d{ISO8601} [%t] %-5p %c{1.} - %m%n%throwable{full}</Pattern>
</PatternLayout>
<Policies>
<SizeBasedTriggeringPolicy size="20 MB"/>
</Policies>
<DefaultRolloverStrategy max="10"/>
</RollingFile>
</Appenders>
<Loggers>
<Logger name="org.eclipse" level="info" additivity="false">
<AppenderRef ref="RollingFile"/>
</Logger>
<Root level="warn">
<AppenderRef ref="RollingFile"/>
</Root>
<Logger name="de.natrix.kura.pulsemqtt.SerialInterface" level="info" additivity="false">
<AppenderRef ref="SerialInterface"/>
</Logger>
<Logger name="de.natrix.kura.pulsemqtt.PulseSensorMQTT" level="info" additivity="false">
<AppenderRef ref="PulseSensorMQTT"/>
</Logger>
<Logger name="de.natrix.kura.pulsemqtt.ThirdPartyBrokerMQTT" level="info" additivity="false">
<AppenderRef ref="ThirdPartyBroker"/>
</Logger>
<Logger name="de.natrix.kura.pulsemqtt.GpioOperations" level="info" additivity="false">
<AppenderRef ref="GpioComponent"/>
</Logger>
</Loggers>
</Configuration>