diff --git a/PyPI-README.md b/PyPI-README.md index ffe72ffde94cc1553460bf6a0d54b15b67b0de1d..af026898da27f78e9833e57e6713b8c1364ca9e4 100644 --- a/PyPI-README.md +++ b/PyPI-README.md @@ -1,6 +1,6 @@ # WZL-MQTT -Current stable version: 2.5.2 +Current stable version: 2.5.3 ## Documentation @@ -79,6 +79,11 @@ while True: ## Changelog +**2.5.3** - 2023-04-15 + - if the port is specified as string it is also correctly processed now + - improved user feedback in case of successful connection to the broker + - improved user feedback if the combination of port, ssl and websocket is invalid + **2.5.2** - 2023-03-29 - client handles slash in at the end of prefix and the beginning of topic to avoid multiple consecutive slashes correctly now diff --git a/README.md b/README.md index 75544dad0ab07f8615e490d65512470155dfc8bd..2c1ea955d171320bc96553a11ca9a92d32b02a55 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # WZL-MQTT -Current stable version: 2.5.2 +Current stable version: 2.5.3 ## Documentation @@ -90,6 +90,10 @@ the European Union’s Horizon 2020 research and innovation programme and the EM ## Changelog +**2.5.3** - 2023-04-15 + - if the port is specified as string it is also correctly processed now + - improved logging output in case of successful connection to the broker + **2.5.2** - 2023-03-29 - client handles slash in at the end of prefix and the beginning of topic to avoid multiple consecutive slashes correctly now diff --git a/setup.py b/setup.py index 7ce09fe42a1b0dfcebbcc51036ebac458a4c5010..3a799fc6e3bc9bc9d35fed0789532b29c382c3a7 100644 --- a/setup.py +++ b/setup.py @@ -4,7 +4,7 @@ with open("PyPI-README.md", "r", encoding="utf-8") as fh: long_description = fh.read() setup(name='wzl-mqtt', - version='2.5.2', + version='2.5.3', url='https://git-ce.rwth-aachen.de/wzl-mq-public/iot/mqtt/', project_urls={ "Bug Tracker": "https://git-ce.rwth-aachen.de/wzl-mq-public/iot/mqtt/-/issues", diff --git a/src/mqtt/client.py b/src/mqtt/client.py index a9730d8819b3bb98b5d8b37c02ecc0b42338a4ab..cdb05ad966aa99d10f3af9975f4a1f3ff73f6c9a 100644 --- a/src/mqtt/client.py +++ b/src/mqtt/client.py @@ -97,19 +97,35 @@ class MQTTClient: If not given explicitly given, the port automatically resolved from the values of "websocket" and "ssl". """ + + address = broker try: - address = broker + if isinstance(port, str): + port = int(port) + except Exception as exception: + self._logger.error(f"Specified port \"{port}\" is invalid. Port must be of type string or integer. Exiting...") + exit() + try: if port == 0: if ssl: port = 443 if websocket else 8883 else: port = 80 if websocket else 1883 + if ssl: + if port not in [8883, 443]: + self._logger.error( + f"Can not connect to the broker. If ssl is set, the port must be \"8883\" (or \"443\" in case websockets are used), but specified port is \"{port}\". Exiting...") + exit() self._client.tls_set() if websocket: + if port not in [80, 443]: + self._logger.error( + f"Can not connect to the broker. If websocket is set, the port must be \"80\" (or \"443\" in case ssl is used), but specified port is \"{port}\". Exiting...") + exit() self._client._transport = "websockets" fields = address.split("/") address = fields[0] @@ -147,7 +163,7 @@ class MQTTClient: def _on_connect(self, client, userdata, flags, rc): if rc == 0: self._logger.info( - "MQTT Client {} connect terminated with code {} ({}).".format( + "MQTT Client {} connected successfully (code {}: {}).".format( self.name, rc, mqtt.error_string(rc))) self._connected = True else: diff --git a/test/publish.py b/test/publish.py index 926458ec830a94b2c04c2a244d85bb4d9673a1fb..ffdabd0a8eed6cb705b9caaf27d4e621dbb9985f 100644 --- a/test/publish.py +++ b/test/publish.py @@ -8,11 +8,11 @@ from src import mqtt ### Ask for settings and individual credentials ### -MQTT_USER = "" -MQTT_PASSWORD = "" +MQTT_USER = "bdn-aafdecf0-a14c-4cb5-bb08-3844399e0a25" +MQTT_PASSWORD = "azesR4Q8~M7UBKh<7S~d\"NN-|)i9:Le[" MQTT_BROKER = "mqtt.wzl-mq.rwth-aachen.de" -MQTT_PORT = 8883 +MQTT_PORT = "0" MQTT_VHOST = "metrology" ### to connect to the central MQTT-Broker of MQ-MS use the following settings: @@ -25,7 +25,7 @@ MQTT_VHOST = "metrology" if __name__ == "__main__": client = mqtt.MQTTPublisher(prefix="bdn-212d8419-c75c-471f-8ea5-f3a5c19ac42e") - client.connect(MQTT_BROKER, MQTT_PORT, MQTT_USER, MQTT_PASSWORD, vhost=MQTT_VHOST, ssl=True) + client.connect(MQTT_BROKER, MQTT_USER, MQTT_PASSWORD, vhost=MQTT_VHOST, port=MQTT_PORT, ssl=True) while True: try: