Implement raw mDNS listener for immediate reconnection#69
Implement raw mDNS listener for immediate reconnection#69amandel wants to merge 1 commit intoseime:masterfrom
Conversation
|
Thanks @amandel . Initial thoughts:
|
|
Hi @seime, thanks for the feedback.
The friendly_name is populated with whatever is configured in the esphome yaml. I observed in the logs that we might get more trigger messages than expected, but since we can directly lookup the current connection state to decide if we need to act, this should be all fine. BTW: This mDNS listening increases the already fast reconnect time even compared with the low retry values from before. |
|
Regarding pt 2: This is part of the mdns traffic captured by wireshark - I have replaced the Do you see such mdns packets? |
|
Yes I see this. And I missed this because in my setup this is always == hostname. |
|
Now the deviceId is used. I'm not sure if we should do the same for the ESPHomeBluetoothProxyHandler? |
src/main/java/no/seime/openhab/binding/esphome/internal/discovery/ESPHomeRawMDNSListener.java
Outdated
Show resolved
Hide resolved
src/main/java/no/seime/openhab/binding/esphome/internal/discovery/ESPHomeRawMDNSListener.java
Outdated
Show resolved
Hide resolved
Please elaborate |
|
The esphomeHandlers currently only collects and reconnects esphome and not bluetooth thing types. I'm not sure if we need to take care for both. |
|
The Bluetooth proxy currently doesn't support connecting to devices, just passively listening to broadcasts for the time being. But when it gets there it would definately be useful to have it reconncet configured things as soon as they re-appear. PRs welcome as always :) |
|
I tested your branch, and the device came online in OH within a few seconds after regaining power. Nice! I noticed this log message: Since we don't use it (yet?), maybe set it to Another extension to this PR could be an option to switch of the automatic reconnect attempts and rather rely on this message based one? Or simply recommend to set the reconnect interval values high? Thanks for contributing! |
|
Thanks for the feedback. The info level was indeed a leftover. Surely we must not trigger a reconnect if the devices sends a goodby. This happens on a proper shutdown, so it should have sent a disconnect request before. I think there is nothing we can do with this message? I wonder if I should change the We could increase the defaults for the automatic reconnects. I'm a bit more careful for different types of setups now ;). There might be setups where the mDNS messages do no reach the openHAB instance (some Container setups). We could argue this setup needs a fix, but we can also use the current more fail safe defaults and suggest changes depending on the setup. |
|
IMHO ESPHome is moving forward at a pace faster than I can keep up with, especially with cornercase configurations and 100% feature parity (never had it and probably never will). Building and maintaining support for features nobody is actually using just slows down support for other future requests. The codebase is getting increasingly complex, and I think some refactoring/splitting of ESPHomeHandler is due (but after merging open PRs). But if you think it is an important update (I do have considered testing the "multidevice" features of ESPHome), I won't object nor refuse to merge :) |
420060a to
edffaaa
Compare
* Add `ESPHomeRawMDNSListener` to listen for mDNS packets directly on port 5353, bypassing JmDNS to avoid caching issues. * Implement manual mDNS packet parsing to detect `_esphomelib._tcp.local` services and extract deviceID. * Update `ESPHomeHandlerFactory` to track active handlers and dispatch reappearance events based on IP or hostname matching. * Add `onDeviceReappeared` to `ESPHomeHandler` to reset exponential backoff and trigger immediate connection.Make mDNS code more readable
edffaaa to
12774e1
Compare
|
@amandel is this still WIP or ready to merge? |
Can be merged. I wanted to change the title a while ago, but obviously failed. |
|
Thanks @amandel |
ESPhome devices that are mostly offline and only come online for a short amount of time, have to wait until a connection reattempt is performed to be able to come online. We could increase the number of reconnect attempts to get a faster reaction time. This PR solves this by listening to to 1st network action that every esphome device does after startup. We then can immediately respond with a connection attempt and so reduce the reconnect time to a minimum.
ESPHomeRawMDNSListenerto listen for mDNS packets directly on port 5353, bypassing JmDNS to avoid caching issues._esphomelib._tcp.localservices and extract hostnames.ESPHomeHandlerFactoryto track active handlers and dispatch reappearance events based on IP or hostname matching.onDeviceReappearedtoESPHomeHandlerto reset exponential backoff and trigger immediate connection.I did not expect this to become so complicated. This is work in progress - too much AI code I did not check - feedback welcome.