|
@@ -1,16 +1,21 @@
|
|
|
+import os
|
|
|
import paho.mqtt.client as mqtt
|
|
|
-import paho.mqtt.subscribe as subscribe
|
|
|
import json
|
|
|
+from dotenv import load_dotenv
|
|
|
|
|
|
+# Load the .env file
|
|
|
+load_dotenv()
|
|
|
|
|
|
-def create_client(broker: str, port: int, username: str, password: str) -> mqtt.Client:
|
|
|
- """Create an MQTT client and connect it to the broker
|
|
|
+# Define the MQTT server details
|
|
|
+broker = os.environ.get("broker")
|
|
|
+port = int(os.environ.get("port"))
|
|
|
+# MQTT username and password
|
|
|
+username = os.environ.get("username")
|
|
|
+password = os.environ.get("password")
|
|
|
|
|
|
- Args:
|
|
|
- broker (str): MQTT broker address
|
|
|
- port (int): MQTT broker port
|
|
|
- username (str): Username for MQTT broker
|
|
|
- password (str): Password for MQTT broker
|
|
|
+
|
|
|
+def create_client() -> mqtt.Client:
|
|
|
+ """Create an MQTT client and connect it to the broker
|
|
|
|
|
|
Returns:
|
|
|
mqtt.Client: Connected MQTT client instance
|