openDsh / dash

Join us on Slack! https://join.slack.com/t/opendsh/shared_invite/zt-la398uly-a6eMH5ttEQhbtE6asVKx4Q
GNU General Public License v3.0
280 stars 85 forks source link

Android auto wireless (bluetooth) connection #33

Open obertr0n opened 3 years ago

obertr0n commented 3 years ago

Issue

Unable to connect to opennauto using bluetooth.

Hardware

| Raspberry Pi 3B+ 1GB | USB Cable | 7" touch screen | Xiaomi Poco F1 | v.1.1? |

Installation Method: Install.sh

Description of problem:

I'm using a raspberry pi with an usb bluetooth dongle that I can successfully use it for media streaming from my phone to dash, but I cannot get the wireless connection with openauto to work. Is there a special procedure to follow? Is this feature even available in dash?

Expected Result:

Successful connection using bluetooth to openauto.

Thank you in advance.

icecube45 commented 3 years ago

First set the pi to emit a hotspot. I like this guide.

Then, go into your openauto.ini and set WiFi.SSID and WiFi.Password to the ssid/passkey of the hotspot you setup.

When you connect your phone to the pi's bluetooth, you should see a message pop up saying "searching for android auto" or similar. The phone should then automatically connect to your hotspot, and establish connection with openauto.

obertr0n commented 3 years ago

I have tried to follow the steps that you have described in the link. Unfortunately the phone was not connecting to the hotspot created by pi (stuck at obtaining ip address) I have then used the scripts from here. With this, the phone was connecting to pi over wifi. Even by doing this, the wireless connection to open auto was not successful, here is the log: libEGL warning: DRI2: failed to authenticate qt5ct: using qt5ct plugin [2020-12-08 17:47:19.379548] [0x70bcf6e0] [info] [OpenAuto] [GSTVideoOutput] RPI Build, running with omxh264dec [2020-12-08 17:47:19.514972] [0x70bcf6e0] [info] [OpenAuto] [AndroidBluetoothServer] listening. [2020-12-08 17:47:19.556157] [0x70bcf6e0] [info] [OpenAuto] [btservice] Listening for connections, address: 00:1A:7D:DA:71:13, port: 22 [2020-12-08 17:47:19.566616] [0x70bcf6e0] [info] [OpenAuto] [btservice] Service registered, port: 22 [2020-12-08 17:47:19.570790] [0x70bcf6e0] [info] [OpenAuto] [App] Waiting for USB device... [2020-12-08 17:47:19.590383] [0x70bcf6e0] [info] [OpenAuto] [App] Waiting for Wireless device... [2020-12-08 17:47:19.596770] [0x5d7732f0] [info] [OpenAuto] [App] Devices enumeration result: false qt5ct: palette support is disabled qt5ct: custom style sheet is disabled [2020-12-08 17:47:20.186629] [0x70bcf6e0] [info] [Dash] [SocketCANBus] 'socketcan' Available [2020-12-08 17:47:20.324742] [0x70bcf6e0] [info] [Dash] [SocketCANBus] Connecting CAN interface [2020-12-08 17:47:20.358079] [0x70bcf6e0] [info] [Dash] [Media] Registered frame handler for id 518 [2020-12-08 17:47:20.358216] [0x70bcf6e0] [info] [Dash] [Media] Registered frame handler for id 513 [2020-12-08 17:47:20.825806] [0x70bcf6e0] [info] [Dash] [Gauges] Registered frame handler for id 1256 [2020-12-08 17:47:20.826930] [0x70bcf6e0] [info] [Dash] [Gauges] Registered frame handler for id 1256 [2020-12-08 17:47:20.828405] [0x70bcf6e0] [info] [Dash] [Gauges] Registered frame handler for id 1667 [2020-12-08 17:47:20.830951] [0x70bcf6e0] [info] [Dash] [Gauges] Registered frame handler for id 1260 [2020-12-08 17:47:23.303866] [0x70bcf6e0] [info] [OpenAuto] [GSTVideoOutput] Got resize request to 748x438 org.kde.bluez: PendingCall Error: "Host is down" [2020-12-08 17:48:11.430487] [0x70bcf6e0] [info] [OpenAuto] [AndroidBluetoothServer] Device Connected: POCOPHONE F1 [2020-12-08 17:48:11.431044] [0x60f7a2f0] [info] [OpenAuto] [AndroidBluetoothServer] Sending socket info. QSocketNotifier: Socket notifiers cannot be enabled or disabled from another thread [2020-12-08 17:48:11.432739] [0x60f7a2f0] [info] [OpenAuto] [AndroidBluetoothServer] Sent socket info. [2020-12-08 17:48:11.448969] [0x70bcf6e0] [info] [OpenAuto] [AndroidBluetoothServer] DATA: [2020-12-08 17:48:11.449478] [0x70bcf6e0] [info] [OpenAuto] [AndroidBluetoothServer] Phone acknowledged socket info. [2020-12-08 17:48:11.449682] [0x60f7a2f0] [info] [OpenAuto] [AndroidBluetoothServer] Sending network packet. [2020-12-08 17:48:11.450719] [0x60f7a2f0] [info] [OpenAuto] [AndroidBluetoothServer] Sent network packet. [2020-12-08 17:48:11.488032] [0x70bcf6e0] [info] [OpenAuto] [AndroidBluetoothServer] DATA: [2020-12-08 17:48:11.489708] [0x70bcf6e0] [info] [OpenAuto] [AndroidBluetoothServer] Phone acknowledged network info with status code: 0 All this time, the phone is displaying: Looking for Android Auto. Currently I'm using the "socketcan" branch from @icecube45 , if that's relevant. Is it necessary that the bluetooth option from OpenAuto settings to be set to ON? I tried with and without it, but the result was the same. If time allows, I will give it a try with a clean raspbian install and the "develop" branch from here.

icecube45 commented 3 years ago

Looks like the handshake completed just fine - two things to check 1: are you using the pi's internal wifi, or an adapter (internal preferred right now) 2: Some phones appear to not fully support AA wifi - try manually connecting the phone to the wifi hotspot once, then retrying the bluetooth handshake

obertr0n commented 3 years ago

I am using the internal wifi. I have tried the following:

After this, the expected behavior would be that the phone is connected wireless to dash (openauto), but it doesn't happen; Also, I have tried having the phone disconnected from pi hotspot, but with the same outcome;

When the [AndroidBluetoothServer] DATA: [2020-12-08 17:48:11.489708] [0x70bcf6e0] [info] [OpenAuto] [AndroidBluetoothServer] Phone acknowledged network info with status code: 0 is logged, does this means that the phone should automatically connect to pi hotspot? Does this requires phone disconnected from other networks, or phone wifi to be off?

I feel like the problem is related to the hotspot setup on pi, but I need a proven method tested by someone else that I can follow to rule out that.

icecube45 commented 3 years ago

The phone should automatically turn on wifi, and connect to the wifi hotspot you specify in openauto.ini.

There are five reasons this can fail:

  1. Wifi SSID is wrong
  2. Wifi password is wrong
  3. MAC address of the wifi hotspot does not match the MAC address sent to the phone (this is why I was asking about internal vs external)
  4. IP address of openauto provided is not found by the phone
  5. Phone being weird.

Unfortunately android auto wifi just doesn't work as expected on all phones - you may be hitting this. All I can say is that using the guide I linked, I successfully run this daily on my Pi 4, and Pixel 3a.

I can try and add some more debugging into a new branch, but if you're getting through the handshaking, there might not be much info gained.

obertr0n commented 3 years ago

The phone should automatically turn on wifi, and connect to the wifi hotspot you specify in openauto.ini.

I don't think that ever happened. I'm going to try over the weekend a clean raspbian (btw, I'm using buster) install with the mainline dash release and also try and use a phone with Android One.

3. MAC address of the wifi hotspot does not match the MAC address sent to the phone (this is why I was asking about internal vs external)

I only have the builtin wifi, and never connected an external wifi card;

4. IP address of openauto provided is not found by the phone

How is this IP going to be used? Is there some documentation about the pairing protocol of AA?

5. Phone being weird.

Highly possible, but I don't have anything else to test.

Unfortunately android auto wifi just doesn't work as expected on all phones - you may be hitting this. All I can say is that using the guide I linked, I successfully run this daily on my Pi 4, and Pixel 3a.

I'm using a Pi3, but I don't think that's a big deal. I'm trying to use wifi mainly because of the phone sucking too much power when on low battery and I'm getting the undervoltage warning; Are you using 5GHz? Also, is this step from the guide required: Enable routing and IP masquerading? I can try and add some more debugging into a new branch, but if you're getting through the handshaking, there might not be much info gained.

I appreciate that, but I don't think that much can be gained from it;

On a different note, can you please guide me on how to detect in SW when AA projection is started? I would like to pause all the media when the connection is completed; Sadly I'm not very experienced with Qt and OOP in general. If I'm asking too much, disregard my comment;

icecube45 commented 3 years ago
4. IP address of openauto provided is not found by the phone

How is this IP going to be used? Is there some documentation about the pairing protocol of AA?

Through bluetooth, Android Auto tells the phone what it's IP is. The phone then tries to connect to Android Auto at that IP address.

There's no documentation (available to us) on any of Android Auto - openauto has all been reverse engineered, the wireless setup included. You'll notice if you dig into the protobuf files I deciphered for this pairing process, there are some values that I still have no clue as to what they do.

I'm using a Pi3, but I don't think that's a big deal. I'm trying to use wifi mainly because of the phone sucking too much power when on low battery and I'm getting the undervoltage warning; Are you using 5GHz? Also, is this step from the guide required: Enable routing and IP masquerading?

Routing is not required - I am using 5GHz (and this is recommended for wireless), but it should work on 2GHz as well. I believe I tested that with no issue, although my memory is lacking.

On a different note, can you please guide me on how to detect in SW when AA projection is started? I would like to pause all the media when the connection is completed; Sadly I'm not very experienced with Qt and OOP in general. If I'm asking too much, disregard my comment;

Pause all the media in what sense? Want to make sure I understand the ask here.

obertr0n commented 3 years ago

What I meant by pause all the media is that, for example, if the local (Pi) media player is playing something to pause it prior to the switch to AA, so I don't have overlapping audio. Same for bt, if that's even possible to happen, I assume AA would take control over bt when connection is completed.

I might just be picky here since it can be easily be paused via the pause button on touchscreen :)

icecube45 commented 3 years ago

That's a good point, @rsjudka is that something that dash currently considers? Otherwise we should open a FR for it.

rsjudka commented 3 years ago

yeah from my testing once AA launches it takes over the audio channel (unless you have some fancy audio setup, where it might be an issue then)

as a little bonus, you can sometimes control the music playing through AA in the dash media player (for spotify at least) :smile:

if you notice any problems tho, let me know... shouldn't be too hard to force stop the media player once AA launches

rsjudka commented 3 years ago

also thanks @icecube45 for helping out here!

icecube45 commented 3 years ago

@obertr0n any news on this front?

obertr0n commented 3 years ago

Hello, sorry for taking so long to report back. I have made a clean install of the latest raspbian. Tried both the develop and the latest socketcan branches with my Xiaomi Poco F1, a Xiaomi Mi A1 with Android One, and a Samsung Galaxy S10 Plus. The behavior was the same as previous.

The only slight success was with the develop branch, but with the Pi and phone connected to same wifi network, and configuring the phone ip in dash. After this, the wireless connection worked. Do I have to keep the head unit server on all the time?

The script that I have used for creating the hotspot is this one: https://github.com/obertr0n/dash/blob/astradash/setup_ap.sh

icecube45 commented 3 years ago

No, head unit server and manually entering of addresses shouldn't be a thing anymore. I've actually just submitted openDsh/openauto#18 which reworks a lot of this setup. Maybe more success will come post merge of that? At the very least it has more debug information present.

obertr0n commented 3 years ago

I finally have some good news. With your _wifi_rework_ branch I was able to get the Xiaomi Mi A1 to work flawlessly. All the steps that you have described worked as expected:

  1. setup a wifi hotspot on Pi (using 5Ghz)
  2. paired the Pi and phone over bluetooth using an USB dongle;
  3. started dash
  4. when Pi and phone connect over bluetooth, the phone will start the wifi and connect to the Pi hotspot (this happens even if wifi is off)
  5. the wireless projection starts in dash;

On the other hand I have less success on Poco: A. at step 4. when dash should send the details about the wifi network, and the phone has wifi off, a message would popup on phone to enable wifi. Even if I start manually the wifi, the handshake won't complete.

B. again, at step 4 if I have wifi already on, the phone will disconnect from the current network and connect to the Pi hotspot. The wifi projection would start but after ~1-2s an error would appears and the projection stops.

I have attached the console log if it helps. miA1_wifi_success.txt poco_wifi_fail.txt

I will try and check with other phones as well.

Thank you for the support!

icecube45 commented 3 years ago

Looks like the pocophone has had issues in the past with wireless Android Auto - is it fully updated?

Being as you're having success with a Xiaomi phone now, whatever issues are present currently are likely on the phone side.

icecube45 commented 2 years ago

Not to necro a really old issue, but rereading this as I clean up issues - there's a chance the phone having issues does not support the wifi channel that being used as the wireless android auto hotspot.