commit | author | age
|
6276d7
|
1 |
<?php |
JK |
2 |
require_once(__DIR__ . '/vendor/autoload.php'); |
|
3 |
require_once('ism7.php'); |
|
4 |
|
|
5 |
$host = 'heater.local'; |
|
6 |
$port = 9091; |
|
7 |
$pass = 'PASSWORD'; |
|
8 |
|
|
9 |
if(is_file('log4php.xml')) { |
|
10 |
$configurator = new LoggerConfiguratorDefault(); |
|
11 |
$config = $configurator->parse('log4php.xml'); |
|
12 |
} elseif(is_file('log4php.properties')) { |
|
13 |
$configurator = new LoggerConfiguratorDefault(); |
|
14 |
$config = $configurator->parse('log4php.properties'); |
|
15 |
} else { |
|
16 |
$config = LoggerConfiguratorDefault::getDefaultConfiguration(); |
|
17 |
} |
|
18 |
Logger::configure($config); |
|
19 |
|
|
20 |
$sql = new PDO('sqlite:ism7_values.db'); |
|
21 |
$sql->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); |
|
22 |
$sql->exec('CREATE TABLE IF NOT EXISTS history ( |
|
23 |
date INT, |
|
24 |
infonumber INT, |
|
25 |
value INT |
|
26 |
);'); |
|
27 |
|
|
28 |
$conn = new ISM7_Connection($host, $port); |
|
29 |
$logonreq = new ISM7_DirectLogonRequest($pass); |
|
30 |
$logonres = $conn->communicate($logonreq); |
|
31 |
var_dump($logonres); |
|
32 |
$confreq = new ISM7_ReadSystemconfigRequest(); |
|
33 |
$confres = $conn->communicate($confreq); |
|
34 |
var_dump($confres); |
|
35 |
|
|
36 |
$infonumbers = array( |
|
37 |
array('A;12', '0x8', '370', 'unknown 1'), |
|
38 |
array('A;13', '0x8', '371', 'unknown 2'), |
|
39 |
array('A;8', '0x8', '13', 'temp.heater', 10, '°C'), # heater temperature |
|
40 |
array('A;9', '0x8', '14', 'temp.water', 10, '°C'), # water temperature |
|
41 |
array('A;10', '0x8', '22', 'temp.return', 10, '°C'), # return temperature |
|
42 |
array('A;11', '0x8', '367', 'unknown 3'), |
|
43 |
array('C;14;551;550', '0x8', '551', 'unknown 4'), |
|
44 |
array('C;14;551;550', '0x8', '550', 'unknown 5'), # heater on times |
|
45 |
array('A;15', '0x8', '554', 'unknown 6'), # time heater on? |
|
46 |
array('A;16', '0x8', '10010', 'pressure', 100, 'bar'), # pressure |
|
47 |
array('A;17', '0x8', '10071', 'unknown 7'), |
|
48 |
array('A;18', '0x8', '328', 'unknown 8'), |
|
49 |
array('A;19', '0x8', '10067', 'unknown 9'), |
|
50 |
array('A;20', '0x8', '10068', 'unknown 10'), |
|
51 |
array('A;21', '0x8', '2', 'unknown 11'), |
|
52 |
array('A;22', '0x8', '3', 'temp.water.target', 10, '°C'), |
|
53 |
array('A;23', '0x35', '10150', 'unknown 12'), |
|
54 |
array('A;24', '0x35', '10145', 'unknown 13'), |
|
55 |
array('A;75', '0x35', '10164', 'temp.int', 10, '°C'), # internal temperature |
|
56 |
array('A;76', '0x35', '10179', 'temp.ext', 10, '°C'), # external temperature (averaged) |
|
57 |
array('A;77', '0x35', '10165', 'unknown 14'), |
|
58 |
array('A;78', '0x35', '10100', 'unknown 15'), |
|
59 |
array('A;79', '0x35', '10155', 'unknown 16'), |
|
60 |
array('A;80', '0x35', '10156', 'unknown 17'), |
|
61 |
array('A;81', '0x35', '10119', 'temp.heater2', 10, '°C'), # t kotła? |
|
62 |
); |
|
63 |
$mapping = array(); |
|
64 |
|
|
65 |
$inforeq = new ISM7_TelegramBundleRequest(30000, 1, TRUE, 'push'); |
|
66 |
foreach($infonumbers as $infonumber) { |
|
67 |
$i = new ISM7_Telegram_InfonumberRead($infonumber[0], hexdec($infonumber[1]), $infonumber[2], 60); |
|
68 |
$inforeq->append($i); |
|
69 |
$mapping[$infonumber[2]] = $infonumber; |
|
70 |
$current[$infonumber[2]] = NULL; |
|
71 |
} |
|
72 |
$infores = $conn->communicate($inforeq); |
|
73 |
var_dump($infores); |
|
74 |
processResponse($infores); |
|
75 |
|
|
76 |
function processResponse($infores) { |
|
77 |
global $infonumbers, $mapping, $current, $sql; |
|
78 |
|
|
79 |
$time = gmmktime(); |
|
80 |
|
|
81 |
foreach($infores as $infonumber) { |
|
82 |
$info = $mapping[$infonumber->infonumber]; |
|
83 |
$value = $infonumber->value; |
|
84 |
|
|
85 |
$current[$infonumber->infonumber] = $value; |
|
86 |
|
|
87 |
if(!isset($info[3])) { |
|
88 |
continue; |
|
89 |
} |
|
90 |
if(isset($info[4])) { |
|
91 |
$value = bcdiv($value, $info[4], 2); |
|
92 |
} |
|
93 |
$unit = ''; |
|
94 |
if(isset($info[5])) { |
|
95 |
$unit = $info[5]; |
|
96 |
} |
|
97 |
|
|
98 |
echo $info[3]."\t".$value.' '.$unit."\n"; |
|
99 |
} |
|
100 |
|
|
101 |
$sql->beginTransaction(); |
|
102 |
$query = $sql->prepare('INSERT INTO history (date, infonumber, value) VALUES (?, ?, ?)'); |
|
103 |
foreach($current as $inumber => $value) { |
|
104 |
$query->execute(array($time, $inumber, $value)); |
|
105 |
} |
|
106 |
$sql->commit(); |
|
107 |
} |
|
108 |
|
|
109 |
while(TRUE) { |
|
110 |
$infores = $conn->wait(); |
|
111 |
processResponse($infores); |
|
112 |
} |
|
113 |
|
|
114 |
$conn->close(); |
|
115 |
|