Skip to content

Improve Handshake Process with HELLO Message#230

Merged
VanceVagell merged 8 commits intoVanceVagell:mainfrom
dkaukov:better-handshake
Feb 15, 2025
Merged

Improve Handshake Process with HELLO Message#230
VanceVagell merged 8 commits intoVanceVagell:mainfrom
dkaukov:better-handshake

Conversation

@dkaukov
Copy link
Collaborator

@dkaukov dkaukov commented Feb 11, 2025

Currently, the host waits for an arbitrary delay after a USB connect event before sending a GET_VERSION request to determine if the module is ready. This can lead to timing issues and unreliable initialization.

This PR updates the handshake process so that the module proactively sends a HELLO message after boot. This ensures the host knows exactly when the module is ready, improving reliability and reducing unnecessary delays.

Changes:

  1. The module now sends a HELLO message immediately after boot.
  2. The host listens for the HELLO message before proceeding with further communication.
  3. If no HELLO is received within a timeout period, the host prompts for flash

Benefits:

  1. Eliminates reliance on arbitrary delays.
  2. Ensures the host only communicates when the module is actually ready.
  3. Improves reliability, especially in cases where boot time varies.
  4. allows to re-sync after module reboot in RX mode

@dkaukov dkaukov requested a review from VanceVagell February 11, 2025 06:40
@VanceVagell
Copy link
Owner

I'm confused, doesn't this just move the timer to waiting for HELLO instead of waiting for the GET_VERSION response?

Also, the microcontoller won't restart when the kv4p HT app is closed and reopened, meaning the HELLO message won't be sent, right?

Maybe I'm missing something...

@dkaukov
Copy link
Collaborator Author

dkaukov commented Feb 11, 2025

Hi @VanceVagell

  1. Doesn’t this just move the timer to waiting for HELLO instead of GET_VERSION?
    Not really—right now, we’re guessing when the module is ready. With HELLO, the module tells us exactly when it's up, so we don’t waste time waiting too long or giving up too soon. No guessing, just a direct signal.

  2. What if the app restarts but the microcontroller doesn’t?
    Not a problem! The microcontroller will restart anyway (watchdog takes care of that). And to speed things up, we can force a restart right after USB connects. That way, HELLO always gets sent, keeping things reliable.

Ensured only one active timeout by clearing all pending callbacks before scheduling a new one, preventing stale events from affecting the connection state.
@dkaukov
Copy link
Collaborator Author

dkaukov commented Feb 12, 2025

May fix: #227, #226

@VanceVagell
Copy link
Owner

Can you please confirm if this fixes bug #226 ? You can test it by plugging into your phone a bare ESP32 (not in a kv4p HT PCB or connected to a radio module) with the firmware installed.

If so I'll merge this in, otherwise it's not clear to me that this has added benefit over current functionality (I appreciate your explanation, and I can go into more detail if this does not fix #226).

@dkaukov
Copy link
Collaborator Author

dkaukov commented Feb 13, 2025

Hi @VanceVagell,

Yes, I can confirm that this does fix #226. I tested it by plugging a bare ESP32 (not in a kv4p HT PCB or connected to a radio module) into my phone with the firmware installed, and it worked as expected.

It's worth noting that the issue wasn't actually related to the changes in the handshake. The problem was due to a WDT reset occurring while waiting for the SA818's reply (see [this line].

@VanceVagell
Copy link
Owner

Awesome, thanks for fixing that bug! I will merge this once you adjust the 2 strings I commented on.

@dkaukov dkaukov requested a review from VanceVagell February 15, 2025 04:11
@sonarqubecloud
Copy link

@VanceVagell VanceVagell merged commit 03b804f into VanceVagell:main Feb 15, 2025
4 checks passed
@dkaukov dkaukov deleted the better-handshake branch February 16, 2025 05:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

2 participants