Smarteon / loxone-java

Java implementation of the Loxoneā„¢ communication protocol (Web Socket)
BSD 3-Clause "New" or "Revised" License
15 stars 10 forks source link

Unable to authenticate within timeout with retry #142

Closed NunoNogueira99 closed 2 years ago

NunoNogueira99 commented 2 years ago

Hello good afternoon

Can someone help me, I'm trying to make an app to communicate with Loxone, when I run the library it's giving me this error (image), tell me how can i solve this problem.

image

jimirocks commented 2 years ago

Hello, the problem is most probably in credentials, since it says Unable to authenticate ... but can also be some network problem. I can't say more from the image. So beeing you, I would double check the loxone miniserver is reachable, all the http and websocket relevant ports are not blocked and also the credentials used are correct. If you can share the snippet of the code and also the full stack trace I can try to guess better.

NunoNogueira99 commented 2 years ago

these is my code

image

these are the settings in loxone

image

NunoNogueira99 commented 2 years ago

full stack trace

image

jimirocks commented 2 years ago

Well the code looks OKish, but there still can be some connection issue - have you tried to reach the miniserver just by http? ie. using LoxoneHttp. Also try to use some notauthenticated endpoints like jdev/cfg/api. Also the library does pretty good logging using slf4j - if you bind it to your andorid logger and set the eevel on trace you should see lot of stuff and most probably also the reason of the failure.

Due to aynchronous processing of the authentication, it's not possible to reveal more from the exception.

NunoNogueira99 commented 2 years ago

Good afternoon

I tried to run the code without being in an asynchronous function but it gives me the NetworkOnMainThreadException exception so I put the code in an asynchronous function.

Could you show me some code on how to send commands to loxone? And how to use LoxoneHttp? And how to use slf4j? please

I'm sorry to bother you but I'm starting to learn about Loxone

thanks

jimirocks commented 2 years ago
new LoxoneHttp(new LoxoneEndpoint(address)).get(LoxoneMessageCommand.DEV_CFG_API)

As for slf4j, there is slf4j-android project providing binding for. To see the maximum info from the library set level for cz.smarteon.loxone to TRACE.

Generally I advise you to read the Loxone documentation referred from README of this library and also go through the library javadoc and even the source code - it's nothing very complicated.

NunoNogueira99 commented 2 years ago

good afternoon thank you very much for your help.

Can you help me with something else that I still haven't figured out how to do, it is possible instead of fetching the uuid to fetch its name like for example uuid = 12678ee3-02d4-b1a1-ffbc112233445566 corresponds to the attic name

I've already been reading the documentation

Tank you

jimirocks commented 2 years ago

Well that's very generic question, but generally such information could be found in LoxoneApp. However this library doesn't parse it completely - contributions are welcomed.

jimirocks commented 2 years ago

Does this mean your original question is resolved?

NunoNogueira99 commented 2 years ago

Yes it is

The problem is in the programming of loxone, after several tests, changes of permissions in loxone and analysis of the xml code of loxone, I found that when you create a user in LoxoneConfig 12.2 it is added an "alg" variable (which I assume is the algorithm used to encrypt the password) that makes the library unable to authenticate.

Only a few hours ago I managed to solve the problem, now I was trying to understand how to solve this problem in the library, this algorithm must have to add.

In the image, you can see the variable "alg" that I say image

jimirocks commented 2 years ago

hmm it may be the case, they changed the algorithm somehow. I will try to investigate. In the meantime, if you have the trace log, it can definitely help to resolve the issue.

jimirocks commented 2 years ago

So looks like the BUG in the library - it ommits the hashing algorithm value returned by jdev/sys/getkey2/{user} and always uses SHA-1 algorithm. Probably all known miniservers we have accessible use SHA-1 so far. Please could you share the result of aforementioned command on your miniserver?

NunoNogueira99 commented 2 years ago

image

jimirocks commented 2 years ago

That's interesting, so the Alg="1" in the config means something else šŸ¤” . The trace log would help - to see which step of authentiction actually fails.

jimirocks commented 2 years ago

Or at least describe the steps in config to reach the state you have

NunoNogueira99 commented 2 years ago

Isso Ć© interessante, entĆ£o o Alg="1"na configuraĆ§Ć£o significa outra coisašŸ¤”. O log de rastreamento ajudaria - para ver qual etapa de autenticaĆ§Ć£o realmente falha.

what you intended was this right?

image

jimirocks commented 2 years ago

No the library can log a lot of useful information when you turn it on, as I already wrote:

As for slf4j, there is slf4j-android project providing binding for. To see the maximum info from the library set level for cz.smarteon.loxone to TRACE.

NunoNogueira99 commented 2 years ago

I'm sorry if that's not what you want, but as I've never used slf4j android, I'm not sure what your output is. I put this on the build:gradel (:app) in dependencies as you can see in the image image

image

if that's not what you want, will you be able to help configure it?

jimirocks commented 2 years ago

Well I am not and android expert, but it seems the most uptodate is to use rather android-logback

There is XML file, when you can set cz.smarteon.loxone logger to TRACE

jimirocks commented 2 years ago

Released new version 2.0.2 with fix of the user algorithm used. Could fix the issue - can you please try?

NunoNogueira99 commented 2 years ago

Good night, sorry for only answering now, but yesterday I made the changes you mentioned in the pull requests but I couldn't test. Today I've only been able to try it now, and I tried it and it seemed to be working. Thank you very much for the quick resolution of this little problem

jimirocks commented 2 years ago

OK I am glad, that it helped.