Skip to content
This repository has been archived by the owner on Jun 20, 2021. It is now read-only.

Commit

Permalink
Merge pull request #2 from Jonathan-Langlais/main
Browse files Browse the repository at this point in the history
Modify socket reading
  • Loading branch information
SharkEzz authored Apr 3, 2021
2 parents 8785ccd + b813892 commit 93e32ff
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
12 changes: 7 additions & 5 deletions src/YeePHP.php
Original file line number Diff line number Diff line change
Expand Up @@ -372,7 +372,7 @@ protected function connect(): bool
$sock = fsockopen($this->lightIP, $this->lightPort, $errCode, $errStr, 30);
if (!$sock) return false;

// stream_set_blocking($sock, false);
stream_set_blocking($sock, false);
$this->socket = $sock;

return true;
Expand Down Expand Up @@ -451,10 +451,11 @@ protected function makeRequest(array $job): ?array
fwrite($this->socket, $requestStr);
fflush($this->socket);

// usleep(100 * 1000); // 0.7s -> wait for the light response
usleep(100 * 1000); // 0.7s -> wait for the light response


$res = fgets($this->socket);
$res = '';
while ($out = stream_get_line($this->socket, 4096, "\r\n"))
$res = $out;


$result = null;
Expand All @@ -464,9 +465,10 @@ protected function makeRequest(array $job): ?array

if (!array_key_exists('error', $res) && array_key_exists('result', $res))
$result = $res['result'];
} else {
throw new Exception('No response received from device !');
}


return $result;
}

Expand Down
2 changes: 1 addition & 1 deletion tests/LightTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class LightTest extends TestCase
*
* @var string
*/
private string $ip = '192.168.0.103';
private string $ip = '192.168.1.21';

private YeePHP $light;

Expand Down

0 comments on commit 93e32ff

Please sign in to comment.