jstrausd / homebridge-simple-wled

Homebridge Plugin to control WLED LED-Strips
ISC License
63 stars 17 forks source link

Quick fix for WLED refusing to connect to homekit (2 weeks waisted for this πŸ˜…) #67

Open Dahman97 opened 5 months ago

Dahman97 commented 5 months ago

Hello amigos!

(Not interested in reading the how I fixed it? Jump to the 2nd section :)

I've spent days on end grappling with the challenge of connecting WLED to my HomeKit setup. I've tried everything – resets, deletions, cache clears, mDNS changes, and every conceivable solution I could unearth on the web over the past two weeks. Frustrated, I activated the debugging log to delve into what was happening under the hood. Lo and behold, I discovered a key on the WLED object that should specify the port it uses, but alas, it was undefined.

Moreover, my attempts to add a key-value pair to specify a port were futile. It refused to work and remained elusive. See the debug log below:

image

Determined to find a solution, I dug into what port WLED was running on and uncovered a disheartening revelation – it randomly changed the port with every restart. In my case, and likely many others, this posed a significant issue as I had a strict firewall in place. Firewalls, as we know, block connections that aren't explicitly allowed. The erratic port changes made the situation worse, forcing me to compromise my firewall if I wanted to integrate WLED with my HomeKit via Homebridge.


So, here's the fix – disable the firewall.

If you're using UFW (Uncomplicated Firewall), simply type:

ufw disable

To check if it's disabled, run:

ufw status

If you haven't installed UFW, I highly recommend doing so, as it's generally very user-friendly and allows for easy port management.

That's it! Hope this helps someone :)

As for @jstrausd, if you could implement a way to specify a fixed port for WLED, it would be awesome. Alternatively, having a designated port that remains consistent across restarts would be a game-changer. Thank you for the plugin, and have a fantastic weekend. Finally, I can pop a beer and enjoy my Hyperion ambient light setup with WLED added to my HomeKit! 😎

jstrausd commented 5 months ago

Hello, thanks for you post and information for others!

The ports are selected randomly by homebridge by default. However you can define your custom port range which homebridge selects one off for the accessories.

{ "bridge": { "name": "JRaspi - Homebridge", "username": "2E:78:C5:39:36:7C", "port": 51316, "pin": "111-11-111", "advertiser": "ciao" }, "ports": { "start": 20000, "end": 21000 },

Like in the snippet above, you can define a "ports" property which contains a start and end property to limit the ports which homebridge is selecting for an accessory. So with that you can predict in which range the port of the accessory is and create a custom ufw (Firewall) rule to accept only those ports.

Like ufw allow 20000: 21000/tcp ufw allow 20000: 21000/udp

I don't know if the accessory is accessed by udp or tcp (Maybe udp). But to be sure just open the port range for both protocols.

Thanks for the support <3

Dahman97 commented 5 months ago
    "start": 20000,

    "end": 21000

Thank you the super fast reply. I'll test this now. This will definitely help with future accessory's connection with HomeKit. πŸ‘πŸ‘β€οΈ