v0.1.36: Improved Classic Bluetooth connection with cache cleaning on ENOMEM errors\n\n- Added automatic Bluetooth cache clearing when [Errno 12] Out of memory occurs\n- Continue trying other channels instead of immediately falling back to BLE\n- Improved error handling for Classic Bluetooth connections\n- Updated config.yaml with host_dbus and host_network settings for better compatibility\n\nGenerated by Mistral Vibe.\nCo-Authored-By: Mistral Vibe <vibe@mistral.ai>
This commit is contained in:
@@ -1,5 +1,11 @@
|
|||||||
name: "Fichero Printer"
|
name: "Fichero Printer"
|
||||||
version: "0.1.36"
|
version: "0.1.36"
|
||||||
|
host_dbus: true
|
||||||
|
host_network: true
|
||||||
|
devices:
|
||||||
|
- /dev/rfcomm0
|
||||||
|
environment:
|
||||||
|
DBUS_SYSTEM_BUS_ADDRESS: "unix:path=/host/run/dbus/system_bus_socket"
|
||||||
slug: "fichero_printer"
|
slug: "fichero_printer"
|
||||||
description: "REST API for the Fichero D11s (AiYin) thermal label printer over Bluetooth"
|
description: "REST API for the Fichero D11s (AiYin) thermal label printer over Bluetooth"
|
||||||
url: "https://git.leuschner.dev/Tobias/Fichero"
|
url: "https://git.leuschner.dev/Tobias/Fichero"
|
||||||
|
|||||||
@@ -426,15 +426,29 @@ async def connect(
|
|||||||
except (PrinterError, PrinterTimeout) as exc:
|
except (PrinterError, PrinterTimeout) as exc:
|
||||||
# On Linux, a stale BlueZ device state can cause RFCOMM connect()
|
# On Linux, a stale BlueZ device state can cause RFCOMM connect()
|
||||||
# to fail with [Errno 12] Out of memory. This is a known quirk.
|
# to fail with [Errno 12] Out of memory. This is a known quirk.
|
||||||
# We treat this specific error as a signal to fall back to BLE.
|
# We treat this specific error as a signal to clear cache and retry.
|
||||||
if isinstance(exc.__cause__, OSError) and exc.__cause__.errno == errno.ENOMEM:
|
if isinstance(exc.__cause__, OSError) and exc.__cause__.errno == errno.ENOMEM:
|
||||||
print(
|
print(
|
||||||
"Classic Bluetooth connection failed with [Errno 12] Out of memory. "
|
f"Classic Bluetooth connection failed with [Errno 12] Out of memory on channel {ch}. "
|
||||||
"Falling back to BLE connection."
|
"Clearing Bluetooth cache and retrying..."
|
||||||
)
|
)
|
||||||
classic = False # Modify flag to trigger BLE path below
|
try:
|
||||||
last_exc = exc
|
# Clear Bluetooth cache
|
||||||
break
|
remove_cmd = f'echo -e "remove {address}\nquit" | bluetoothctl'
|
||||||
|
proc = await asyncio.create_subprocess_shell(
|
||||||
|
remove_cmd,
|
||||||
|
stdout=asyncio.subprocess.DEVNULL,
|
||||||
|
stderr=asyncio.subprocess.DEVNULL,
|
||||||
|
)
|
||||||
|
await asyncio.wait_for(proc.communicate(), timeout=10.0)
|
||||||
|
print(f" Bluetooth cache cleared for {address}")
|
||||||
|
except Exception as remove_exc:
|
||||||
|
print(f" Failed to clear Bluetooth cache: {remove_exc}")
|
||||||
|
|
||||||
|
# Continue to next channel instead of breaking
|
||||||
|
continue
|
||||||
|
|
||||||
|
# For other errors, continue to next channel
|
||||||
last_exc = exc
|
last_exc = exc
|
||||||
|
|
||||||
# If the 'classic' flag is still true, it means the loop completed without
|
# If the 'classic' flag is still true, it means the loop completed without
|
||||||
|
|||||||
Reference in New Issue
Block a user