Skip to content

Commit

Permalink
Merge pull request #23 from fledge-iot/2.2.0RC
Browse files Browse the repository at this point in the history
2.2.0RC
  • Loading branch information
dianomicbot committed Oct 20, 2023
2 parents 8cf5bde + 38c4816 commit c2c3c82
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 14 deletions.
4 changes: 2 additions & 2 deletions VERSION.south.mqtt-readings
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
fledge_south_mqtt-readings_version=2.1.0
fledge_version>=2.1
fledge_south_mqtt-readings_version=2.2.0
fledge_version>=2.2
Binary file modified docs/images/mqtt-sub.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ To create a south service you, as with any other south plugin

- **MQTT Broker Port**: The network port of the broker.

- **Username**: Username for broker authentication.

- **Password**: Password for broker authentication.

- **Keep Alive Interval**: Maximum period in seconds allowed between communications with the broker. If no other messages are being exchanged, this controls the rate at which the client will send ping messages to the broker.

- **Topic To Subscribe**: The subscription topic to subscribe to receive messages.
Expand Down
37 changes: 25 additions & 12 deletions python/fledge/plugins/south/mqtt-readings/mqtt-readings.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,6 @@
Topic is required, all other parameters are optional and will default to None, 0 and False respectively.
Defaults to None, which indicates no will should be used.
auth
a dict containing authentication parameters for the client:
auth = {‘username’:”<username>”, ‘password’:”<password>”}
Defaults to None, which indicates no authentication is to be used.
tls
a dict containing TLS configuration parameters for the cient:
Expand Down Expand Up @@ -97,27 +91,41 @@
'displayName': 'MQTT Broker Port',
'mandatory': 'true'
},
'username': {
'description': 'Username for broker authentication',
'type': 'string',
'default': '',
'order': '3',
'displayName': 'Username'
},
'password': {
'description': 'Password for broker authentication',
'type': 'string',
'default': '',
'order': '4',
'displayName': 'Password'
},
'keepAliveInterval': {
'description': 'Maximum period in seconds allowed between communications with the broker. If no other messages are being exchanged, '
'this controls the rate at which the client will send ping messages to the broker.',
'type': 'integer',
'default': '60',
'order': '3',
'order': '5',
'displayName': 'Keep Alive Interval'
},
'topic': {
'description': 'The subscription topic to subscribe to receive messages',
'type': 'string',
'default': 'Room1/conditions',
'order': '4',
'order': '6',
'displayName': 'Topic To Subscribe',
'mandatory': 'true'
},
'qos': {
'description': 'The desired quality of service level for the subscription',
'type': 'integer',
'default': '0',
'order': '5',
'order': '7',
'displayName': 'QoS Level',
'minimum': '0',
'maximum': '2'
Expand All @@ -126,7 +134,7 @@
'description': 'Name of Asset',
'type': 'string',
'default': 'mqtt-',
'order': '6',
'order': '8',
'displayName': 'Asset Name',
'mandatory': 'true'
}
Expand All @@ -136,7 +144,7 @@
def plugin_info():
return {
'name': 'MQTT Subscriber',
'version': '2.1.0',
'version': '2.2.0',
'mode': 'async',
'type': 'south',
'interface': '1.0',
Expand Down Expand Up @@ -234,12 +242,14 @@ def plugin_register_ingest(handle, callback, ingest_ref):
class MqttSubscriberClient(object):
""" mqtt listener class"""

__slots__ = ['mqtt_client', 'broker_host', 'broker_port', 'topic', 'qos', 'keep_alive_interval', 'asset', 'loop']
__slots__ = ['mqtt_client', 'broker_host', 'broker_port', 'username', 'password', 'topic', 'qos', 'keep_alive_interval', 'asset', 'loop']

def __init__(self, config):
self.mqtt_client = mqtt.Client()
self.broker_host = config['brokerHost']['value']
self.broker_port = int(config['brokerPort']['value'])
self.username = config['username']['value']
self.password = config['password']['value']
self.topic = config['topic']['value']
self.qos = int(config['qos']['value'])
self.keep_alive_interval = int(config['keepAliveInterval']['value'])
Expand Down Expand Up @@ -271,6 +281,9 @@ def on_unsubscribe(self, client, userdata, mid):
pass

def start(self):
if self.username and len(self.username.strip()) and self.password and len(self.password):
# no strip on pwd len check, as it can be all spaces?!
self.mqtt_client.username_pw_set(self.username, password=self.password)
# event callbacks
self.mqtt_client.on_connect = self.on_connect

Expand Down

0 comments on commit c2c3c82

Please sign in to comment.