diff --git a/README.md b/README.md index b121047542072fc0a52746e69a33072996e58e22..471cf0d5bdd1e5e2baee87f26534d0a9d8282efd 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ # WZL-MQTT [](https://git-ce.rwth-aachen.de/wzl-mq-ms/forschung-lehre/digital-mars/mqtt/badges/master) -Current stable version: 2.4.1 +Current stable version: 2.4.2 ## Installation Requires at least Python 3.6 @@ -79,6 +79,9 @@ To obtain credentials for MQTT-Broker of WZL-MQ-MS contact [Mark Sanders](mailto For more detailed explanation and full API documentation, view [https://iot.wzl-mq.rwth-aachen.de/documentation/libs/mqtt/](https://iot.wzl-mq.rwth-aachen.de/documentation/libs/mqtt/) ## Changelog +2.4.2 +- fixed a bug of websocket connection + 2.4.1 - made the error message of code 1 more precise diff --git a/private_testing/publish.py b/private_testing/publish.py deleted file mode 100644 index 7842d210a4f3506b36f150e4e3648414c5302301..0000000000000000000000000000000000000000 --- a/private_testing/publish.py +++ /dev/null @@ -1,39 +0,0 @@ -import datetime -import json -import random -import time -import uuid - -from src.mqtt import Logger -from src import mqtt - -### Ask for settings and individual credentials ### - -MQTT_USER = "bdn-212d8419-c75c-471f-8ea5-f3a5c19ac42e" -MQTT_PASSWORD = "azesR4Q8~M7UBKh<7S~d\"NN-|)i9:Le[" - -MQTT_BROKER = "mqtt.wzl-mq.rwth-aachen.de" -MQTT_PORT = 8883 -MQTT_VHOST = "metrology" - -### to connect to the central MQTT-Broker of MQ-MS use the following settings: -# MQTT_BROKER = "wzl-mbroker01.wzl.rwth-aachen.de" -# MQTT_PORT = 1883 -# MQTT_VHOST = "metrology" - -### Ask for settings and individual credentials ### - - -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) - - while True: - try: - message = json.dumps({"value": [random.uniform(0, 5) for i in range(3)], "timestamp": datetime.datetime.utcnow().isoformat() + "Z", - "covariance": [[2, 0, 0], [0, 2, 0], [0, 0, 0]], "nonce": str(uuid.uuid4()), "hash": None, "unit": "MTR"}) - client.publish("channel-001", message.encode("utf-8"), 2) - time.sleep(1) - except KeyboardInterrupt: - break diff --git a/private_testing/receive.py b/private_testing/receive.py deleted file mode 100644 index d08d8ae8dfaf0eda23ee7044f886b3bd2ca55015..0000000000000000000000000000000000000000 --- a/private_testing/receive.py +++ /dev/null @@ -1,42 +0,0 @@ -import time - -from src.mqtt import Logger -from src import mqtt - -### Ask for settings and individual credentials ### - -MQTT_USER = "bdn-212d8419-c75c-471f-8ea5-f3a5c19ac42e" -MQTT_PASSWORD = "azesR4Q8~M7UBKh<7S~d\"NN-|)i9:Le[" - -MQTT_BROKER = "mqtt.wzl-mq.rwth-aachen.de" -MQTT_PORT = 8883 -MQTT_VHOST = "metrology" - -## to connect to the central MQTT-Broker of MQ-MS use the following settings: -# MQTT_BROKER = "wzl-mbroker01.wzl.rwth-aachen.de" -# MQTT_PORT = 1883 -# MQTT_VHOST = "metrology" - -### Ask for settings and individual credentials ### - -topic = "#" # set topic to subscribe according to MQTT syntax! -qos = 0 # set QoS according to MQTT specifications! - -logger = Logger() - -def print_mqtt_message(topic, message): - logger.get('Receiver').info("### {} ###\r\n{}\r\n".format(topic, message.decode("utf-8"))) - -if __name__=="__main__": - client = mqtt.MQTTSubscriber(prefix="bdn-212d8419-c75c-471f-8ea5-f3a5c19ac42e", logger=logger) - client.connect(MQTT_BROKER, MQTT_PORT, MQTT_USER, MQTT_PASSWORD, vhost=MQTT_VHOST) - - client.set_callback("PRINT", print_mqtt_message) - # client.subscribe(topic, qos) - - while True: - try: - time.sleep(1) - except KeyboardInterrupt: - break - diff --git a/setup.py b/setup.py index cc01c2f5571b2eb75171e06bfd244c332f71230d..0a3325aa02959035076fcf4e9716170a9ddd7ad0 100644 --- a/setup.py +++ b/setup.py @@ -1,7 +1,7 @@ from setuptools import setup, find_packages setup(name='wzl-mqtt', - version='2.4.1', + version='2.4.2', url='', author='Benjamin Montavon, Matthias Bodenbenner', author_email='m.bodenbenner@wzl.rwth-aachen.de', diff --git a/src/mqtt/client.py b/src/mqtt/client.py index ba065ca1ec84790a053a85fad18069b1b29238a6..4ab774f2d49b8e372788d087b42c3bbdfc3d8442 100644 --- a/src/mqtt/client.py +++ b/src/mqtt/client.py @@ -96,19 +96,23 @@ class MQTTClient: """ try: address = broker + if ssl: self._client.tls_set() + if websocket: self._client._transport = "websockets" fields = address.split("/") address = fields[0] path = "/".join(fields[1:]) - self._client.ws_set_options(path=path) + print(address, path) + self._client.ws_set_options(path=f'/{path}') if vhost != '' and vhost != '/': self._client.username_pw_set(f'{vhost}:{username}', password) else: self._client.username_pw_set(username, password) + self._client.connect(address, port, keep_alive) except Exception as exception: