From 3113cbadab7f92e02039134e63045b4cba0d681b Mon Sep 17 00:00:00 2001 From: Jonathan Langlais Date: Sat, 3 Apr 2021 10:35:17 +0200 Subject: [PATCH] Missing file in commit --- src/YeePHP.php | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/YeePHP.php b/src/YeePHP.php index ac5b2c0..cb74725 100644 --- a/src/YeePHP.php +++ b/src/YeePHP.php @@ -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; @@ -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; @@ -464,10 +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 !'); } - var_dump($requestStr, json_encode($res)); - return $result; }