Drone. Adapters. Tello. Connection
(ex_drone v0.3.0)
View Source
UDP connection helper for the Tello drone.
Manages a :gen_udp socket for sending SDK command strings and receiving
ASCII responses over Wi-Fi. Defaults match the official Tello SDK network:
| Constant | Default |
|---|---|
| Drone IP | {192, 168, 10, 1} |
| Drone port | 8889 |
| Local bind port | 8889 |
| Reply timeout | 10_000 ms |
Examples
{:ok, socket} = Drone.Adapters.Tello.Connection.open(local_port: 9030)
{:ok, "ok"} =
Drone.Adapters.Tello.Connection.send_command(socket, "command",
drone_ip: {192, 168, 10, 1},
timeout: 5_000
)
:ok = Drone.Adapters.Tello.Connection.close(socket)
Summary
Functions
Closes a UDP socket opened with open/1.
Default Tello station IP address.
Default Tello command UDP port.
Default local UDP bind port.
Default command reply timeout in milliseconds.
Opens a passive UDP socket bound to the local port.
Receives one UDP datagram from the Tello (or times out).
Sends a command string and waits for one UDP reply.
Functions
@spec close(port()) :: :ok
Closes a UDP socket opened with open/1.
Parameters
socket(port()) — socket fromopen/1
Returns
Always :ok.
Examples
:ok = Drone.Adapters.Tello.Connection.close(socket)
@spec default_drone_ip() :: :inet.ip_address()
Default Tello station IP address.
Returns
:inet.ip_address() — {192, 168, 10, 1}.
Examples
{192, 168, 10, 1} = Drone.Adapters.Tello.Connection.default_drone_ip()
@spec default_drone_port() :: pos_integer()
Default Tello command UDP port.
Returns
8889.
Examples
8889 = Drone.Adapters.Tello.Connection.default_drone_port()
@spec default_local_port() :: pos_integer()
Default local UDP bind port.
Returns
8889.
Examples
8889 = Drone.Adapters.Tello.Connection.default_local_port()
@spec default_timeout() :: pos_integer()
Default command reply timeout in milliseconds.
Returns
10_000.
Examples
10_000 = Drone.Adapters.Tello.Connection.default_timeout()
Opens a passive UDP socket bound to the local port.
Parameters
opts(keyword()) — optional::local_port(non_neg_integer()) — bind port (default8889)
Returns
{:ok, port()}— open:gen_udpsocket (active: false){:error, term()}— bind failure (for example:eaddrinuse)
Examples
{:ok, socket} = Drone.Adapters.Tello.Connection.open(local_port: 0)
:ok = Drone.Adapters.Tello.Connection.close(socket)
@spec receive_response(port(), non_neg_integer()) :: {:ok, binary()} | {:error, term()}
Receives one UDP datagram from the Tello (or times out).
Charlist payloads from older OTP paths are converted to binaries.
Parameters
socket(port()) — open UDP socket in passive modetimeout(non_neg_integer()) — milliseconds to wait
Returns
{:ok, binary()}— reply bytes{:error, :timeout}— no packet received{:error, term()}— other:gen_udp.recv/3errors
Examples
{:ok, data} = Drone.Adapters.Tello.Connection.receive_response(socket, 5_000)
{:error, :timeout} =
Drone.Adapters.Tello.Connection.receive_response(socket, 1)
Sends a command string and waits for one UDP reply.
Parameters
socket(port()) — open UDP socketcommand(String.t()) — ASCII SDK command (fromDrone.Adapters.Tello.Encoder.encode/1)opts(keyword()) — optional::drone_ip(:inet.ip_address()) — default{192, 168, 10, 1}:drone_port(non_neg_integer()) — default8889:timeout(non_neg_integer()) — recv timeout ms (default10_000)
Returns
{:ok, binary()}— raw reply payload (not yet parsed){:error, :timeout}— no datagram within the timeout{:error, term()}— send or socket failure
Examples
{:ok, reply} =
Drone.Adapters.Tello.Connection.send_command(socket, "battery?",
timeout: 3_000
)
{:ok, percent} = Drone.Adapters.Tello.Parser.parse(reply)