diff options
Diffstat (limited to 'localwebsite/classes/Si7021dClient.php')
-rw-r--r-- | localwebsite/classes/Si7021dClient.php | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/localwebsite/classes/Si7021dClient.php b/localwebsite/classes/Si7021dClient.php new file mode 100644 index 0000000..b976448 --- /dev/null +++ b/localwebsite/classes/Si7021dClient.php @@ -0,0 +1,31 @@ +<?php + +class Si7021dClient extends MySimpleSocketClient { + + public string $name; + public float $temp; + public float $humidity; + + /** + * @throws Exception + */ + public function __construct(string $host, int $port, string $name) { + parent::__construct($host, $port); + $this->name = $name; + + socket_set_timeout($this->sock, 3); + } + + public function readSensor(): void { + $this->send('read'); + + $data = jsonDecode($this->recv()); + + $temp = round((float)$data['temp'], 3); + $hum = round((float)$data['humidity'], 3); + + $this->temp = $temp; + $this->humidity = $hum; + } + +}
\ No newline at end of file |