kukkjanos / ewelink

EWeLink Smart Home API Methods
27 stars 12 forks source link

function "toggleDevice" is not working #2

Open pm-pm opened 5 years ago

pm-pm commented 5 years ago

Hello, the functions getDevices() and getDevices($deviceId) work and give back all necessary data. :+1:

But toggleDevice($deviceId) is not working.

Apache logs says: [Thu Apr 11 18:02:55.088519 2019] [:error] [pid 14929] [client 195.111.111.111:51120] PHP Fatal error: Uncaught WebSocket\\ConnectionException: Empty read; connection dead? Stream state: {"crypto":{"protocol":"TLSv1.2","cipher_name":"ECDHE-RSA-AES128-GCM-SHA256","cipher_bits":128,"cipher_version":"TLSv1.2"},"timed_out":false,"blocked":true,"eof":true,"stream_type":"tcp_socket\\/ssl","mode":"r+","unread_bytes":0,"seekable":false} in /var/.../src/vendor/textalk/websocket/lib/Base.php:202\nStack trace:\n#0 /var/.../src/vendor/textalk/websocket/lib/Base.php(92): WebSocket\\Base->read(2)\n#1 /var/.../src/vendor/kukkjanos/ewelink/src/Api/Api.php(154): WebSocket\\Base->receive()\n#2 /var/.../src/vendor/kukkjanos/ewelink/src/Api/EWeApi.php(73): EWeLink\\Api\\Api->sendWSMessage(Array)\n#3 /var/.../src/toaster.php(48): EWeLink\\Api\\EWeApi->toggleDevice('1xxxxaabbc')\n#4 {main}\n thrown in /var/.../src/vendor/textalk/websocket/lib/Base.php on line 202

Could you please check this. I am not able to debug php.

Thanks

kukkjanos commented 5 years ago

I tried my webserver (with apache) and it's working. Maybe Firewall problem?

Niek commented 4 years ago

Same problem here:

PHP Fatal error:  Uncaught WebSocket\ConnectionException: Empty read; connection dead?  Stream state: {"crypto":{"protocol":"TLSv1.2","cipher_name":"ECDHE-RSA-AES128-GCM-SHA256","cipher_bits":128,"cipher_version":"TLSv1.2"},"timed_out":false,"blocked":true,"eof":true,"stream_type":"tcp_socket\/ssl","mode":"r+","unread_bytes":0,"seekable":false} in /var/www/vendor/textalk/websocket/lib/Base.php:202
Stack trace:
#0 /var/www/vendor/textalk/websocket/lib/Base.php(92): WebSocket\Base->read(2)
#1 /var/www/vendor/kukkjanos/ewelink/src/Api/Api.php(154): WebSocket\Base->receive()
#2 /var/www/vendor/kukkjanos/ewelink/src/Api/EWeApi.php(73): EWeLink\Api\Api->sendWSMessage(Array)
#3 /var/www/file.php(43): EWeLink\Api\EWeApi->toggleDevice('myid')
#4 {main}
  thrown in /var/www/vendor/textalk/websocket/lib/Base.php on line 202
Niek commented 4 years ago

I guess related to https://github.com/Textalk/websocket-php/issues/57?

Niek commented 4 years ago

FYI, I found that a workaround is to re-open the API just before the toggleDevice() call, something like this:

$api = new EWeLink\Api\EWeApi($config);
print_r($api->getDevice($deviceId));
$api = new EWeLink\Api\EWeApi($config);
$api->toggleDevice($deviceId);