pizzalorddex / homebridge-unifi-ap-light

Control the light rings on your UniFi Wireless Access Point(s) with HomeKit
Apache License 2.0
0 stars 0 forks source link

Request failed with status code 404 #3

Closed daywalkeraut closed 1 month ago

daywalkeraut commented 1 month ago

Describe The Bug: It is an UDR (Unifi Dream Router) not an UDM (Unifi Dream Machine)

At Starting from HomeBridge I get that Message.

With Port 8443 [UniFi AP Lights] Both authentication methods failed: AxiosError: Request failed with status code 404 [UniFi AP Lights] Device discovery failed: Request failed with status code 404

Without Port [UniFi AP Lights] Device discovery failed: Request failed with status code 404

To Reproduce: UDR (Unifi Dream Router) run on UniFi OS 3.2.12 UniFi Network run on Version 8.1.127 Install plugin with Homebridge and configure from Documentation

Expected behavior:

Logs:

With Port 8443
[UniFi AP Lights] Both authentication methods failed: AxiosError: Request failed with status code 404
[UniFi AP Lights] Device discovery failed: Request failed with status code 404

Without Port
[UniFi AP Lights] Device discovery failed: Request failed with status code 404

Plugin Config:

{
  "name": "UniFi AP Lights",
  "platform": "UnifiAPLight",
  "host": "192.1XX:X:X:8443",
  "username": "XXXXXX",
  "password": "XXXXXX"
}

or 

{
  "name": "UniFi AP Lights",
  "platform": "UnifiAPLight",
  "host": "192.1XX:X:X",
  "username": "XXXXXX",
  "password": "XXXXXX"
}

Screenshots:

Environment:

pizzalorddex commented 1 month ago

Hello @daywalkeraut! I have made some minor changes, including support (I hope!) for UDM and UDR devices.

Before reinstalling please enable debug mode for homebridge in the homebridge settings.

After enabling debug mode please reinstall the plugin. Your issue will probably not be fixed, but hopefully we can now see in the logs exactly why it is failing.

daywalkeraut commented 1 month ago

Hello Pizzalorddex,

always when I write your name I want eat a Pizza :-)

Thank you so much for you Work. You change so much on the Plugin from Yesterday to today. Amazing

I have some information for you from the debug mode.

With Port 8443

[5/16/2024, 3:47:03 PM] [UniFi AP Lights] Primary authentication method failed, attempting secondary. (node:8537) [DEP0123] DeprecationWarning: Setting the TLS ServerName to an IP address is not permitted by RFC 6066. This will be ignored in a future version. (Use node --trace-deprecation ... to show where the warning was created) [5/16/2024, 3:47:04 PM] [UniFi AP Lights] Both authentication methods failed: AxiosError: Request failed with status code 404 Requesting URL: /s/default/stat/device Endpoint not found: /s/default/stat/device, trying next endpoint Requesting URL: /proxy/network/api/s/default/stat/device [5/16/2024, 3:47:04 PM] [UniFi AP Lights] Device discovery failed: Request failed with status code 404

Without Port

[5/16/2024, 3:48:43 PM] [UniFi AP Lights] Authentication with secondary method successful. Requesting URL: /s/default/stat/device Endpoint not found: /s/default/stat/device, trying next endpoint Requesting URL: /proxy/network/api/s/default/stat/device [5/16/2024, 3:48:44 PM] [UniFi AP Lights] Device discovery failed: Request failed with status code 404

Have a Nice Day

pizzalorddex commented 1 month ago

Ok, thanks! Looks like you only need to test without the port number :) Logging into the API is not a problem and uses the correct URL. That is very good!

It fails requesting devices from the API so I suspect it is a problem with how I am creating the URL for your usage.

I have updated the plugin (1.2.8), please test with this version to see if it is working.

daywalkeraut commented 1 month ago

Moved to https://github.com/pizzalorddex/homebridge-unifi-ap-light/issues/4#issuecomment-2116130768

Good Evening Pizzalorddex,

you really AMAZING.

Looks better. The plugin start an load an find my two AP the UAP-AC-IW and the Unifi Dream Router and I also get two toggle in HomeKit. The UAP-AC-IW toggle works can turn on and off the Blue LED from the UAP-AC-IW The Unifi Dream Router toggle I can press on and off butt the Blue LED from the Unifi Dream Router do nothing.

But it is already a very good way both toggle appear good work nice 👍

Hier some logs.

[UniFi AP Lights] Finished loading, starting device discovery.

[UniFi AP Lights] Primary authentication method failed, attempting secondary.

[UniFi AP Lights] Authentication with secondary method successful. Requesting URL: /api/s/default/stat/device Endpoint not found: /api/s/default/stat/device, trying next endpoint Requesting URL: /proxy/network/api/s/default/stat/device

[UniFi AP Lights] Adding new accessory: UAP-AC-IW (123456789abcd……..) [UniFi AP Lights] Adding new accessory: Unifi Dream Router (987654321abc……..)

[UniFi AP Lights] Successfully set LED state for Unifi Dream Router to on. (Nothing Happen) [UniFi AP Lights] Successfully set LED state for Unifi Dream Router to off. (Nothing Happen)

[UniFi AP Lights] Successfully set LED state for UAP-AC-IW to on. (Blue LED turn ON) [UniFi AP Lights] Successfully set LED state for UAP-AC-IW to off. (Blue LED turn OFF)

Thanks Again for your Work an Time you a Genius

pizzalorddex commented 1 month ago

Moved to https://github.com/pizzalorddex/homebridge-unifi-ap-light/issues/4#issuecomment-2116135178

Thanks for the feedback. I was hoping it would be simple, but it looks like it isn't so simple. Let me research this a bit more to see if it is possible. I may ask you to run a few commands to gather information about the UDR. I guess it handles its light differently than WAPs.

daywalkeraut commented 1 month ago

Moved to https://github.com/pizzalorddex/homebridge-unifi-ap-light/issues/4#issuecomment-2116136768

Yes of course you can tell me what commands I should run where.

I will take some screenshots later and post it here for you I think I see what is different.

daywalkeraut commented 1 month ago

Moved to https://github.com/pizzalorddex/homebridge-unifi-ap-light/issues/4#issuecomment-2116138395

Here the Picture what I found what is different. Better Picture because I can not explain maybe you would understand me wrong.

1 UAP-AC-IW 2 UDR 3 Console Settings 4 Consol Settings

pizzalorddex commented 1 month ago

Moved to https://github.com/pizzalorddex/homebridge-unifi-ap-light/issues/4#issuecomment-2116140215

Thanks for the additional pictures! That makes it a little more clear for me. It also makes me worried because the app would need to use the API to control the light. If it is not supported in the app it is hard to say if the plugin can support it.

I am sorry, but this will be a long message. If you don't understand anything I will be happy to answer!



To check further there are some commands you can run from a linux machine, like your raspberry pi. Anything in the commands you need to replace with your own information I will put in < >

First we need to log into the API to copy a couple tokens using this command: curl -k -i -X POST "https://<YOUR-HOST>/api/auth/login" -H "Content-Type: application/json" -d '{"username": "<YOUR-USERNAME>", "password": "<YOUR-PASSWORD>"}'

You should see a message like this: HTTP/1.1 200 vary: Origin Set-Cookie: unifises=THE-FIRST-TOKEN; Path=/; HttpOnly Set-Cookie: csrf_token=THE-SECOND-TOKEN; Path=/ X-Frame-Options: DENY Content-Type: application/json;charset=UTF-8 Content-Length: 30 Date: SOME-DAY-AND-TIME GMT

From this message we need both of the sets of random numbers and letters for unifises and csrf_token. Using these we can actually talk to the API.

Next, we can run this command to see what capabilities the udr has: curl -k -X GET "https://<YOUR-HOST>/proxy/network/api/s/default/stat/device" -H "Content-Type: application/json" -H "Cookie: unifises=<YOUR-UNIFISES-TOKEN>; csrf_token=<YOUR-CSRF_TOKEN>" | jq '.data[] | select(.type == "udm") | {id: ._id, name: .name, type: .type, model: .model, capabilities: (. | with_entries(select(.key | contains("led"))))}'

You should see a message like this: { "id": "AN-ID-NUMBER", "name": "NAME-OF-DEVICE", "type": "udm", "model": "UDR", "capabilities": { "mesh_sta_vap_enabled": false, "led_override_color": "#0000FF", "atf_enabled": false, "dot1x_portctrl_enabled": false, "led_override": "on", "led_override_color_brightness": 100, "vwireEnabled": false }

You can censor the id and name, those are not important. This should be your UDR. For type: it should say udm and for model: it should say UDR.

In this list it is very important that there is something like led_override.

Please send this so I can see what is available on the UDR to play with :)

pizzalorddex commented 1 month ago

The initial bug has been solved. All messages regarding the new feature to support UDR LED control have been moved to #4 Add Support For UDR LED Control. We can continue the conversation there @daywalkeraut :)