Skip to content
Snippets Groups Projects
Commit 28fdb268 authored by Matthias Stefan Bodenbenner's avatar Matthias Stefan Bodenbenner
Browse files

V 2.5.3

parent 82ef4d2b
Branches
No related tags found
No related merge requests found
Pipeline #254907 passed
# WZL-MQTT # WZL-MQTT
Current stable version: 2.5.2 Current stable version: 2.5.3
## Documentation ## Documentation
...@@ -79,6 +79,11 @@ while True: ...@@ -79,6 +79,11 @@ while True:
## Changelog ## 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 **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 - client handles slash in at the end of prefix and the beginning of topic to avoid multiple consecutive slashes correctly now
......
# WZL-MQTT # WZL-MQTT
Current stable version: 2.5.2 Current stable version: 2.5.3
## Documentation ## Documentation
...@@ -90,6 +90,10 @@ the European Union’s Horizon 2020 research and innovation programme and the EM ...@@ -90,6 +90,10 @@ the European Union’s Horizon 2020 research and innovation programme and the EM
## Changelog ## 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 **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 - client handles slash in at the end of prefix and the beginning of topic to avoid multiple consecutive slashes correctly now
......
...@@ -4,7 +4,7 @@ with open("PyPI-README.md", "r", encoding="utf-8") as fh: ...@@ -4,7 +4,7 @@ with open("PyPI-README.md", "r", encoding="utf-8") as fh:
long_description = fh.read() long_description = fh.read()
setup(name='wzl-mqtt', setup(name='wzl-mqtt',
version='2.5.2', version='2.5.3',
url='https://git-ce.rwth-aachen.de/wzl-mq-public/iot/mqtt/', url='https://git-ce.rwth-aachen.de/wzl-mq-public/iot/mqtt/',
project_urls={ project_urls={
"Bug Tracker": "https://git-ce.rwth-aachen.de/wzl-mq-public/iot/mqtt/-/issues", "Bug Tracker": "https://git-ce.rwth-aachen.de/wzl-mq-public/iot/mqtt/-/issues",
......
...@@ -97,19 +97,35 @@ class MQTTClient: ...@@ -97,19 +97,35 @@ class MQTTClient:
If not given explicitly given, the port automatically resolved from the values of "websocket" and "ssl". If not given explicitly given, the port automatically resolved from the values of "websocket" and "ssl".
""" """
try:
address = broker address = broker
try:
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 port == 0:
if ssl: if ssl:
port = 443 if websocket else 8883 port = 443 if websocket else 8883
else: else:
port = 80 if websocket else 1883 port = 80 if websocket else 1883
if ssl: 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() self._client.tls_set()
if websocket: 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" self._client._transport = "websockets"
fields = address.split("/") fields = address.split("/")
address = fields[0] address = fields[0]
...@@ -147,7 +163,7 @@ class MQTTClient: ...@@ -147,7 +163,7 @@ class MQTTClient:
def _on_connect(self, client, userdata, flags, rc): def _on_connect(self, client, userdata, flags, rc):
if rc == 0: if rc == 0:
self._logger.info( self._logger.info(
"MQTT Client {} connect terminated with code {} ({}).".format( "MQTT Client {} connected successfully (code {}: {}).".format(
self.name, rc, mqtt.error_string(rc))) self.name, rc, mqtt.error_string(rc)))
self._connected = True self._connected = True
else: else:
......
...@@ -8,11 +8,11 @@ from src import mqtt ...@@ -8,11 +8,11 @@ from src import mqtt
### Ask for settings and individual credentials ### ### Ask for settings and individual credentials ###
MQTT_USER = "" MQTT_USER = "bdn-aafdecf0-a14c-4cb5-bb08-3844399e0a25"
MQTT_PASSWORD = "" MQTT_PASSWORD = "azesR4Q8~M7UBKh<7S~d\"NN-|)i9:Le["
MQTT_BROKER = "mqtt.wzl-mq.rwth-aachen.de" MQTT_BROKER = "mqtt.wzl-mq.rwth-aachen.de"
MQTT_PORT = 8883 MQTT_PORT = "0"
MQTT_VHOST = "metrology" MQTT_VHOST = "metrology"
### to connect to the central MQTT-Broker of MQ-MS use the following settings: ### to connect to the central MQTT-Broker of MQ-MS use the following settings:
...@@ -25,7 +25,7 @@ MQTT_VHOST = "metrology" ...@@ -25,7 +25,7 @@ MQTT_VHOST = "metrology"
if __name__ == "__main__": if __name__ == "__main__":
client = mqtt.MQTTPublisher(prefix="bdn-212d8419-c75c-471f-8ea5-f3a5c19ac42e") 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: while True:
try: try:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment