domnulvlad / KLineKWP1281Lib

Arduino / ESP / RPi Pico library integrating the proprietary VAG Key-Word 1281 protocol (KWP1281/KW1281)
https://domnulvlad.github.io/KLineKWP1281Lib/
GNU General Public License v3.0
44 stars 5 forks source link

Long time to switch between modules #5

Closed emtepe35 closed 9 months ago

emtepe35 commented 9 months ago

I found that switching between ECU and Cluster modules (closing one connection, waking another module and connecting) takes about 12000ms from read to read. Is there a way to do it quicker?

domnulvlad commented 9 months ago

I just tried it and indeed it is slow, but that is just how this protocol is.

First it takes 2 seconds to perform the 5baud init, then it takes some time to get the module's info (which cannot be skipped), and then when you disconnect, it is required to wait 1 second before connecting to something else (actually it happens automatically with the connect() function when an attempt fails).

And also the module's baud rate influences the time taken, for example data will be much quicker on a 10400 baud device than on 4800. Again, you can't change any of this.

On my setup I have a cluster at 10400 and radio at 9600, and I can get about one measurement every 8.5 seconds if I switch between modules. Unfortunately there is nothing you can do differently with KWP1281.

Personally, I would say that if you have a project where you show data on a screen, you should have a separate page for each module, not trying to mix multiple modules at once, because you can see how slow it is. Every connection attempt has its own "overhead".

domnulvlad commented 9 months ago

You can technically shave off a few seconds by saving a 5baud attempt if you manually delay about 1s between disconnect() and connect(), or you could find some other delay that still works.

emtepe35 commented 9 months ago

Hi!

Many thanks for your reply. I use separate page for each module but the thing I want to implement the most is detecting doors open. In my car there is no communication between cluster and CCM so the only way to do so is to get measurements from CCM (each door have their mes. group). Displaying this info forces me to get data about 2 times per second. It has no sense when you have to wait 8 seconds for the screen to display your doors are open. Is there a way to keep two connections active at one time through one K-line wire? I could use separate LM339 chips or even two ESP boards.

I really appreciate your work. It gives a lot of joy to build it.

Best regards, Matthew

On Tue, Jan 30, 2024, 12:19 PM domnulvlad @.***> wrote:

You can technically shave off a few seconds by saving a 5baud attempt if you manually delay about 1s between disconnect() and connect(), or you could find some other delay that still works.

— Reply to this email directly, view it on GitHub https://github.com/domnulvlad/KLineKWP1281Lib/issues/5#issuecomment-1916625950, or unsubscribe https://github.com/notifications/unsubscribe-auth/AXGH6UBVWCI2IROHOSC7PZ3YRDJLZAVCNFSM6AAAAABCQ6O3XKVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTSMJWGYZDKOJVGA . You are receiving this because you authored the thread.Message ID: @.***>

domnulvlad commented 9 months ago

No, the protocol only supports one connection at a time. Everything happens on a single wire so there is nothing to do.

You could actually maybe get to the connector on the CCM and cut the K-line from the bus so it isn't connected to the other K-lines anymore. Then you could use a dedicated adapter for the CCM and another one for the rest of the modules.

domnulvlad commented 9 months ago

I haven't done it before because I only have one adapter but I think you would have to use you own custom5baudWaitFunction, in which you update the other connection so it doesn't break while the code is delay()-ing. Also you should avoid the normal connect() function and instead use attemptConnect() so you can avoid the other connection breaking while one is waiting after a failed attempt.

I will try to write such an example for two adapters when I have the time.

emtepe35 commented 9 months ago

Thank you so much for your help. For now I will try to optimize my code to use one connection at a time. Need to check if the cluster have some free pins, maybe I could add some extra wiring from CCM to cluster where my screen sits.

On Tue, Jan 30, 2024, 1:12 PM domnulvlad @.***> wrote:

I haven't done it before because I only have one adapter but I think you would have to use you own custom5baudWaitFunction, in which you update the other connection so it doesn't break while the code is delay()-ing. Also you should avoid the normal connect() function and instead use attemptConnect() so you can avoid the other connection breaking while one is waiting after a failed attempt.

I will try to write such an example for two adapters when I have the time.

— Reply to this email directly, view it on GitHub https://github.com/domnulvlad/KLineKWP1281Lib/issues/5#issuecomment-1916709506, or unsubscribe https://github.com/notifications/unsubscribe-auth/AXGH6UFBREOZK6C3XAWVXW3YRDPRXAVCNFSM6AAAAABCQ6O3XKVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTSMJWG4YDSNJQGY . You are receiving this because you authored the thread.Message ID: @.***>

domnulvlad commented 9 months ago

Ok. So for the future, the most reliable way to get your door data to update quickly is to isolate the CCM's K-line and use a separate adapter. Then of course you won't be able to diagnose the CCM with VCDS, you could maybe add a hidden switch that reconnects it to the K-line bus if you want.

domnulvlad commented 5 months ago

Hi again, @emtepe35. If you are still interested in this, I have written up a little page about your issue here with a bit more explanations. The conclusion is the same, there is no way to do what you wish to do without having to modify something, but if you are ok with modifications, then the solution is simple enough.

domnulvlad commented 5 months ago

I have updated that wiki page. I had completely overlooked the multitasking capabilities of the ESP32, which would be the best solution to your problem. No need for any additional microcontrollers.