RealZimboGuy / ewelink-api-java

Java Api for the Sonoff ewelink
http://ewelink-api-java.co.zw/
15 stars 5 forks source link

503 error #5

Closed AlexOdsUa closed 1 year ago

AlexOdsUa commented 1 year ago

Hi

Thank for your job and java lib

A couple of days ago, the server started responding with the following error: Server returned HTTP response code: 503 for URL: https://eu-api.coolkit.cc:8080/api//user/device?lang=en&appid=******&ts=****&version=8&getTags=1

Is there an alternative server or could the reason be something else?

RealZimboGuy commented 1 year ago

Not sure, if you try with a server "us" instead of "eu" but my test it returns 301 with "eu" quite possibly a temp issue on their side as the login works but any functions get http 503. will check again tomorrow

madavraman commented 1 year ago

The issue is seen even with the Javascript library. Looks like the library needs to be upgraded to api-v2 https://github.com/skydiver/ewelink-api/issues/221#issuecomment-1716205345

RealZimboGuy commented 1 year ago

if you are able to mod the code and do a pull req, i can merge it. otherwise might only have time in a few days to look at this

robozb commented 1 year ago

I experienced the same error:

image

Thank you so much for your effort solving the issue :)

I'm trying to determine which server the application is communicating with

Bela

robozb commented 1 year ago

They have answered, but the primary result is same: Please refer to https://coolkit-technologies.github.io/eWeLink-API/#/en/APICenterV2?id=interface-domain-name image

Mainland China: https://cn-apia.coolkit.cn/
Asia: https://as-apia.coolkit.cc/
Americas: https://us-apia.coolkit.cc/
Europe: https://eu-apia.coolkit.cc/

All servers are unavailable: 503 Service Temporarily Unavailable

robozb commented 1 year ago

Their next asnwer:

Hello,

https://eu-api.coolkit.cc:8080/ We have stopped maintaining this API domain name for 3 years, please forget it,You can refer to the latest documentation to use it https://eu-apia.coolkit.cc/,As it is an API service, it must be accompanied by path requests, and usually direct access to domain names is not available. Our open API list:https://coolkit-technologies.github.io/eWeLink-API/#/zh-cmn/%E6%8E%A5%E5%8F%A3%E6%B8%85%E5%8D%95_v2

You can also use this code example https://github.com/coolkit-carl/eWeLinkOAuthLoginDemo ,Register as a personal developer for eWeLink and manage your own devices.

If you plan to pay for it, you can use all the open interface content of v2.

robozb commented 1 year ago

Their last answer:

"Greetings,

We appreciate your engagement with our services.

Our server has observed a substantial influx of requests originating from this project. After a thorough analysis, we've identified that many users are utilizing default personal APPID configuration parameters. However, as this project still employs the v1 interface, which is no longer under maintenance, it's leading to various issues.

To ensure interface security and mitigate potential risks, we are gradually discontinuing the v1 interface and will render it entirely inaccessible in the future.

We encourage individual users to utilize the eWeLink Developer Center for free. By visiting https://dev.ewelink.cc/, you can create your own application and obtain a unique APPID. This personalized APPID can be used continuously within reasonable limits.

We've also taken note of reports from numerous users indicating certain feature limitations due to the project being inactive for the past three years. An alternative option available is the https://www.npmjs.com/package/ewelink-api-next library. This library leverages the v2 interface and has comprehensively encapsulated all available v2 interfaces. It offers local area network discovery, and control functionalities, and facilitates bidirectional communication with devices through established WebSocket connections. This enables real-time data exchange and receipt of device-generated updates.

Should you require further information or assistance, please don't hesitate to contact us.

Best regards"

RealZimboGuy commented 1 year ago

I have done the application process on the ewelink portal, if i can figure out the process will update the java api to use it. but so far it seems i have to wait a day or two for them to approve the api access

robozb commented 1 year ago

I have experienced the same :) Thank you so much!

RealZimboGuy commented 1 year ago

i have the new new website partially reversed in terms of the APIs will keep working through them to try get all the basic functionality working

robozb commented 1 year ago

since then I have received API permission, I will see what the possibilities are

RealZimboGuy commented 1 year ago

@robozb @madavraman @AlexOdsUa a new version is out (should be on maven central in a few hours) please can you test and let me know. sadly had to change quite a bit of code so its a breaking change

robozb commented 1 year ago

@robozb @madavraman @AlexOdsUa a new version is out (should be on maven central in a few hours) please can you test and let me know. sadly had to change quite a bit of code so its a breaking change

I'll do that soon! Thank you so much!

robozb commented 1 year ago

Dear @RealZimboGuy ,

Shouldn't I use the data on the surface below somewhere in the login process?

image

Especially the APPID and APP SECRET?

Thank you so much!

Bela

RealZimboGuy commented 1 year ago

@robozb you should be able to just use the code as is, filling in the correct login info. ie

        EweLink eweLink = new EweLink("eu", "test@gmail.com", "test", "+263",60);

i tested with my account details and another friends. the background i dug through the current ewelink android app to find the endpoints and login sequence etc.

RealZimboGuy commented 1 year ago

can you try run the TestCode class in the test folder with your credentials

robozb commented 1 year ago

Sorry, It worked, I can reach the devices :) I'm trying to switch on and off those right now

RealZimboGuy commented 1 year ago

great, so i had to move the on/off logic through the websocket as i couldnt find a basic http endpoint that controls them

robozb commented 1 year ago

Wow, beautiful! It can switch the devices :) Amazing :)

robozb commented 1 year ago

Finally, Should I set the api key to mine? Thank you so much!

RealZimboGuy commented 1 year ago

so it automatically pulls your api key from the response of the login sequence

image

robozb commented 1 year ago

Oh, I see, wonderful :) Thank you so much again!

robozb commented 1 year ago

How do I have to prevent this situation when the key is null? Occurs when one of the sonoff device(a lamp switcher) is unavailable:

2023-09-25 16:57:47.754 [WebSocketConnectReadThread-17] ERROR org.java_websocket.drafts.Draft_6455 - Runtime exception during onWebsocketMessage
java.lang.NullPointerException: key cannot be null
        at net.jodah.expiringmap.internal.Assert.notNull(Assert.java:14) ~[expiringmap-0.5.10.jar:?]
        at net.jodah.expiringmap.ExpiringMap.put(ExpiringMap.java:909) ~[expiringmap-0.5.10.jar:?]
        at com.github.realzimboguy.ewelink.api.EweLinkWebSocketClient.parseMessage(EweLinkWebSocketClient.java:64) ~[ewelink-api-java-3.0.0-RELEASE.jar:?]
        at com.github.realzimboguy.ewelink.api.EweLinkWebSocketClient.onMessage(EweLinkWebSocketClient.java:56) ~[ewelink-api-java-3.0.0-RELEASE.jar:?]
        at org.java_websocket.client.WebSocketClient.onWebsocketMessage(WebSocketClient.java:593) ~[Java-WebSocket-1.5.1.jar:?]
        at org.java_websocket.drafts.Draft_6455.processFrameText(Draft_6455.java:885) [Java-WebSocket-1.5.1.jar:?]
        at org.java_websocket.drafts.Draft_6455.processFrame(Draft_6455.java:819) [Java-WebSocket-1.5.1.jar:?]
        at org.java_websocket.WebSocketImpl.decodeFrames(WebSocketImpl.java:379) [Java-WebSocket-1.5.1.jar:?]
        at org.java_websocket.WebSocketImpl.decode(WebSocketImpl.java:216) [Java-WebSocket-1.5.1.jar:?]
        at org.java_websocket.client.WebSocketClient.run(WebSocketClient.java:506) [Java-WebSocket-1.5.1.jar:?]
        at java.lang.Thread.run(Thread.java:829) [?:?]
RealZimboGuy commented 1 year ago

not sure how that is null but have added a check and pushed 3.0.1 RELEASE

robozb commented 1 year ago

Dear @RealZimboGuy,

Thanks again! I was able to restore my system :)

Kind Regards: Beci

robozb commented 1 year ago

How do I have to prevent this situation when the key is null? Occurs when one of the sonoff device(a lamp switcher) is unavailable:

2023-09-25 16:57:47.754 [WebSocketConnectReadThread-17] ERROR org.java_websocket.drafts.Draft_6455 - Runtime exception during onWebsocketMessage
java.lang.NullPointerException: key cannot be null
        at net.jodah.expiringmap.internal.Assert.notNull(Assert.java:14) ~[expiringmap-0.5.10.jar:?]
        at net.jodah.expiringmap.ExpiringMap.put(ExpiringMap.java:909) ~[expiringmap-0.5.10.jar:?]
        at com.github.realzimboguy.ewelink.api.EweLinkWebSocketClient.parseMessage(EweLinkWebSocketClient.java:64) ~[ewelink-api-java-3.0.0-RELEASE.jar:?]
        at com.github.realzimboguy.ewelink.api.EweLinkWebSocketClient.onMessage(EweLinkWebSocketClient.java:56) ~[ewelink-api-java-3.0.0-RELEASE.jar:?]
        at org.java_websocket.client.WebSocketClient.onWebsocketMessage(WebSocketClient.java:593) ~[Java-WebSocket-1.5.1.jar:?]
        at org.java_websocket.drafts.Draft_6455.processFrameText(Draft_6455.java:885) [Java-WebSocket-1.5.1.jar:?]
        at org.java_websocket.drafts.Draft_6455.processFrame(Draft_6455.java:819) [Java-WebSocket-1.5.1.jar:?]
        at org.java_websocket.WebSocketImpl.decodeFrames(WebSocketImpl.java:379) [Java-WebSocket-1.5.1.jar:?]
        at org.java_websocket.WebSocketImpl.decode(WebSocketImpl.java:216) [Java-WebSocket-1.5.1.jar:?]
        at org.java_websocket.client.WebSocketClient.run(WebSocketClient.java:506) [Java-WebSocket-1.5.1.jar:?]
        at java.lang.Thread.run(Thread.java:829) [?:?]

This was the only "issue" what I experienced.

RealZimboGuy commented 1 year ago

just use V 3.0.1-RELEASE i was assuming that all messages coming in on the websocket have a sequence but thats clearly not the case. the sequence in the timed hashmap is what is being used when you do a switch state change so we can track the request/response on ie setDeviceStatus, the boolean return is that wait for the response