Fix things

This commit is contained in:
2026-01-02 16:17:49 +01:00
parent 3399b5925e
commit 0cc827e1ce
5 changed files with 68 additions and 26 deletions

View File

@@ -5,10 +5,12 @@ from flask import Flask
from src.controllers.AuthController import AuthController
from src.controllers.ClientController import ClientController
from src.controllers.message_controller import MessageController
from src.controllers.mqtt_forwarder import MQTTForwarder
from src.models.AuthData import AuthData
from src.services.mqtt_service import MQTTService
client_id = "1"
client_id = "3b12678d-8d6f-444b-b1a7-671a2c92eabf"
load_dotenv()
app = Flask(__name__)
@@ -19,10 +21,6 @@ local_broker_port = int(os.environ.get("LOCAL_BROKER_PORT", 1883))
api_broker_address = os.environ.get("API_BROKER_ADDRESS", "127.0.0.1")
api_broker_port = int(os.environ.get("API_BROKER_PORT", 1883))
auth_controller = AuthController(app)
client_controller = ClientController(app)
if __name__ == '__main__':
local_broker = MQTTService(
local_broker_address,
local_broker_port,
@@ -39,6 +37,15 @@ if __name__ == '__main__':
password="hepl",
)
auth_data = AuthData()
auth_controller = AuthController(app, auth_data, "https://192.168.15.120:8000")
client_controller = ClientController(app, auth_data, "https://192.168.15.120:8000")
message_controller = MessageController(app, auth_data, "https://192.168.15.120:8000")
if __name__ == '__main__':
forwarder = MQTTForwarder(client_id, local_broker, api_broker)
forwarder.start(f"/customer/telemetry/#", f"/board-mate/{client_id}/telemetry")

View File

@@ -2,11 +2,17 @@ from board_mate.auth import *
from flask import jsonify, request
from pydantic import StrictStr
from src.models.AuthData import AuthData
class AuthController:
def __init__(self, app):
_auth_data : AuthData = None
def __init__(self, app, auth_data, host):
self._register_routes(app)
self.config = Configuration(host="https://192.168.15.120:8000")
self.config = Configuration(host=host)
self.auth_data = auth_data
self.config.verify_ssl = False
def _register_routes(self, app):
@@ -30,5 +36,5 @@ class AuthController:
return jsonify({"success" : response.success, "message" : response.message , "data" : response.data}), 200
except Exception as e:
print(f"Exception when calling AuthAPI->login: {e}")
return jsonify({"success" : response.success, "message" : response.message , "data" : response.data}), 500
return jsonify({"success" : False, "message" : e , "data" : null}), 500

View File

@@ -2,11 +2,17 @@ from board_mate.client import Configuration, ApiClient, ClientApi, ClientDto, Ap
from flask import jsonify, request
from pydantic import StrictStr
from src.models.AuthData import AuthData
class ClientController:
def __init__(self, app):
_auth_data : AuthData = None
def __init__(self, app, auth_data, host):
self._register_routes(app)
self.config = Configuration(host="https://192.168.15.120:8000")
self.config = Configuration(host=host)
self.auth_data = auth_data
self.config.verify_ssl = False
def _register_routes(self, app):

View File

@@ -1,7 +1,9 @@
import json
from board_mate.message import Configuration
from flask import jsonify, request
from src.models.AuthData import AuthData
from src.services.mqtt_service import MQTTService
@@ -9,10 +11,12 @@ class MessageController:
_mqtt_service : MQTTService = None
_client_id : MQTTService = None
_auth_data : AuthData = None
def __init__(self, client_id : str, service : MQTTService):
self._mqtt_service = service
self.client_id = client_id
def __init__(self, app, auth_data : AuthData, host : str):
self._register_routes(app)
self.config = Configuration(host=host)
self.auth_data = auth_data
def _register_routes(self, app):
app.add_url_rule("/message/send", view_func=self.send, methods=['POST'])
@@ -23,7 +27,7 @@ class MessageController:
msg = req["message"]
payload = json.dumps({"content" : msg})
print(payload)
self._mqtt_service.publish(f"/chat/${self.client_id}/message", payload)
self._mqtt_service.publish(f"/chat/${self.auth_data.get_client_id()}/message", payload)
return jsonify({"success" : True, "message": "An error occurred"}), 500
except Exception as e:
print(e)

View File

@@ -0,0 +1,19 @@
class AuthData:
_token : str
_client_id : str
def __init__(self):
pass
def get_token(self):
return self._token
def set_token(self, token:str):
self._token = token
def get_client_id(self):
return self._client_id
def set_client_id(self, client_id:str):
self._client_id = client_id