> For the complete documentation index, see [llms.txt](https://developer.fotokite.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://developer.fotokite.com/code-examples/flight-telemetry.md).

# Flight Telemetry

This section explains how to use the flight control capabilities of the API. It includes examples for subscribing to live data and sending flight commands, providing precise, real-time control of the system.

For more details, see [Flight](/fotokite-api/flight.md) or the [GitHub repository](https://github.com/fotokite/fotokite-api/tree/main/example/).

### Subscribe flight state

Provides real-time data about the system’s operational status. By using the flight state information, applications can monitor system performance, ensure operation within safe limits, and more.

```python
def flight_telemetry(
 on_message_callback: Callable[[dict[str, object]], None],
    access_token: str = "",
    max_messages: int | None = None,
) -> None:
    """Subscribes to flight telemetry updates from the System.
​
    Args:
        on_message_callback: Callback function to handle incoming telemetry messages.
        access_token: The authentication token to use in the websocket connection.
        max_messages: Maximum number of messages to receive before unsubscribing. Defaults to None(read forever).
    """
    ws_url = f"{BASE_WEBSOCKET_API_URL}/telemetry/flight/subscribe"
    try:
        with connect(
            ws_url, additional_headers={"Authorization": f"Bearer {access_token}"}
        ) as websocket:
            logging.info("Connected to flight telemetry")
            count = 0
            while True:
                message = websocket.recv()
                data = json.loads(message)
                on_message_callback(data)
                count += 1
                if max_messages is not None and count >= max_messages:
                    break
    except Exception as e:
        logging.error(f"Error in flight telemetry: {e}")
```

### **Flight control**

To control the system, you must use the endpoints in the `/control` namespace. It is important to note that these endpoints are part of the Control Handoff mechanism. Control Handoff ensures that only one client can control the system at any given time. Before using any endpoint in the `/control` namespace, the API must first request control.

The API does not block or wait for a command to complete. Command execution must be verified through flight state data, which indicates changes in the aircraft’s status.

The example demonstrates how to send a take off command.

```python
def take_off(access_token: str) -> bool:
    """Sends a take off command to the Ground Station.
    Args:
        access_token: The authentication token to use in the request.
    Returns:
        True if the take off command was sent successfully (HTTP 200), False otherwise.
        This does not guarantee that the Kite will take off, only that the command was sent successfully.
        To check if the Kite has taken off, monitor the flight telemetry.​
    """
    try:
        # Tries to retrieve handoff control before sending a command. If handoff retrieval fails then it will raise an exception.
        retrieve_handoff(access_token)
        
        headers = {"Authorization": f"Bearer {access_token}"}
        response = requests.post(
            f"{BASE_REST_API_URL}/flight/take_off", headers=headers
        )
​
        if response.status_code == 200:
            logging.info("Take off command sent successfully.")
            return True
        else:
            logging.error(f"Error sending take off command: {response.text}")
    except Exception as e:
        logging.error(f"Exception in take_off: {e}")
        
    return False
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://developer.fotokite.com/code-examples/flight-telemetry.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
