Open dospaquetes opened 5 years ago
I was thinking maybe adding a slight delay between simultaneous requests would help? Tbh I haven't had my hands in code in a long time so I'm hesitant to get into it myself
Fixed it by adding a 100ms delay after platform.wsc.send(string) in the setPowerState function. Did it super dirty but it works
`if (platform.isSocketOpen) {
setTimeout(function() {
platform.wsc.send(string);
// TODO Here we need to wait for the response to the socket
var waitTill = new Date(new Date().getTime() + 100);
while(waitTill > new Date()){}
callback();
}, 1);
Thanks! I will look into this and implement a fix.
Fixed it by adding a 100ms delay after platform.wsc.send(string) in the setPowerState function. Did it super dirty but it works
`if (platform.isSocketOpen) {
setTimeout(function() { platform.wsc.send(string); // TODO Here we need to wait for the response to the socket var waitTill = new Date(new Date().getTime() + 100); while(waitTill > new Date()){} callback(); }, 1);
Hi, thanks for support. where do I enter this code?
Thanks..
Hi @rcapolino, I'm still working on a proper fix for this. In the meantime you may use dospaquetes's fork https://github.com/dospaquetes/homebridge-ewelink
Hello. I can make the dispaquete’s fork to work. I wonder if you have had the chance to merge it into yours? Count me in if you need people to test it out. Regards.
Hi @daveramirez5, dospaquetes's fork add a small delay to setPowerState, although this may work but this does not 100% address the issue. The proper way to fix this is to implement a request-response mechanism for the websocket messages, and only send the next message after we got response for the previous one. Unfortunately I still don't have time to write code for this yet. If you happen to know programming, please consider contributing to the this project!
Here's my attempt at a fix.
The approach is to not allow new WebSocket send requests to leave until the previous one has responded. Seems to work for me. Contains extra debugging output that should be removed at a later date.
Thoughts ?
https://github.com/howanghk/homebridge-ewelink/compare/master...rob0101:master
[01/07/2019, 4:42:24 pm] [eWeLink] Setting power state to [off] for device [eWeSwitch3] [01/07/2019, 4:42:24 pm] [eWeLink] Setting power state to [off] for device [eWeSwitch1] [01/07/2019, 4:42:24 pm] [eWeLink] Setting power state to [off] for device [eWeSwitch4] [01/07/2019, 4:42:24 pm] [eWeLink] WebSocket messge received: {"error":0,"deviceid":"xxxx","apikey":"yyyyyyy","sequence":"1561965144113"} [01/07/2019, 4:42:24 pm] [eWeLink] ========== sendIfSafe Waited 0.5s so far. [01/07/2019, 4:42:24 pm] [eWeLink] ========== sendIfSafe now CLEAR [01/07/2019, 4:42:24 pm] [eWeLink] **** ========== sendIfSafe Waited 0.5s so far. [01/07/2019, 4:42:25 pm] [eWeLink] WebSocket messge received: {"error":0,"deviceid":"xxxx","apikey":"yyyyyyy","sequence":"1561965144113"} [01/07/2019, 4:42:25 pm] [eWeLink] ========== sendIfSafe Waited 1s so far. [01/07/2019, 4:42:25 pm] [eWeLink] *** ========== sendIfSafe now CLEAR **** [01/07/2019, 4:42:25 pm] [eWeLink] WebSocket messge received: {"error":0,"deviceid":"xxxxxxx","apikey":"yyyyyyy","sequence":"1561965144113"}
I never received any feedback on this fix.
I forgot I had this fix and updated the ewelink-homebridge and immediately lost reliable control over my devices when they are grouped and turned on/off together.
How are other people having any luck without a fix for this in place ?
I merged my code back into the main branch and all works again.
Hi @rob0101 there's a similar fix https://github.com/howanghk/homebridge-ewelink/pull/66 merged and relased in 0.1.18 on Dec 16, 2019. I looked at your fork the last commit was dated Jun 30, 2019. Is the fix in 0.1.18 not helping your situation?
Hi @howanghk, I'm using the latest version of your plugin and got the same problem with automation and multiple devices.
The error exists only for blinds. I was able to correct the error #82.
Hello, I'm having a problem with my basic switches. When asking for multiple (any number above 1) switches to turn on/off more than ~15 seconds after the last successful request/login, only one switch responds and the websocket closes with reason 1006.
No issue arises when only asking for only one basic switch to turn on/off.
As long as my first request is within 15 seconds of websocket login, and I keep making requests within 15 seconds of each other, every command works no matter how many switches are commanded (Well, I have 5 Sonoff Basic Switches so I know it works up to 5). If not, only the first device responds.
Here's the log. You can see two successful requests right after login, but if I wait a little I get a 1006 error
I hope I was as descriptive as possible. I edited out my credentials, obviously