71 lines
2.0 KiB
Python
71 lines
2.0 KiB
Python
import os
|
|
|
|
from dotenv import load_dotenv
|
|
from flask import Flask
|
|
from pydantic import StrictStr
|
|
|
|
from src.controllers.mqtt_forwarder import MQTTForwarder
|
|
from src.services.mqtt_service import MQTTService
|
|
from board_mate.client import ClientApi, ApiClient, Configuration
|
|
from board_mate.client.models import ClientDto
|
|
from board_mate.client.exceptions import ApiException
|
|
|
|
client_id = "1"
|
|
load_dotenv()
|
|
|
|
app = Flask(__name__)
|
|
|
|
local_broker_address = os.environ.get("LOCAL_BROKER_ADDRESS", "127.0.0.1")
|
|
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))
|
|
|
|
@app.route('/')
|
|
def hello_world():
|
|
return 'Hello World!'
|
|
|
|
if __name__ == '__main__':
|
|
local_broker = MQTTService(
|
|
local_broker_address,
|
|
local_broker_port,
|
|
client_id="customer-api",
|
|
username="main",
|
|
password="hepl",
|
|
)
|
|
|
|
api_broker = MQTTService(
|
|
api_broker_address,
|
|
api_broker_port,
|
|
client_id="customer-api",
|
|
username="customer",
|
|
password="hepl",
|
|
)
|
|
|
|
forwarder = MQTTForwarder(client_id, local_broker, api_broker)
|
|
forwarder.start(f"/customer/telemetry/#", f"/board-mate/{client_id}/telemetry")
|
|
|
|
"""config = Configuration(
|
|
host="https://192.168.15.120:8000",
|
|
)
|
|
config.verify_ssl = False
|
|
|
|
with ApiClient(config) as api_client:
|
|
client_api = ClientApi(api_client)
|
|
|
|
new_client = ClientDto(
|
|
name=StrictStr("Alice Example"),
|
|
username=StrictStr("alice123"),
|
|
)
|
|
|
|
try:
|
|
# 5. Call the endpoint
|
|
response = client_api.create(client_dto=new_client)
|
|
print("Success:", response.success)
|
|
print("Message:", response.message)
|
|
print("Data:", response.data)
|
|
except ApiException as e:
|
|
print(f"Exception when calling ClientApi->create: {e}")"""
|
|
|
|
app.run(host="0.0.0.0", port=5000, debug=True)
|