Skip to content

Commit 5767db7

Browse files
committed
New implementation
1 parent 60c535e commit 5767db7

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+1134
-879
lines changed

.gitignore

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/target/
1+
target/
22
.classpath
33
.project
4-
.settings
4+
.settings/

README.md

+77-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,83 @@
11
# MQTT Tinkerforge Bridge
22

3-
This project allows to bind Tinker Forge sensors and actuators using MQTT to a central broker.
3+
This project allows to bind TinkerForge sensors and actuators using MQTT to a central broker.
44
The application is built using Spring Boot and is currently in a playground phase.
55

66
## Installation and usage
77

8-
Makre sure to correct the `application.properties` and build with Apache Maven using `mvn clean install`.
8+
### Installation
9+
10+
In order to build the software, please run `mvn clean package` from command line (you will require Apache Maven).
11+
12+
### Configuration
13+
14+
For configuration, make sure to copy the `application.properties` from `docs` folder and adjust the configuration.
15+
16+
#### General configuration
17+
18+
In order to connect to the TinkerForge MasterBrick, the connection needs to be specified.
19+
Please use the following two values to configure the connection (the specified values are default):
20+
21+
#
22+
# TF connection
23+
#
24+
tinkerforge.host=localhost
25+
tinkerforge.port=4223
26+
27+
The sensor values are delivered to a MQTT broker, which has to be configured.
28+
29+
#
30+
# MQTT connection
31+
#
32+
mqtt.broker=tcp://localhost:1883
33+
mqtt.client.id=localtest
34+
mqtt.qos=2
35+
36+
#### Configuring MQTT delivery
37+
38+
The MQTT protocol allows to create topics in a special way, so MQTT selectors (# and +) can be applied. In doing so, every MQTT sensor setup has a naming scheme which can be applied to the devices delivering the events. Usually this naming scheme is establishing a topology (physical or logical). The configuration is divided in three parts:
39+
40+
- Topic prefix of the entire application
41+
- Topic segment for device
42+
- Topic segment for measurement
43+
44+
The resulting topic is created by a concatenation of all three segments. The application topic prefix is configured by the property `mqtt.topic.prefix`. The device topic segment is configured using properties of scheme `<uid>.topic=cellar` where the `<uid>` is denoting the device UID of the bricklet. It is possible to configure multiple devices to point to the same topic. e.G.:
45+
46+
mqtt.topic.prefix=testsetup/
47+
aDc.topic=cellar
48+
hgY.topic=cellar
49+
dfH.topic=cellar
50+
51+
In this setup, the three devices with given UIDs are located in cellar and deliver measurements to the same topic `testsetup/cellar`. The measurement topic is configured usgin the device specific setting (see next section).
52+
53+
#### Device configuration
54+
55+
Currently, the following sensor types are supported:
56+
- Ambient light
57+
- Barometer
58+
- Distance Infra-Red
59+
- Distance Ultra-Sound
60+
- Hygrometer
61+
- LCD 20x4 Buttons
62+
- Scale
63+
- Thermometer
64+
- Thermometer Infra-Red
65+
- Voltmeter
66+
67+
In addition, the following actuators are implemented:
68+
- LCD 20x4 Text and Backlight
69+
70+
In general, you can configure every value sensor and set its value read timeout (`callbackperiod`) and the target topic (`topic`).
71+
72+
#
73+
# Example ambient light
74+
#
75+
tinkerforge.ambilight.topic=illuminance
76+
tinkerforge.ambilight.callbackperiod=10000
77+
78+
This will configure the ambient light to be checked every 10 seconds and deliver the value to `testsetup/cellar/illuminance`.
79+
80+
81+
### Run
82+
83+
To run the software just run `java -jar <mqtt-tinkerforge-boot-version.jar>

docs/application.properties

+11-16
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,14 @@
1+
#
2+
# MQTT Part
3+
#
4+
mqtt.broker=tcp://localhost:1883
5+
mqtt.client.id=localtest
6+
mqtt.qos=2
7+
mqtt.topic.prefix=homebase/
8+
9+
#
10+
# TF Part
11+
#
112
tinkerforge.host=localhost
213
tinkerforge.port=4223
3-
tinkerforge.master.uid=6wxw1h
4-
5-
tinkerforge.bricklet.barometer.uid=k61
6-
tinkerforge.bricklet.barometer.callbackperiod=20000
7-
tinkerforge.bricklet.thermometer.uid=nnA
8-
tinkerforge.bricklet.thermometer.callbackperiod=20000
9-
tinkerforge.bricklet.hygrometer.uid=kfp
10-
tinkerforge.bricklet.hygrometer.callbackperiod=20000
11-
tinkerforge.bricklet.lcd.uid=qor
1214

13-
14-
15-
mqtt.broker=tcp://localhost:1883
16-
#mqtt.broker=tcp://rlx-v88.ham.dlh.de:1883
17-
mqtt.qos=2
18-
mqtt.topic.prefix=tis/fridge/
19-
mqtt.client.id=MQTT Sensor Client

docs/realm.properties

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
mcy.topic=room1
2+
kqN.topic=room1
3+
4+
qor.topic=cellar
5+
nnA.topic=cellar
6+
kfp.topic=cellar
7+
k61.topic=cellar
8+
9+
10+

pom.xml

+4-3
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,15 @@
33
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
44
<modelVersion>4.0.0</modelVersion>
55
<groupId>de.techjava</groupId>
6-
<artifactId>mqtt-tinkerforge</artifactId>
6+
<artifactId>mqtt-tinkerforge-bridge</artifactId>
77
<packaging>jar</packaging>
88
<name>TinkerForge MQTT Bridge</name>
9+
<description>Spring Boot application providing TinkerForge to MQTT bridge.</description>
910

1011
<parent>
1112
<groupId>org.springframework.boot</groupId>
1213
<artifactId>spring-boot-starter-parent</artifactId>
13-
<version>1.2.4.RELEASE</version>
14+
<version>1.3.1.RELEASE</version>
1415
<relativePath />
1516
</parent>
1617

@@ -26,7 +27,7 @@
2627
<dependency>
2728
<groupId>org.springframework.boot</groupId>
2829
<artifactId>spring-boot-dependencies</artifactId>
29-
<version>1.2.4.RELEASE</version>
30+
<version>1.3.1.RELEASE</version>
3031
<type>pom</type>
3132
<scope>import</scope>
3233
</dependency>
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,10 @@
11
package de.techjava.mqtt.tf;
22

3-
import org.slf4j.Logger;
4-
import org.slf4j.LoggerFactory;
53
import org.springframework.boot.SpringApplication;
6-
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
7-
import org.springframework.context.ConfigurableApplicationContext;
8-
import org.springframework.context.annotation.ComponentScan;
9-
import org.springframework.context.annotation.Configuration;
10-
import org.springframework.context.annotation.EnableAspectJAutoProxy;
114

12-
@Configuration
13-
@EnableAutoConfiguration
14-
@EnableAspectJAutoProxy(proxyTargetClass = true)
15-
@ComponentScan
165
public class Starter {
176

18-
static final Logger logger = LoggerFactory.getLogger(Starter.class);
19-
207
public static void main(final String[] args) {
21-
final ConfigurableApplicationContext applicationContext = SpringApplication.run(Starter.class, args);
22-
applicationContext.addApplicationListener((event) -> {
23-
24-
});
8+
SpringApplication.run(StarterConfiguration.class, args);
259
}
2610
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package de.techjava.mqtt.tf;
2+
3+
import javax.annotation.PostConstruct;
4+
5+
import org.slf4j.Logger;
6+
import org.slf4j.LoggerFactory;
7+
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
8+
import org.springframework.boot.context.properties.EnableConfigurationProperties;
9+
import org.springframework.context.annotation.Configuration;
10+
import org.springframework.context.annotation.Import;
11+
12+
import de.techjava.mqtt.tf.comm.MqttConfiguration;
13+
import de.techjava.mqtt.tf.core.TinkerForgeConfiguration;
14+
15+
@Configuration
16+
@Import({ MqttConfiguration.class, TinkerForgeConfiguration.class })
17+
public class StarterConfiguration {
18+
19+
private static final Logger logger = LoggerFactory.getLogger(StarterConfiguration.class);
20+
21+
@PostConstruct
22+
public void postConstruct() {
23+
logger.info("Configuration loaded.");
24+
}
25+
}

src/main/java/de/techjava/mqtt/tf/TinkerForgeConfiguration.java

-66
This file was deleted.

src/main/java/de/techjava/mqtt/tf/actuator/LCD20x4.java

-109
This file was deleted.

0 commit comments

Comments
 (0)