65 lines
2.0 KiB
Python
65 lines
2.0 KiB
Python
import os
|
||
import uuid
|
||
|
||
from flask import Flask
|
||
from src.controllers.mqtt_forwarder import MQTTForwarder
|
||
from src.services.mqtt_service import MQTTService
|
||
from openapi_client import ApiClient, Configuration
|
||
from openapi_client.api.default_api import DefaultApi # Remplace DefaultApi par le nom de ton endpoint
|
||
|
||
client_id = "1"
|
||
|
||
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")
|
||
|
||
# main.py
|
||
|
||
|
||
# 1️⃣ Configurer la connexion à l'API
|
||
config = Configuration(
|
||
host="https://api.monservice.com", # URL de ton API
|
||
api_key={"Authorization": "Bearer TON_TOKEN"} # Ton token Bearer si nécessaire
|
||
)
|
||
|
||
# 2️⃣ Créer le client et appeler l'API
|
||
with ApiClient(config) as client:
|
||
api_instance = DefaultApi(client) # Remplace par UsersApi, PetsApi, etc. selon ton endpoint
|
||
|
||
try:
|
||
# Appel de l'endpoint GET (méthode générée automatiquement)
|
||
response = api_instance.get_users() # Remplace par la méthode générée correspondant à ton endpoint
|
||
print("Réponse de l'API :", response)
|
||
except Exception as e:
|
||
print("Erreur lors de la requête :", e)
|
||
|
||
app.run(host="0.0.0.0", port=5000, debug=False)
|