Skip to content

Commit

Permalink
Add MQTT authorization
Browse files Browse the repository at this point in the history
  • Loading branch information
TheMrBooyah committed Nov 24, 2022
1 parent 94f2ab6 commit 40d69c1
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ public class MqttBridge extends org.eclipse.paho.client.mqttv3.MqttClient {
public MqttBridge(
@Value("${dirigera.mqtt.hostname:localhost}") final String host,
@Value("${dirigera.mqtt.port:1883}") final Short port,
@Value("${dirigera.mqtt.username:}") final String username,
@Value("${dirigera.mqtt.password:}") final String password,
@Value("${dirigera.mqtt.reconnect:true}") final Boolean reconnect,
@Value("${dirigera.mqtt.timeout:10}") final Integer timeout,
final DirigeraApi api) throws MqttException {
Expand All @@ -38,6 +40,11 @@ public MqttBridge(
options.setAutomaticReconnect(reconnect);
options.setCleanSession(true);
options.setConnectionTimeout(timeout);

if (!username.isEmpty() && !password.isEmpty()) {
options.setUserName(username);
options.setPassword(password.toCharArray());
}
this.connect(options);

log.info("Connection to MQTT broker successfully established");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
spring.application.name=Dirigera Dump
spring.application.name=Dirigera MQTT
logging.level.root=error
logging.level.de.dvdgeisler.iot.dirigera=debug
spring.main.web-application-type=none
Expand Down

0 comments on commit 40d69c1

Please sign in to comment.