summaryrefslogtreecommitdiff
path: root/localwebsite
diff options
context:
space:
mode:
authorEvgeny Sorokin <me@ch1p.io>2024-01-17 03:35:59 +0300
committerEvgeny Sorokin <me@ch1p.io>2024-01-17 03:35:59 +0300
commita9a241ad19449c29b68cd4a5b539bcbec816e341 (patch)
tree2ebfc73b206e4cec30fd94613bd6bf42ef5b269d /localwebsite
parent8a89dd77be03ca8eb9cdc378ba8e912292494fa9 (diff)
lws: pump page rewritten to python
Diffstat (limited to 'localwebsite')
-rw-r--r--localwebsite/classes/GPIORelaydClient.php18
-rw-r--r--localwebsite/classes/InverterdClient.php69
-rw-r--r--localwebsite/handlers/MiscHandler.php42
-rw-r--r--localwebsite/htdocs/index.php2
-rw-r--r--localwebsite/templates-web/pump.twig17
5 files changed, 0 insertions, 148 deletions
diff --git a/localwebsite/classes/GPIORelaydClient.php b/localwebsite/classes/GPIORelaydClient.php
deleted file mode 100644
index 89c8dc9..0000000
--- a/localwebsite/classes/GPIORelaydClient.php
+++ /dev/null
@@ -1,18 +0,0 @@
-<?php
-
-class GPIORelaydClient extends MySimpleSocketClient {
-
- const STATUS_ON = 'on';
- const STATUS_OFF = 'off';
-
- public function setStatus(string $status) {
- $this->send($status);
- return $this->recv();
- }
-
- public function getStatus() {
- $this->send('get');
- return $this->recv();
- }
-
-} \ No newline at end of file
diff --git a/localwebsite/classes/InverterdClient.php b/localwebsite/classes/InverterdClient.php
deleted file mode 100644
index b68b784..0000000
--- a/localwebsite/classes/InverterdClient.php
+++ /dev/null
@@ -1,69 +0,0 @@
-<?php
-
-class InverterdClient extends MySimpleSocketClient {
-
- /**
- * @throws Exception
- */
- public function setProtocol(int $v): string
- {
- $this->send("v $v");
- return $this->recv();
- }
-
- /**
- * @throws Exception
- */
- public function setFormat(string $fmt): string
- {
- $this->send("format $fmt");
- return $this->recv();
- }
-
- /**
- * @throws Exception
- */
- public function exec(string $command, array $arguments = []): string
- {
- $buf = "exec $command";
- if (!empty($arguments)) {
- foreach ($arguments as $arg)
- $buf .= " $arg";
- }
- $this->send($buf);
- return $this->recv();
- }
-
- /**
- * @throws Exception
- */
- public function recv()
- {
- $recv_buf = '';
- $buf = '';
-
- while (true) {
- $result = socket_recv($this->sock, $recv_buf, 1024, 0);
- if ($result === false)
- throw new Exception(__METHOD__ . ": socket_recv() failed: " . $this->getSocketError());
-
- // peer disconnected
- if ($result === 0)
- break;
-
- $buf .= $recv_buf;
- if (endsWith($buf, "\r\n\r\n"))
- break;
- }
-
- $response = explode("\r\n", $buf);
- $status = array_shift($response);
- if (!in_array($status, ['ok', 'err']))
- throw new Exception(__METHOD__.': unexpected status ('.$status.')');
- if ($status == 'err')
- throw new Exception(empty($response) ? 'unknown inverterd error' : $response[0]);
-
- return trim(implode("\r\n", $response));
- }
-
-} \ No newline at end of file
diff --git a/localwebsite/handlers/MiscHandler.php b/localwebsite/handlers/MiscHandler.php
index 4c5a25e..efaca22 100644
--- a/localwebsite/handlers/MiscHandler.php
+++ b/localwebsite/handlers/MiscHandler.php
@@ -3,17 +3,6 @@
class MiscHandler extends RequestHandler
{
- public function GET_main() {
- global $config;
- $this->tpl->set_title('Главная');
- $this->tpl->set([
- 'grafana_sensors_url' => $config['grafana_sensors_url'],
- 'grafana_inverter_url' => $config['grafana_inverter_url'],
- 'cameras' => $config['cam_list']['labels']
- ]);
- $this->tpl->render_page('index.twig');
- }
-
public function GET_sensors_page() {
global $config;
@@ -30,29 +19,6 @@ class MiscHandler extends RequestHandler
$this->tpl->render_page('sensors.twig');
}
- public function GET_pump_page() {
- global $config;
-
- if (isset($_GET['alt']) && $_GET['alt'] == 1)
- $config['pump_host'] = '192.168.5.223';
-
- list($set) = $this->input('set');
- $client = new GPIORelaydClient($config['pump_host'], $config['pump_port']);
-
- if ($set == GPIORelaydClient::STATUS_ON || $set == GPIORelaydClient::STATUS_OFF) {
- $client->setStatus($set);
- redirect('/pump/');
- }
-
- $status = $client->getStatus();
-
- $this->tpl->set([
- 'status' => $status
- ]);
- $this->tpl->set_title('Насос');
- $this->tpl->render_page('pump.twig');
- }
-
public function GET_cams() {
global $config;
@@ -160,12 +126,4 @@ class MiscHandler extends RequestHandler
}
}
- public function GET_debug() {
- print_r($_SERVER);
- }
-
- public function GET_phpinfo() {
- phpinfo();
- }
-
}
diff --git a/localwebsite/htdocs/index.php b/localwebsite/htdocs/index.php
index eeeaacb..cd32132 100644
--- a/localwebsite/htdocs/index.php
+++ b/localwebsite/htdocs/index.php
@@ -18,8 +18,6 @@ $router->add('inverter/set-osp/', 'Inverter set_osp');
// misc
$router->add('/', 'Misc main');
$router->add('sensors/', 'Misc sensors_page');
-$router->add('pump/', 'Misc pump_page');
-$router->add('phpinfo/', 'Misc phpinfo');
$router->add('cams/', 'Misc cams');
$router->add('cams/([\d,]+)/', 'Misc cams id=$(1)');
$router->add('cams/stat/', 'Misc cams_stat');
diff --git a/localwebsite/templates-web/pump.twig b/localwebsite/templates-web/pump.twig
deleted file mode 100644
index 3bce0e2..0000000
--- a/localwebsite/templates-web/pump.twig
+++ /dev/null
@@ -1,17 +0,0 @@
-{% include 'bc.twig' with {
- history: [
- {text: "Насос" }
- ]
-} %}
-
-<form action="/pump/" method="get">
- <input type="hidden" name="set" value="{{ status == 'on' ? 'off' : 'on' }}" />
- Сейчас насос
- {% if status == 'on' %}
- <span class="text-success"><b>включен</b></span>.<br><br>
- <button type="submit" class="btn btn-primary">Выключить</button>
- {% else %}
- <span class="text-danger"><b>выключен</b></span>.<br><br>
- <button type="submit" class="btn btn-primary">Включить</button>
- {% endif %}
-</form> \ No newline at end of file