delid4ve / openhab-3.x-sonoff

Openhab Binding for Sonoff Devices
26 stars 11 forks source link

[OH 3.3] cannot conect to the cloud #18

Open pasman1 opened 2 years ago

pasman1 commented 2 years ago

Your binding works with openhab 3.2, but with openhab 3.3 cannot connect to sonoff cloud. Precompiled version org.openhab.binding.sonoff-3.2.0-SNAPSHOT_2.5R10.jar installed in snap openhab 3.3

theclive commented 2 years ago

I'm having the same problem. Been using this binding for ages but today I noticed the cloud aint working (local still works). Here are some debug logs

I redacted my UN/PWD. I've noticed two things:

1) The countryCode is incorrect but I don't see anywhere to set this. 2) One of the logs shows appid is unauthorized

Binding Version: org.openhab.binding.sonoff-3.2.0-SNAPSHOT_2.5R10.jar openHAB Version: 3.1.0 (openhabian)

Debug Logs:

2022-07-06 18:49:53.657 [DEBUG] [nternal.handler.SonoffAccountHandler] - Initialising Sonoff Account: sonoff:account:b0ebf0a5af
2022-07-06 18:49:53.659 [INFO ] [nternal.handler.SonoffAccountHandler] - Sonoff Access Mode set to: mixed
2022-07-06 18:49:53.669 [DEBUG] [.sonoff.internal.SonoffCacheProvider] - Added new state for device 1000a1d855
2022-07-06 18:49:53.681 [DEBUG] [.sonoff.internal.SonoffCacheProvider] - Added new state for device 10008e93c7
2022-07-06 18:49:53.690 [DEBUG] [.sonoff.internal.SonoffCacheProvider] - Added new state for device 1000a1677c
2022-07-06 18:49:53.691 [DEBUG] [unication.SonoffCommunicationManager] - Message queue is running
2022-07-06 18:49:53.695 [DEBUG] [ernal.connection.SonoffLanConnection] - mDNS service has been started on IP 127.0.0.1
2022-07-06 18:49:53.699 [DEBUG] [ernal.connection.SonoffLanConnection] - mDNS service has been started on IP 172.16.10.50
2022-07-06 18:49:53.701 [DEBUG] [l.connection.SonoffConnectionManager] - Lan connected
2022-07-06 18:49:53.711 [DEBUG] [ernal.connection.SonoffApiConnection] - Api Login Request:{"email":"xxxxxxxxxxxx","password":"xxxxxxxxxxxxx","countryCode":"+1"}
2022-07-06 18:49:53.717 [DEBUG] [rnal.handler.SonoffBaseDeviceHandler] - Initialising device: sonoff:1:b0ebf0a5af:10008e93c7
2022-07-06 18:49:53.721 [DEBUG] [rnal.handler.SonoffBaseDeviceHandler] - Initialising device: sonoff:1:b0ebf0a5af:1000a1d855
2022-07-06 18:49:53.724 [DEBUG] [ng.sonoff.internal.SonoffTaskManager] - Stopping local polling for 
2022-07-06 18:49:53.726 [DEBUG] [ng.sonoff.internal.SonoffTaskManager] - Stopping local polling for 
2022-07-06 18:49:53.727 [DEBUG] [ng.sonoff.internal.SonoffTaskManager] - Stopping consumption polling for 
2022-07-06 18:49:53.727 [DEBUG] [ng.sonoff.internal.SonoffTaskManager] - Stopping consumption polling for 
2022-07-06 18:49:53.728 [DEBUG] [rnal.handler.SonoffBaseDeviceHandler] - bridgeStatusChanged ONLINE (COMMUNICATION_ERROR): Cloud Offline for thing sonoff:1:b0ebf0a5af:1000a1d855
2022-07-06 18:49:53.728 [DEBUG] [rnal.handler.SonoffBaseDeviceHandler] - bridgeStatusChanged ONLINE (COMMUNICATION_ERROR): Cloud Offline for thing sonoff:1:b0ebf0a5af:10008e93c7
2022-07-06 18:49:53.730 [DEBUG] [rnal.handler.SonoffBaseDeviceHandler] - Requesting local update for 1000a1d855
2022-07-06 18:49:53.730 [DEBUG] [rnal.handler.SonoffBaseDeviceHandler] - Requesting local update for 10008e93c7
2022-07-06 18:49:53.733 [DEBUG] [rnal.handler.SonoffBaseDeviceHandler] - Requesting cloud update for 10008e93c7
2022-07-06 18:49:53.733 [DEBUG] [rnal.handler.SonoffBaseDeviceHandler] - Requesting cloud update for 1000a1d855
2022-07-06 18:49:53.733 [DEBUG] [unication.SonoffCommunicationManager] - Added a message to the queue
2022-07-06 18:49:53.734 [DEBUG] [l.connection.SonoffConnectionManager] - Unable to request cloud update as the connection is offline
2022-07-06 18:49:53.736 [DEBUG] [unication.SonoffCommunicationManager] - Added a message to the queue
2022-07-06 18:49:53.739 [DEBUG] [ng.sonoff.internal.SonoffTaskManager] - Stopping local polling for 1000a1d855
2022-07-06 18:49:53.740 [DEBUG] [ng.sonoff.internal.SonoffTaskManager] - Stopping consumption polling for 1000a1d855
2022-07-06 18:49:53.743 [DEBUG] [ng.sonoff.internal.SonoffTaskManager] - Stopping local polling for 10008e93c7
2022-07-06 18:49:53.745 [DEBUG] [ng.sonoff.internal.SonoffTaskManager] - Stopping consumption polling for 10008e93c7
2022-07-06 18:49:53.835 [DEBUG] [unication.SonoffCommunicationManager] - Message queue is running
2022-07-06 18:49:53.836 [DEBUG] [l.connection.SonoffConnectionManager] - Unable to request cloud update as the connection is offline
2022-07-06 18:49:53.941 [DEBUG] [unication.SonoffCommunicationManager] - Message queue is running
2022-07-06 18:49:53.971 [DEBUG] [unication.SonoffCommunicationManager] - Updated state for 10008e93c7, with data {"data1":"NNk2supfOdkvgF61iJ9bjeZliAvecAUrHhp14wKCSy+7XIUC8XbON+QP39AwsgYV6XpNIMyVeAnpWePAZMIHN3fiYJF+qKfNO9J0g2tSN+kSdpCpNfxLowqzT0cCLbm2reZPj2rqgTUJEM3aVIRFWUGaBNkvqFEYfxd1UYBpgdfKTxTWpoKXUFz8QQn9wOrF","seq":"28","iv":"NTE5NDI1MjQxOTI4NjY0Nw\u003d\u003d","apivers":"1","type":"plug","txtvers":"1","encrypt":"true","deviceid":"10008e93c7","localAddress":"172.16.10.81","params":{"switch":"on","startup":"off","pulse":"off","sledOnline":"on","pulseWidth":500,"rssi":-59,"ssid":"Munro-CAM","bssid":"00:00:00:00:00:00"},"ipaddress":"172.16.10.81"}
2022-07-06 18:49:53.977 [DEBUG] [ng.sonoff.internal.SonoffTaskManager] - Stopping local polling for 10008e93c7
2022-07-06 18:49:53.978 [DEBUG] [ng.sonoff.internal.SonoffTaskManager] - Stopping consumption polling for 10008e93c7
2022-07-06 18:49:53.979 [DEBUG] [nternal.handler.SonoffAccountHandler] - Added IP Address 10008e93c7 for device 172.16.10.81
2022-07-06 18:49:54.046 [DEBUG] [ernal.connection.SonoffApiConnection] - Api Login Response:{"error":407,"msg":"appid is unauthorized! oeVkj2lYFGnJu5XUtWisfW4utiN4u9Mq","data":null}
2022-07-06 18:49:54.048 [DEBUG] [l.connection.SonoffConnectionManager] - Api disconnected
2022-07-06 18:49:54.049 [DEBUG] [connection.SonoffWebSocketConnection] - Stopping websocket client
Sil-SP commented 2 years ago

It seems there was a change in the cloud connection, we are alone: https://community.home-assistant.io/t/new-sonoff-problem/437256

pasman1 commented 2 years ago

In home-assistant is message appid is unauthorized too. They solved the issue using the second appid.

https://github.com/AlexxIT/SonoffLAN/issues/887

jgesser commented 1 year ago

I did the change to use the second appid from home assistant source code and now it's working for me. PR: https://github.com/delid4ve/openhab-3.x-sonoff/pull/19

JalejandroV93 commented 1 year ago

I have problems to compile sonoff binding with new API, can you explain me, thanks.

jgesser commented 1 year ago

I uploaded the compiled version for those who are not able to compile it: https://github.com/jgesser/openhab-3.x-sonoff/releases/download/v3.3.0-SNAPSHOT/org.openhab.binding.sonoff-3.3.0-SNAPSHOT.jar

JacekKac commented 1 year ago

After installing and first restart OK but after that only :


 Exception occurred while initializing handler of thing 'sonoff:account:15369a9f6d': Index 2 out of bounds for length 2
java.lang.IndexOutOfBoundsException: Index 2 out of bounds for length 2
        at jdk.internal.util.Preconditions.outOfBounds(Preconditions.java:64) ~[?:?]
        at jdk.internal.util.Preconditions.outOfBoundsCheckIndex(Preconditions.java:70) ~[?:?]
        at jdk.internal.util.Preconditions.checkIndex(Preconditions.java:248) ~[?:?]
        at java.util.Objects.checkIndex(Objects.java:372) ~[?:?]
        at java.util.ArrayList.get(ArrayList.java:459) ~[?:?]
        at com.google.gson.JsonArray.get(JsonArray.java:203) ~[bundleFile:?]
        at org.openhab.binding.sonoff.internal.handler.SonoffDeviceState.setParameters(SonoffDeviceState.java:112) ~[?:?]
        at org.openhab.binding.sonoff.internal.handler.SonoffDeviceState.updateState(SonoffDeviceState.java:80) ~[?:?]
        at org.openhab.binding.sonoff.internal.handler.SonoffDeviceState.<init>(SonoffDeviceState.java:64) ~[?:?]
        at org.openhab.binding.sonoff.internal.SonoffCacheProvider.getStates(SonoffCacheProvider.java:157) ~[?:?]
        at org.openhab.binding.sonoff.internal.handler.SonoffAccountHandler.restoreStates(SonoffAccountHandler.java:296) ~[?:?]
        at org.openhab.binding.sonoff.internal.handler.SonoffAccountHandler.initialize(SonoffAccountHandler.java:100) ~[?:?]
        at jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:?]
        at jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[?:?]
        at jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:?]
        at java.lang.reflect.Method.invoke(Method.java:566) ~[?:?]
        at org.openhab.core.internal.common.AbstractInvocationHandler.invokeDirect(AbstractInvocationHandler.java:154) [bundleFile:?]
        at org.openhab.core.internal.common.Invocation.call(Invocation.java:52) [bundleFile:?]
        at java.util.concurrent.FutureTask.run(FutureTask.java:264) [?:?]
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128) [?:?]
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628) [?:?]
        at java.lang.Thread.run(Thread.java:834) [?:?]
jgesser commented 1 year ago

@JacekKac what version of OH are you using? This release was supposed to work on 3.2 and 3.3. At least it worked here on both versions.

JacekKac commented 1 year ago

Version: 3.3.0 (Build) during discovery :


 Api Cache Request:{"appid":"KOBxGJna5qkk3JLXw3LHLX3wSNiPjAVi","nonce":"sOIwFAx9","ts":1658254436001,"version":8}
2022-07-19 20:13:56.304 [DEBUG] [ernal.connection.SonoffApiConnection] - Api Cache response:{"error":400,"msg":"\"authorization\" with value \"Bearer\" fails to match the required pattern: /^Bearer\\s[0-9a-f]+$/","data":null}
jgesser commented 1 year ago

Hi @JacekKac , it looks like there was an error when handling devices with more than 1 switch. I fixed that issue and updated the compiled jar. The changes for this fix are in my fork and in the same PR to the main repository.

JacekKac commented 1 year ago

@jgesser thank you, it's working now :)

halext commented 1 year ago

Yes, it is working very well. You will include new devices in future bluid's ? like Sonoff NSPanel ?