Skip to content

Commit

Permalink
Merge pull request #539 from JonasArnold/develop
Browse files Browse the repository at this point in the history
added possibility to configure login data for mqtt broker
  • Loading branch information
Schrolli91 authored Mar 14, 2022
2 parents c75a807 + 278b536 commit e057a8b
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
##### Added
- Functionality to fill coordinate values in POC data structure (lat, lon) based on configured locations that match a regular expression in POC message [#510](https://github.com/Schrolli91/BOSWatch/pull/510)
- Extending POC data-structure by Regex named groups matching. [#508](https://github.com/Schrolli91/BOSWatch/pull/508)
- MQTT Plugin: Added possibility to configure login (user and password) for mqtt broker. [#539](https://github.com/Schrolli91/BOSWatch/pull/539)
##### Changed
##### Deprecated
##### Removed
Expand Down
3 changes: 3 additions & 0 deletions config/config.template.ini
Original file line number Diff line number Diff line change
Expand Up @@ -596,6 +596,9 @@ commandPOC =
#Adress from MQTT-Broker
brokeraddress = 192.168.178.27
topic = alarm/data
# username and password for the broker. leave username empty to use anonymous login
brokerusername =
brokerpassword =

#####################
##### Not ready yet #
Expand Down
12 changes: 11 additions & 1 deletion plugins/mqtt/mqtt.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,11 @@ def run(typ,freq,data):
########## User Plugin CODE ##########
broker_address = globalVars.config.get("mqtt", "brokeraddress")
topic = globalVars.config.get("mqtt", "topic")
mqttClient = mqtt.Client()

broker_username = globalVars.config.get("mqtt", "brokerusername")
broker_password = globalVars.config.get("mqtt", "brokerpassword")

mqttClient = mqtt.Client()

if typ == "FMS":
x = {
Expand Down Expand Up @@ -112,6 +116,12 @@ def run(typ,freq,data):
logging.warning("Invalid Typ: %s", typ)

y = json.dumps(x)


## only login if there is a username given
if( len(broker_username) > 0 ):
mqttClient.username_pw_set(broker_username, broker_password)

mqttClient.connect(broker_address)
mqttClient.publish(topic,y)
########## User Plugin CODE ##########
Expand Down

0 comments on commit e057a8b

Please sign in to comment.