diff options
Diffstat (limited to 'localwebsite')
-rw-r--r-- | localwebsite/classes/TemphumdClient.php (renamed from localwebsite/classes/Si7021dClient.php) | 14 | ||||
-rw-r--r-- | localwebsite/classes/config.php | 3 | ||||
-rw-r--r-- | localwebsite/config.php | 4 | ||||
-rw-r--r-- | localwebsite/handlers/MiscHandler.php | 4 | ||||
-rw-r--r-- | localwebsite/templates-web/sensors.twig | 8 |
5 files changed, 25 insertions, 8 deletions
diff --git a/localwebsite/classes/Si7021dClient.php b/localwebsite/classes/TemphumdClient.php index b976448..07e5a3e 100644 --- a/localwebsite/classes/Si7021dClient.php +++ b/localwebsite/classes/TemphumdClient.php @@ -1,17 +1,19 @@ <?php -class Si7021dClient extends MySimpleSocketClient { +class TemphumdClient extends MySimpleSocketClient { public string $name; public float $temp; public float $humidity; + public ?int $flags; /** * @throws Exception */ - public function __construct(string $host, int $port, string $name) { + public function __construct(string $host, int $port, string $name, ?int $flags = null) { parent::__construct($host, $port); $this->name = $name; + $this->flags = $flags; socket_set_timeout($this->sock, 3); } @@ -28,4 +30,12 @@ class Si7021dClient extends MySimpleSocketClient { $this->humidity = $hum; } + public function hasTemperature(): bool { + return ($this->flags & config::TEMPHUMD_NO_TEMP) == 0; + } + + public function hasHumidity(): bool { + return ($this->flags & config::TEMPHUMD_NO_HUM) == 0; + } + }
\ No newline at end of file diff --git a/localwebsite/classes/config.php b/localwebsite/classes/config.php index 87ecf1c..927321e 100644 --- a/localwebsite/classes/config.php +++ b/localwebsite/classes/config.php @@ -2,6 +2,9 @@ class config { + const TEMPHUMD_NO_TEMP = 1 << 0; + const TEMPHUMD_NO_HUM = 1 << 1; + public static function get(string $key) { global $config; return is_callable($config[$key]) ? $config[$key]() : $config[$key]; diff --git a/localwebsite/config.php b/localwebsite/config.php index 8ad472c..57ff739 100644 --- a/localwebsite/config.php +++ b/localwebsite/config.php @@ -15,9 +15,9 @@ return [ 'pump_host' => '192.168.1.2', 'pump_port' => 8307, - 'si7021d_servers' => [ + 'temphumd_servers' => [ // fill here, example: - 'hall' => ['192.168.1.3', 8306, 'Big Hall'], + 'hall' => ['192.168.1.3', 8306, 'Big Hall'/*, optional: config::TEMPHUMD_NO_HUM */], ], // modem names (array keys) must match ipset names and diff --git a/localwebsite/handlers/MiscHandler.php b/localwebsite/handlers/MiscHandler.php index 983570f..10817e1 100644 --- a/localwebsite/handlers/MiscHandler.php +++ b/localwebsite/handlers/MiscHandler.php @@ -17,8 +17,8 @@ class MiscHandler extends RequestHandler global $config; $clients = []; - foreach ($config['si7021d_servers'] as $key => $params) { - $cl = new Si7021dClient(...$params); + foreach ($config['temphumd_servers'] as $key => $params) { + $cl = new TemphumdClient(...$params); $clients[$key] = $cl; $cl->readSensor(); diff --git a/localwebsite/templates-web/sensors.twig b/localwebsite/templates-web/sensors.twig index 14f8454..1005dc0 100644 --- a/localwebsite/templates-web/sensors.twig +++ b/localwebsite/templates-web/sensors.twig @@ -6,6 +6,10 @@ {% for key, sensor in sensors %} <h6 class="text-primary{% if not loop.first %} mt-4{% endif %}">{{ sensor.name }}</h6> - <span class="text-secondary">Температура:</span> <b>{{ sensor.temp }}</b> °C<br> - <span class="text-secondary">Влажность:</span> <b>{{ sensor.humidity }}</b>% + {% if sensor.hasTemperature() %} + <span class="text-secondary">Температура:</span> <b>{{ sensor.temp }}</b> °C<br> + {% endif %} + {% if sensor.hasHumidity() %} + <span class="text-secondary">Влажность:</span> <b>{{ sensor.humidity }}</b>% + {% endif %} {% endfor %} |