fixje / deflux

Write deCONZ sensor measurements to InfluxDB
MIT License
2 stars 2 forks source link

Unable to retrieve data from deconz #5

Open muppel2 opened 3 months ago

muppel2 commented 3 months ago

Dear deflux team,

I have installed deflux on my RaspberrPi4 running on Raspbian (Bullseye).

When I try to acquire an API key or retrieve data from the websocket (after manually retrieving the API key using POSTMAN), deflux always reports an error:

time=2024-06-10T12:39:04.022+02:00 level=ERROR msg="Failed to fetch sensors: %s" !BADKEY="unable to decode deCONZ /sensors response: invalid character '<' looking for beginning of value"

or

time=2024-06-10T12:36:37.184+02:00 level=ERROR msg="Could not create websocket reader: %s" !BADKEY="unable to populate sensor cache: unable to decode deCONZ /sensors response: invalid character '<' looking for beginning of value"

My config files looks like:

deconz:
  addr: http://192.168.3.118:80/`
  apikey: "[snip]"
  wsaddr: "ws://192.168.3.118:443"
influxdb:
  url: http://localhost:8086
  token: [snip]
  org: CHI
  bucket: zigbee
fillvalues:
  enabled: false
  initialfill: true
  fillinterval: 30m0s
  lastseentimeout: 2h0m0s

(the port ":80" worked for the API key generation)

Go reports go version go1.22.4 linux/arm64

Is this a configuration mistake on my side or more an issue in deflux?

rvk01 commented 3 months ago

Are you sure the wsaddr is correct? Why not just remove it and let the code auto-discover this by itself?

muppel2 commented 3 months ago

Thank you for your quick reply!

That was my first try as well, but it failed (Deconz was open for new registrations at that moment):

/root/go/bin/deflux -config-gen

## deCONZ Gateway discovery failed: unable to parse json from discovery endpoint: invalid character '<' looking for beginning of value. Complete config manually.
## Could not pair with deconz: unable to send post request: Post "http://127.0.0.1:8080/api": dial tcp 127.0.0.1:8080: connect: connection refused
## Please add the API key manually
deconz:
  addr: http://127.0.0.1:8080/
  apikey: ""
  wsaddr: ""
influxdb:
  url: http://localhost:8086
  token: SECRET
  org: organization
  bucket: default
fillvalues:
  enabled: false
  initialfill: true
  fillinterval: 30m0s
  lastseentimeout: 2h0m0s

Deconz does not answer for me on Port :8080, only :80 - this it where I manually retrieved the auth key. is it possible to autodetect also on port :80 ?

rvk01 commented 3 months ago

Deconz does not answer for me on Port :8080, only :80 - this it where I manually retrieved the auth key. is it possible to autodetect also on port :80 ?

It's been a while since I had deconz running... But do you have it on the same computer as this script? (Because of the 127.0.0.1 while you had 192.168.3.118 before).

Why 8080? I thought it was just port 80 (but leave it off, 80 is default). Then just use addr: http://127.0.0.1 That is... If it's on the same computer. If it's on another computer, then try to change the ip and use the 8080. Then the connection refused was just because you used 127.0.0.1 localhost.

Did you already got an api-key? What does http://x.x.x.x/api/[api-key]/config give you in a browser? That's the way, if only http://x.x.x.x:yyyy and apikey is given, it does the discovery for the websocket.

See docs at https://dresden-elektronik.github.io/deconz-rest-doc/endpoints/configuration/

(Result will have "websocketport": xx in it. So it's not needed to provide this manually)

muppel2 commented 3 months ago

The pasted output comes completely from the deflux -config-gen command. The correct IP would indeed be 192.168.3.118 and I do prefer :80 as well since my Deconz is listening there.

What makes me wonder is the unable to parse json from discovery endpoint: invalid character '<' looking for beginning of value.

If I manually populate the config file, someting similar appears: unable to decode deCONZ /sensors response: invalid character '<' looking

I have an API key, placed in the deflux.yml but same result.

Querying http://192.168.3.118/api/RemovedHexKey/config gave me "websocketport":443

rvk01 commented 3 months ago

The pasted output comes completely from the deflux -config-gen command. The correct IP would indeed be 192.168.3.118 and I do prefer :80 as well since my Deconz is listening there.

Are you sure the api is also really listening on that port. I now see default for the api could be 8080. So try addr: http://192.168.3.118:8080/

What makes me wonder is the unable to parse json from discovery endpoint: invalid character '<' looking for beginning of value.

If you are listening on a http port which just spits out html code, you'll get that error. It's not json what you get back. The api url should give json back. If you already have an api key fill that one in too.

addr: http://192.168.3.118:8080/ apikey: "known_api_key"

Nothing else. It will detect the correct websocket itself (if all goes well).

If you don't have a valid api key yet then leave that one empty, it should get it (if you put deconz in new client mode).

Gr. It's really been a ling time. Maybe you do need /api after it

addr: http://192.168.3.118:8080/api apikey: "known_api_key"

muppel2 commented 3 months ago

The discovery problem might be caused by a failing call to "https://dresden-light.appspot.com/discover". If I query the URL via browser, it returns

Error: Server Error
The server encountered an error and could not complete your request.
Please try again in 30 seconds.
rvk01 commented 3 months ago

The discovery problem might be caused by a failing call to "https://dresden-light.appspot.com/discover".

Yes, but I think the external discover is only used to fill in the IP. If you fill that in manually it should just work locally. So try both suggestion above to see uf the apikey gets retrieved. (And if you have one, fill it in)