Skip to content

Conversation

barrymac
Copy link

@barrymac barrymac commented Feb 5, 2025

Victron BLE Plugin: Raspberry Pi 4 Stability & Multi-Adapter Support

Summary

This update adds critical support for external Bluetooth adapters to address instability with Raspberry Pi 4's built-in Bluetooth hardware when used with Victron devices. Users can now select between adapters (e.g., hci1 for USB dongles) via SignalK UI to bypass Pi 4's unreliable native Bluetooth stack.

Key Changes

🛠️ Pi 4 Hardware Workarounds

  • Adapters now selectable in UI (hci0/hci1) to support external BLE dongles
  • Default changed to external adapters (hci1) for stable operation
  • Added auto-recovery for adapter disconnects

🪲 Why This Matters for Pi 4 Users

Pi 4's built-in Bluetooth:
➔ Fails to maintain stable GATT connections
➔ Causes packet loss with Victron devices
External dongles (e.g., CSR4.0/Plugable BT4LE) resolve these issues.


Full Changelog

Features

  • 007d6c8: Core Bluetooth adapter selection logic
  • 9471a9d: UI configuration for adapter switching
  • ee255ed: Packet logging (size/timestamp/RSSI) for debugging

Fixes & Stability

  • d9ba0c3: Compatibility with Bleak 0.20+ APIs
  • 3e7aa1c: Adapter selection via OS environment
  • 6a21b55: Health monitoring and restart logic

Code Quality

  • c62a146/a911e39: Type hint improvements
  • 4dcba99: Reduced log noise for production

Verification Steps

  1. Adapter Selection (Pi 4 + USB dongle):
    • Set to hci1 → Confirm logs show [DEBUG] Using Bluetooth adapter hci1
  2. Stability Test:
    • Unplug dongle → Verify auto-restart after 5s
  3. Device Naming:
    • Ensure Victron-reported names appear under electrical.devices.*.deviceName

Tested Hardware: Raspberry Pi 4 (Buster) + Victron Orion XS/SmartShunt + Plugable USB-BT4LE dongle.
Requires: bleak>=0.20.0

barry added 30 commits January 25, 2025 16:02
@stefanor
Copy link
Owner

stefanor commented Feb 5, 2025

Thank you for looking at this!

@barrymac
Copy link
Author

barrymac commented Feb 6, 2025

Thank you for looking at this!

Thanks to you for creating it! I battled for quite some time before discovering some comments about the RPi4 bluetooth. So I tried a dongle and it just worked.

@stefanor
Copy link
Owner

stefanor commented Feb 6, 2025

Yeah, I'll admit that I use an external Bluetooth dongle too... But I just disable the internal one.

Copy link
Owner

@stefanor stefanor left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, didn't get to this sooner. The commits are also verbose that it's hard to approach. AI generated?

updates: [{
values: [{
path: "plugins.victronBLE.status",
value: "active"
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What purpose does this serve? I don't see this path documented anywhere

)

T = TypeVar('T', bound=DeviceData)
import inspect
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sort stdlib imports together

VEBusData,
)

T = TypeVar('T', bound=DeviceData)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please put this below imports

super().__init__()
except TypeError as e:
logger.debug(f"Parent __init__ args required: {e}")
raise
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This all seems pretty unnecessary.

logger.debug(
f"Received data from {bl_device.address.lower()}: {raw_data.hex()}"
f"Received {len(raw_data)}B packet from {bl_device.address.lower()} "
f"(RSSI: {rssi}) @ {datetime.datetime.now().isoformat()}: "
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Log entries are already timestamped, why include the time again here?

values.append({
"path": f"electrical.devices.{id_}.deviceName",
"value": bl_device.name
})
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Repeated

) -> SignalKDeltaValues:
values: SignalKDeltaValues = [
{
"path": f"electrical.deviceMetadata.{id_}.name",
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where is this path documented?


# Add device name to all deltas
values.append({
"path": f"electrical.devices.{id_}.deviceName",
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where is this path documented?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants