Skip to content

Force Bluetooth connection to same device after Timeout #13

@KreAch3R

Description

@KreAch3R

Hello @manio!

I've been using my solution with your aa-proxy-rs on my car for a couple of days now and it works beautifully. I have noticed a minor inconvenience. If, for some reason, it throws a USB read/write" and/or "TCP deadline has elapsed and it disconnects, it won't re-connect to bluetooth on its own and the only way to make it restart is to restart the rpi, if you are driving. I suspect this is because the phone thinks it is already connected so it won't try to re-connect. I am talking about using it without the "-c connect" option.

These are the running parameters:

AA_PROXY_RS_ARGS="-b NaviPi --hostapd-conf /etc/hostapd/hostapd.conf -k"

This is the log:

2025-01-25, 14:35:55.605 [INFO] 🛸 aa-proxy-rs is starting, build: 20241228_022643, git: 20241224-38a633c-dirty
2025-01-25, 14:35:55.637 [INFO]  main:  📜 Log file path: /var/log/aa-proxy-rs.log
2025-01-25, 14:35:55.637 [INFO]  main:  ⚙️ Showing transfer statistics: disabled
2025-01-25, 14:35:55.692 [INFO]  proxy:  🛰️ Starting TCP server...
2025-01-25, 14:35:55.692 [INFO]  proxy:  🛰️ TCP server bound to:  0.0.0.0:5288
2025-01-25, 14:35:55.692 [INFO]  proxy:  💤 waiting for bluetooth handshake...
2025-01-25, 14:35:55.766 [INFO]  usb:  Using UDC: "dummy_udc.0"
2025-01-25, 14:35:55.767 [INFO]  usb:  🔌 Initializing USB Manager
2025-01-25, 14:35:55.767 [INFO]  usb:  🔌 USB Manager: Disabled all USB gadgets
2025-01-25, 14:35:55.768 [INFO]  bluetooth:  🥏 Bluetooth alias: NaviPi
2025-01-25, 14:35:55.890 [INFO]  bluetooth:  🥏 Opened bluetooth adapter hci0 with address B8:27:EB:86:FF:AE
2025-01-25, 14:35:55.979 [INFO]  bluetooth:  📱 AA Wireless Profile: registered
2025-01-25, 14:35:55.981 [INFO]  bluetooth:  🎧 Headset Profile (HSP): registered
2025-01-25, 14:35:55.981 [INFO]  bluetooth:  ⏳ Waiting for phone to connect via bluetooth...
2025-01-25, 14:36:15.748 [INFO]  bluetooth:  📱 AA Wireless Profile: connect from: 30:74:67:AF:9C:C2
2025-01-25, 14:36:15.749 [INFO]  bluetooth:  📲 Sending parameters via bluetooth to phone...
2025-01-25, 14:36:15.749 [INFO]  bluetooth:  🛜 Sending Host IP Address: 10.0.0.1
2025-01-25, 14:36:15.749 [INFO]  bluetooth:  📨 stage #1 of 5: Sending WifiStartRequest frame to phone...
2025-01-25, 14:36:15.997 [INFO]  bluetooth:  📨 stage #2 of 5: Received WifiInfoRequest frame from phone (⏱️ 247 ms)
2025-01-25, 14:36:15.997 [INFO]  bluetooth:  🛜 Sending Host SSID and Password: NaviPi, AANaviPi
2025-01-25, 14:36:15.997 [INFO]  bluetooth:  📨 stage #3 of 5: Sending WifiInfoResponse frame to phone...
2025-01-25, 14:36:15.998 [INFO]  bluetooth:  📨 stage #4 of 5: Received WifiStartResponse frame from phone (⏱️ 0 ms)
2025-01-25, 14:36:20.143 [INFO]  bluetooth:  📨 stage #5 of 5: Received WifiConnectStatus frame from phone (⏱️ 4143 ms)
2025-01-25, 14:36:20.143 [INFO]  bluetooth:  🚀 Bluetooth launch sequence completed
2025-01-25, 14:36:20.143 [INFO]  proxy:  🛰️ TCP server: listening for phone connection...
2025-01-25, 14:36:20.882 [INFO]  proxy:  📳 TCP server: new client connected: 10.0.0.20:34940
2025-01-25, 14:36:20.882 [INFO]  proxy:  📂 Opening USB accessory device: /dev/usb_accessory
2025-01-25, 14:36:20.883 [INFO]  proxy:  ♾️ Starting to proxy data between TCP and USB...
2025-01-25, 14:36:20.971 [INFO]  usb:  🔌 USB Manager: Switched to accessory gadget
2025-01-25, 14:36:20.971 [INFO]  bluetooth:  🥷 Unregistering default agent
2025-01-25, 14:36:20.971 [INFO]  bluetooth:  📱 Removing AA profile
2025-01-25, 14:36:23.473 [WARN]  bluetooth:  🎧 Error waiting for HSP profile task: deadline has elapsed
2025-01-25, 14:36:23.473 [INFO]  bluetooth:  💤 Bluetooth adapter stays on
2025-01-25, 14:58:46.080 [ERROR]  proxy:  🔴 Connection error: USB write: deadline has elapsed
2025-01-25, 14:58:47.437 [INFO]  proxy:  ⌛ session time: 22m 27s 707ms 590us 457ns
2025-01-25, 14:58:47.437 [INFO]  proxy:  💤 waiting for bluetooth handshake...
2025-01-25, 14:58:47.441 [INFO]  main:  📵 TCP/USB connection closed or not started, trying again...
2025-01-25, 14:58:48.443 [INFO]  usb:  🔌 Initializing USB Manager
2025-01-25, 14:58:49.090 [INFO]  usb:  🔌 USB Manager: Disabled all USB gadgets
2025-01-25, 14:58:49.090 [INFO]  bluetooth:  🥏 Bluetooth alias: NaviPi
2025-01-25, 14:58:49.159 [INFO]  bluetooth:  🥏 Opened bluetooth adapter hci0 with address B8:27:EB:86:FF:AE
2025-01-25, 14:58:49.224 [INFO]  bluetooth:  📱 AA Wireless Profile: registered
2025-01-25, 14:58:49.230 [INFO]  bluetooth:  🎧 Headset Profile (HSP): registered
2025-01-25, 14:58:49.231 [INFO]  bluetooth:  ⏳ Waiting for phone to connect via bluetooth...
2025-01-25, 17:54:10.801 [INFO] 🛸 aa-proxy-rs is starting, build: 20241228_022643, git: 20241224-38a633c-dirty

I will try to increase the --timeout-secs parameter and see if this decreases the frequency, but the root problem of not re-connecting to bluetooth remains.

I thought of a solution; What if we save the connected bluetooth mac somewhere, and in the case of a timeout/connection error, we try to reconnect to the same bluetooth device? Only on the next restart, the default behavior will still hold, i.e. wait for any bluetooth connection. What do you think?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions