Support ESP-NOW connection in pyflix

Set arbitrary pymavlink connection string using device parameter or FLIX_DEVICE env variable.
pyflix@0.16.
This commit is contained in:
Oleg Kalachev
2026-05-28 18:22:16 +03:00
parent a294883dea
commit 4e32414dae
3 changed files with 19 additions and 12 deletions
+2
View File
@@ -28,6 +28,8 @@ from pyflix import Flix
flix = Flix() # create a Flix object and wait for connection flix = Flix() # create a Flix object and wait for connection
``` ```
If using ESP-NOW connection, specify the proxy's device name in `FLIX_DEVICE` environment variable or pass it to the constructor: `Flix(device='/dev/cu.usbserial-0001')`.
### Telemetry ### Telemetry
Basic telemetry is available through object properties. The property names generally match the corresponding variables in the firmware code: Basic telemetry is available through object properties. The property names generally match the corresponding variables in the firmware code:
+16 -11
View File
@@ -44,22 +44,27 @@ class Flix:
_print_buffer: str = '' _print_buffer: str = ''
_modes = ['RAW', 'ACRO', 'STAB', 'AUTO'] _modes = ['RAW', 'ACRO', 'STAB', 'AUTO']
def __init__(self, system_id: int=1, wait_connection: bool=True): def __init__(self, system_id: int=1, wait_connection: bool=True, device=os.getenv('FLIX_DEVICE')):
if not (0 <= system_id < 256): if not (0 <= system_id < 256):
raise ValueError('system_id must be in range [0, 255]') raise ValueError('system_id must be in range [0, 255]')
self._setup_mavlink() self._setup_mavlink()
self.system_id = system_id self.system_id = system_id
self._init_state() self._init_state()
try: if device is not None:
# Direct connection # User defined connection
logger.debug('Listening on port 14550') logger.debug(f'Connecting to {device}')
self.connection: mavutil.mavfile = mavutil.mavlink_connection('udpin:0.0.0.0:14550', source_system=255) # type: ignore self.connection: mavutil.mavfile = mavutil.mavlink_connection(device, source_system=255) # type: ignore
except OSError as e: else:
if e.errno != errno.EADDRINUSE: try:
raise # Direct connection
# Port busy - using proxy logger.debug('Listening on port 14550')
logger.debug('Listening on port 14555 (proxy)') self.connection: mavutil.mavfile = mavutil.mavlink_connection('udpin:0.0.0.0:14550', source_system=255) # type: ignore
self.connection: mavutil.mavfile = mavutil.mavlink_connection('udpin:0.0.0.0:14555', source_system=254) # type: ignore except OSError as e:
if e.errno != errno.EADDRINUSE:
raise
# Port busy - using proxy
logger.debug('Listening on port 14555 (proxy)')
self.connection: mavutil.mavfile = mavutil.mavlink_connection('udpin:0.0.0.0:14555', source_system=254) # type: ignore
self.connection.target_system = system_id self.connection.target_system = system_id
self.mavlink: mavlink.MAVLink = self.connection.mav self.mavlink: mavlink.MAVLink = self.connection.mav
self._event_listeners: Dict[str, List[Callable[..., Any]]] = {} self._event_listeners: Dict[str, List[Callable[..., Any]]] = {}
+1 -1
View File
@@ -1,6 +1,6 @@
[project] [project]
name = "pyflix" name = "pyflix"
version = "0.15" version = "0.16"
description = "Python API for Flix drone" description = "Python API for Flix drone"
authors = [{ name="Oleg Kalachev", email="okalachev@gmail.com" }] authors = [{ name="Oleg Kalachev", email="okalachev@gmail.com" }]
license = "MIT" license = "MIT"