Skip to content
Snippets Groups Projects
Commit 93fbab4a authored by Manuel Krombholz's avatar Manuel Krombholz
Browse files

Added mqtt username and password for receiver

parent 0ce98daa
Branches
No related tags found
1 merge request!19dev to master
Pipeline #9848 passed
...@@ -40,6 +40,8 @@ public class MQTTUpdater implements AutoCloseable { ...@@ -40,6 +40,8 @@ public class MQTTUpdater implements AutoCloseable {
public void setRoot(Root root) { public void setRoot(Root root) {
ExternalHost host = root.getMqttRoot().getHost(); ExternalHost host = root.getMqttRoot().getHost();
delegatee.setHost(host.getHostName(), host.getPort()); delegatee.setHost(host.getHostName(), host.getPort());
delegatee.setUsername(root.getMqttRoot().getUser());
delegatee.setPassword(root.getMqttRoot().getPassword());
delegatee.setOnMessage((topicString, message)-> delegatee.setOnMessage((topicString, message)->
root.getMqttRoot().resolveTopic(topicString).ifPresent(topic -> root.getMqttRoot().resolveTopic(topicString).ifPresent(topic ->
topic.getItems().forEach( topic.getItems().forEach(
......
...@@ -28,6 +28,8 @@ public class MqttReceiver implements AutoCloseable { ...@@ -28,6 +28,8 @@ public class MqttReceiver implements AutoCloseable {
/** The host running the MQTT broker. */ /** The host running the MQTT broker. */
private URI host; private URI host;
private String username;
private String password;
/** The connection to the MQTT broker. */ /** The connection to the MQTT broker. */
private CallbackConnection connection; private CallbackConnection connection;
/** Whether we are subscribed to the topics yet */ /** Whether we are subscribed to the topics yet */
...@@ -54,6 +56,14 @@ public class MqttReceiver implements AutoCloseable { ...@@ -54,6 +56,14 @@ public class MqttReceiver implements AutoCloseable {
logger.debug("Host is {}", this.host); logger.debug("Host is {}", this.host);
} }
public void setUsername(String username) {
this.username = username;
}
public void setPassword(String password) {
this.password = password;
}
public void setOnMessage(BiConsumer<String, String> callback) { public void setOnMessage(BiConsumer<String, String> callback) {
this.onMessageCallback = callback; this.onMessageCallback = callback;
} }
...@@ -101,6 +111,8 @@ public class MqttReceiver implements AutoCloseable { ...@@ -101,6 +111,8 @@ public class MqttReceiver implements AutoCloseable {
Objects.requireNonNull(this.host, "Host need to be set!"); Objects.requireNonNull(this.host, "Host need to be set!");
MQTT mqtt = new MQTT(); MQTT mqtt = new MQTT();
mqtt.setHost(this.host); mqtt.setHost(this.host);
mqtt.setPassword(this.password);
mqtt.setUserName(this.username);
connection = mqtt.callbackConnection(); connection = mqtt.callbackConnection();
AtomicReference<Throwable> error = new AtomicReference<>(); AtomicReference<Throwable> error = new AtomicReference<>();
connection.listener(new ExtendedListener() { connection.listener(new ExtendedListener() {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment