Conexion to sim #560
-
|
Hi everyone, I'm building a FastAPI endpoint to send commands to BlueSky. My client connects to the simulator (for example, it shows "Client b'\x00| \r\x1e' connected to host b'\x00\xef}W\xdf"), and the endpoint confirms that the command was been sent successfully. However, no airplane is created. I’ve verified that the simulation is running and taxi mode is enabled. Does anyone know why the commands are reaching the stack function but aren’t executed by the simulator? def stack(self, text: str):
print("Sending command:", text)
self.send_event(b'STACKCMD', data=text)Note: I built the plugin below based on the approach followed in Example implementation: A simple text client and the only purpose is to pass commands to the sim. this is my plugin from bluesky.network.client import Client
class SimpleCLIClient(Client):
def __init__(self):
super().__init__()
# Connect to simulator
self.connect(event_port=11000, stream_port=11001)
def event(self, name, data, sender_id):
print(f"Event received: {name}, data: {data}")
def stack(self, text: str):
print("Sending command:", text)
self.send_event(b'STACKCMD', data=text)and main for running the plugin # main.py
import threading
import uvicorn
from fastapi import FastAPI
from scr.router.endpoints import router as core_router
from bluesky.__main__ import main as bluesky_main
from scr.services.init_client import SimpleCLIClient
# FastAPI and add routes
api = FastAPI()
api.include_router(core_router)
def run_fastapi():
uvicorn.run(api, host="127.0.0.1", port=8000, log_level="info")
def run_bsclient():
# Initialize and connect the BlueSky client
bsclient = SimpleCLIClient()
# Assign the client instance to the FastAPI application state
api.state.bsclient = bsclient
if __name__ == "__main__":
# Start the FastAPI server
fastapi_thread = threading.Thread(target=run_fastapi, daemon=True)
fastapi_thread.start()
# Start the BlueSky client connection in a separate thread
client_thread = threading.Thread(target=run_bsclient, daemon=True)
client_thread.start()
# Keep the main thread active
fastapi_thread.join() |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
|
Hi @Santisoutoo, First off, the example you used is unfortunately outdated. I immediately updated it to reflect the changes from BlueSky's recent networking update. Secondly, I think you are not calling |
Beta Was this translation helpful? Give feedback.
-
|
Thank you, I really appreciate your efforts in keeping the wiki up to date. |
Beta Was this translation helpful? Give feedback.
Hi @Santisoutoo,
First off, the example you used is unfortunately outdated. I immediately updated it to reflect the changes from BlueSky's recent networking update. Secondly, I think you are not calling
Client.update(). This function needs to be periodically called so that the client checks for new incoming data.