From 27efacd9a70bd604b142126d4c6f4cf982a6a251 Mon Sep 17 00:00:00 2001 From: Fredrik Olsson Date: Fri, 20 Oct 2023 10:48:44 +0200 Subject: [PATCH] Removing python examples from this repository. Refer to https://github.com/MO-RISE/pontos-examples --- examples/README.md | 15 -------- examples/publisher-python/publisher.py | 41 --------------------- examples/requirements.txt | 1 - examples/subscriber-python/subscriber.py | 45 ------------------------ 4 files changed, 102 deletions(-) delete mode 100644 examples/README.md delete mode 100644 examples/publisher-python/publisher.py delete mode 100644 examples/requirements.txt delete mode 100644 examples/subscriber-python/subscriber.py diff --git a/examples/README.md b/examples/README.md deleted file mode 100644 index aa90fb0..0000000 --- a/examples/README.md +++ /dev/null @@ -1,15 +0,0 @@ -# Examples -This folder contains a set of example scripts that serve as a combination of documentation as well as a starting point, code-wise, for integration with the PONTOS datahub. - - -**Requirements** - -- Python requirements can be found in the `requirements.txt` file in this folder - -## Publisher (Python) - -A python publisher using the paho mqtt library. - -## Subscriber (Python) - -A python subscriber using the paho mqtt library \ No newline at end of file diff --git a/examples/publisher-python/publisher.py b/examples/publisher-python/publisher.py deleted file mode 100644 index 096f2e5..0000000 --- a/examples/publisher-python/publisher.py +++ /dev/null @@ -1,41 +0,0 @@ -"Publisher example for PONTOS datahub" -import time -import json -import logging -from paho.mqtt.client import Client - -HOST = "hostname" -PORT = 1234 -PATH = "/path" -USERNAME = "username" -PASSWORD = "password" - -logging.basicConfig( - format="%(asctime)s %(levelname)s %(name)s %(message)s", level=logging.DEBUG -) - -# Create client, explicitly specifying that the transport protocol should be websockets -client = Client(transport="websockets") - -client.enable_logger(logging.getLogger("paho")) - -# Specify the path where the broker listens for websocket connections -client.ws_set_options(path=PATH) - -# Force transport protcol encryption through TLS (i.e. wss) -client.tls_set() - -# Set username and password to be used for client auth upon connection -client.username_pw_set(USERNAME, PASSWORD) - -# Connect to client using the correct hostname and port -if client.connect(HOST, PORT) > 0: - raise ConnectionRefusedError("Failed to connect to PONTOS!") - -# Run a background thread keeping track of heartbeats, reconnections etc -client.loop_start() - -while True: - client.publish("examples/producer", json.dumps({"alive": "yes"})) - time.sleep(1) - diff --git a/examples/requirements.txt b/examples/requirements.txt deleted file mode 100644 index d173f65..0000000 --- a/examples/requirements.txt +++ /dev/null @@ -1 +0,0 @@ -paho-mqtt \ No newline at end of file diff --git a/examples/subscriber-python/subscriber.py b/examples/subscriber-python/subscriber.py deleted file mode 100644 index c7e5af3..0000000 --- a/examples/subscriber-python/subscriber.py +++ /dev/null @@ -1,45 +0,0 @@ -"Subscriber example for PONTOS datahub" -import logging -from paho.mqtt.client import Client - -HOST = "hostname" -PORT = 1234 -PATH = "/path" -USERNAME = "username" -PASSWORD = "password" - -logging.basicConfig( - format="%(asctime)s %(levelname)s %(name)s %(message)s", level=logging.DEBUG -) - -# Create client, explicitly specifying that the transport protocol should be websockets -client = Client(transport="websockets") - -client.enable_logger(logging.getLogger("paho")) - -# Specify the path where the broker listens for websocket connections -client.ws_set_options(path=PATH) - -# Force transport protcol encryption through TLS (i.e. wss) -client.tls_set() - -# Set username and password to be used for client auth upon connection -client.username_pw_set(USERNAME, PASSWORD) - -@client.connect_callback() -def on_connect( - client, userdata, flags, reason_code -): - client.subscribe("examples/producer") - -# Connect to client using the correct hostname and port -if client.connect(HOST, PORT) > 0: - raise ConnectionRefusedError("Failed to connect to PONTOS!") - - -@client.message_callback() -def on_message(client, userdata, message): - logging.info("Got message %s on topic %s", message.payload, message.topic) - -# Blocking function that keep track of hearbeats, reconnections etc -client.loop_forever() \ No newline at end of file