nisargjhaveri / WirelessAndroidAutoDongle

Use Wireless Android Auto with a car that supports only wired Android Auto using a Raspberry Pi.
MIT License
320 stars 43 forks source link

Add dongle mode connection strategy #72

Closed nisargjhaveri closed 3 months ago

nisargjhaveri commented 4 months ago

Connection to dongle mode requires the following steps:

Demon000 commented 4 months ago

Is call audio sent via TCP in this case?

nisargjhaveri commented 4 months ago

Is call audio sent via TCP in this case?

No, the call audio goes directly to the headunit via bluetooth.

Ioniq3 commented 4 months ago

Hello Nisarg , I've check on my hyundai and the dongle mode works perfectly with the initial boot of the raspberry before turning on the headunit. Great work.

hkfuertes commented 3 months ago

Looks really interesting! Testing out this evening! :)

admiralspeedy commented 3 months ago

Dongle Mode still seems super inconsistent to me. I ran a build of my own with the new change to keep BT on and I had to power cycle the dongle like 3 times before it would actually work for some reason.

Ioniq3 commented 3 months ago

Hello Nisarg , can you explain me the reasons to not disable bluetooth in dongle mode. I test before this commit and it is not necessary to maintain the bluetooth connection

nisargjhaveri commented 3 months ago

Yeah, the bluetooth changes are not working great. Haven't had a chance to debug properly.

The idea was that, with dongle mode, we don't really need to disconnect/reconnect bluetooth as well, as the phone should anyway try to reconnect. And the delay we have between restarting the tcp server might hinder with the reconnection from phone. Will have another look later.

nisargjhaveri commented 3 months ago

@admiralspeedy would you be able to help out with logs where the dongle mode doesn't work? This has been working well for me, and I think this would help with some of the other issues as well. I'd like to learn more about issues and fix and merge this if possible.

@hkfuertes, @Ioniq3 do let me know how it works you. I've reverted the commit with always on bluetooth, will debug that one later.

Ioniq3 commented 3 months ago

Hi, for me works perfectly, the dongle mode is a huge upgrade in the first connection in the cars that the usb power prior to turn in the headunit. It is important for the people to remeber all the steps: clear cache and memory of the android auto app, unpair, pair by wired cable and connect. The bluetooth have to poweroff to increase battery life having in mind that wireless lan drains the battery too.

admiralspeedy commented 3 months ago

@nisargjhaveri I can, the problem is that most of the time when I have issues I am not going somewhere where I can easily keep my car on and connect to the Pi to retrieve logs. I can do it when my destination is home because I can pull in my driveway and connect to the Pi from my computer in the house. We really need persistent logs.

I think most of my issues happen due to the disconnection handling, because part of the issue is that I regularly remote start my car (Canada, it's winter) and my phone connects to the dongle sometimes for 15 minutes before I get in the car. When you do this, the head unit does not actually fully boot until you get in the car and press the start button on any Ford with a Sync 3 APIM. This seems to confuse it and for some reason and the dongle sometimes (not always) gets stuck in a limbo state. I have checked the logs before when this happens but I never see anything of note that would explain why the dongle is stuck.

I've also had a number of times where my phone just repeatedly connects and instantly disconnects from the dongle over and over until I reboot the dongle and again, the one time I checked the logs, there were no errors or anything.

@Ioniq3 I think we have different definitions of perfect, because handling disconnection/re-connection is still not handled correctly and even with my own not-so-great fixes it still has problems for me.

Also, you really don't have to remove old cars or clear the cache of Android Auto for dongle mode to work. As long as the car is already in your list of previously connected cars, it does just work when you plug in and connect to the dongle.

Ioniq3 commented 3 months ago

@admiralspeedy I understand some of your issues. I have a personal workaround in my reconnect-externalprogram branch (use of a signal to external program "myscript" to restart S92_usbgadget and S93_aawgd to recover the AA) if you want to investigate it, I don' t make a PR because is part of a very particular adaptation because I use the raspberry for android auto and usb music stick simulation by means of external buttons.

Making persistent logs for embedded systems may destroy the microsd in few months, in my experience with a lot of raspberry it is better not to write on it and only read from the operating systems, all the rest in ramfs. If @nisargjhaveri want to implement persistent logs I recommend in a special debug mode, activate by another enviroment variable and not in the main mode.

nisargjhaveri commented 3 months ago

@admiralspeedy, yes the disconnections are still not fixed with this PR. This is only supposed to improve the speed and reliability of connection process, and improve call audio routing on some phones by removing the fake headset profile. The reconnection issues should stay similar to the other modes. If we can focus on connection issues, it would be great for this PR.

For the persistent logs, I agree with @Ioniq3. I'm okay having a new variable to persist logs, but it comes with high risk of sd card corruption when enabled. We might also need to reduce verbosity of the logs, especially when we log every read/write. Will see if I can work on this or happy to take in a PR.

admiralspeedy commented 3 months ago

@nisargjhaveri The problem is that most of the connection issues myself and others are having are probably almost all related to the re-connection/disconnections not being handled properly.

I know for a fact I almost always have an issue with it if I have remote started my car and the dongle doesn't make a connection to the head unit (since the head unit doesn't fully boot until you actually get in the car and press the ignition button, as I mentioned above) but has connected to the phone for a bit already (because the Bluetooth is strong enough to reach my phone in my house when I remote start my car).

The other main time I have issues connecting are when I shut my car off, walk away and then come back after a short amount of time because my car and many others do not power down the USB ports right away (sometimes mine stay on for 10-15 minutes, but some cars don't power them down at all actually), so the dongle loses connection to AA over USB, get stuck waiting for a read and when you come back the dongle is just forever stuck until you reboot it.

And then sometimes just randomly I have issues and I can't explain them. For example, I walked to my car on Friday after work without command starting it, got in it, turned it on and started driving home and after a few minutes of waiting I stopped and checked my phone because I was not getting Android Auto. I had to forget and re-connect to the dongle's Bluetooth despite the fact that I literally used the dongle on my way to work that same morning without a problem and didn't change anything at all before leaving work. I've also had times where I just got in my car and it refused to work for seemingly no reason and I just had to reboot the dongle, again I don't know why.

The thing that annoys me with these issues is that there isn't even a ton of code involved in any of this, it's a pretty straightforward proxy system and the connection functions are all pretty straightforward so I don't understand why it seems to stop working totally at random when all other variables appear to be the same.

As for the logs, I was never suggesting it be permanent, it should definitely be a debug setting and I am personally more than willing to sacrifice SD cards for it, I have a whole bin full lol. Without persistent logs, a lot of these bugs are never going to get figured out because based on most of our discussions, you, me, and @Ioniq3 are probably the only people here who even know how to SSH into a Pi and pull the logs so most users are never going to be able to submit them if they have to keep the dongle alive long enough to save them.

simquad commented 3 months ago

Jumping in on this.

I have a Kia eNiro, currently it is not connecting but I do know how to SSH in ☺️ so I'll take a look at the logs, see if I can fix anything, and pass on any findings.

Will report back.

nisargjhaveri commented 3 months ago

I believe with the other fixes to handle disconnection or retries, this should not work better for most cases. Seems to work well for me.

Planning to merge soon, let me know in case anyone's still facing issues with this. I'd appreciate if someone else can also try out the latest changes.

admiralspeedy commented 3 months ago

Do the other changes play nice with dongle mode?

nisargjhaveri commented 3 months ago

Do the other changes play nice with dongle mode?

I had to update some things from the original changes. But yes, the latest changes work well along with the other connection recovery mechanisms, at least for me. Not sure if there might be something better we can do for dongle mode, especially for initial connection. Nit a lot of info is available on how dongle mode is supposed to work.