Browse Source

[doc] updated documentation fitting to new procedure

Maxime Alves LIRMM@home 3 years ago
parent
commit
f40b1474dc
1 changed files with 154 additions and 7 deletions
  1. 154
    7
      staging/dev/INSTALL

+ 154
- 7
staging/dev/INSTALL View File

@@ -14,28 +14,110 @@ The downloaded img is resized on the SD card during the installation. We will ne
14 14
 qemu-img resize rpi.img +1G
15 15
 ```
16 16
 
17
-Install dependencies :
17
+### After booting
18
+
19
+Log-in : rpi
20
+Password : raspberry
21
+
22
+Login as root :
23
+
24
+```
25
+sudo su
26
+```
27
+
28
+Create udev rules :
29
+
30
+```
31
+cat << EOF > /etc/udev/rules.d/42-rs485.rules
32
+SUBSYSTEMS=="usb-serial", DRIVERS=="ftdi_sio", SYMLINK+="rs485"
33
+EOF
34
+```
35
+
36
+
37
+#### Dependencies
18 38
 
19 39
 ```
20 40
 apt install git sqlite3 python3-pip python3-click python3-requests python3-netifaces python3-serial
21 41
 ```
22 42
 
43
+#### Deployment 
44
+
23 45
 Deploy pyHeatpump. Replace MONITORING_SERVER with the address of your server :
46
+
24 47
 ```
25 48
 mkdir /var/lib/pyheatpump
26 49
 echo 'pip3 install --upgrade git+https://git.yannweb.net/cli/pyHeatpump.git' > /var/lib/pyheatpump/pyheatpump_upgrade.sh
27 50
 chmod +x /var/lib/pyheatpump/pyheatpump_upgrade.sh
28 51
 /var/lib/pyheatpump/pyheatpump_upgrade.sh
52
+```
29 53
 
30
-cp db/*.sql /var/lib/pyheatpump/
31
-cp db/*.service /var/lib/pyheatpump/
32
-cp db/*.timer /var/lib/pyheatpump/
54
+#### Database initialisation
55
+```
56
+cat << EOF > /var/lib/pyheatpump/pyheatpump.sql
57
+
58
+CREATE TABLE IF NOT EXISTS var_type (
59
+  slabel CHAR(1) UNIQUE PRIMARY KEY,
60
+  label VARCHAR(10) UNIQUE,
61
+  type VARCHAR(10) NOT NULL,
62
+  start_address INT NOT NULL DEFAULT 0,
63
+  end_address INT NOT NULL DEFAULT 250
64
+);
65
+
66
+CREATE TABLE IF NOT EXISTS variable (
67
+  type CHAR(1) NOT NULL,
68
+  address INT NOT NULL,
69
+  unit VARCHAR(5) NULL,
70
+  last_update INT NULL,
71
+
72
+
73
+  FOREIGN KEY (type) REFERENCES var_type(slabel)
74
+    ON DELETE CASCADE,
75
+  PRIMARY KEY(type, address)
76
+);
77
+
78
+CREATE TABLE IF NOT EXISTS var_value (
79
+  type CHAR(1) NOT NULL,
80
+  address INT NOT NULL,
81
+  time INT DEFAULT (strftime('%s', datetime('now'))),
82
+  value INT NOT NULL,
83
+
84
+  FOREIGN KEY (type) REFERENCES variable(type)
85
+    ON DELETE CASCADE,
86
+  FOREIGN KEY (address) REFERENCES variable(address)
87
+    ON DELETE CASCADE,
88
+  PRIMARY KEY(type, address, time)
89
+);
90
+
91
+INSERT INTO var_type (slabel, label, type, start_address, end_address) VALUES (
92
+  'A', 'Analog', 'float', 1, 5000);
93
+INSERT INTO var_type (slabel, label, type, start_address, end_address) VALUES (
94
+  'I', 'Integer', 'int', 5002, 10002);
95
+INSERT INTO var_type (slabel, label, type, start_address, end_address) VALUES (
96
+  'D', 'Digital', 'bool', 1, 2048);
97
+
98
+CREATE TRIGGER variable_last_update AFTER INSERT ON var_value
99
+FOR EACH ROW
100
+BEGIN
101
+  UPDATE variable
102
+  SET last_update = NEW.time
103
+  WHERE
104
+    type = NEW.type
105
+    AND
106
+    address = NEW.address;
107
+END;
108
+
109
+EOF
33 110
 
34 111
 sqlite3 -init /var/lib/pyheatpump/pyheatpump.sql /var/lib/pyheatpump/pyheatpump.sqlite3
35 112
 
113
+```
114
+
115
+#### PyHeatpump configuration file
116
+```
36 117
 cat << EOF > /var/lib/pyheatpump/pyheatpump.ini
37 118
 [heatpump]
38 119
 database = /var/lib/pyheatpump/pyheatpump.sqlite3
120
+serial_port = /dev/rsa485
39 121
 
40 122
 [supervisor]
41 123
 scheme = https
@@ -49,15 +131,80 @@ heatpump_id = 42
49 131
 [api]
50 132
 host = 0.0.0.0
51 133
 port = 80
134
+
135
+EOF
136
+```
137
+
138
+
139
+#### API Service (no-need in production)
140
+```
141
+cat << EOF > /var/lib/pyheatpump/pyheatpump_api.service
142
+[Unit]
143
+Description=API to fetch data from heatpump with HTTP
144
+After=network.target
145
+
146
+[Service]
147
+Type=simple
148
+WorkingDirectory=/var/lib/pyheatpump/
149
+Environment="LOGLEVEL=INFO"
150
+ExecStart=/usr/bin/env pyheatpump run
151
+KillMode=mixed
152
+TimeoutStopSec=30
153
+PrivateTmp=true
154
+
155
+[Install]
156
+WantedBy=multi-user.target
157
+
158
+EOF
159
+```
160
+
161
+
162
+#### Fetch Service
163
+```
164
+cat << EOF > /var/lib/pyheatpump/pyheatpump_fetch.service
165
+[Unit]
166
+Description=pyHeatpump fetch - retrieve the data from the serial port with modbus
167
+Wants=dev-rs485.device
168
+
169
+[Service]
170
+Type=simple
171
+WorkingDirectory=/var/lib/pyheatpump/
172
+Environment="LOGLEVEL=INFO"
173
+ExecStart=/usr/bin/env pyheatpump fetch -t D -t A -t I
174
+ExecStop=/usr/bin/env pyheatpump supervise --since
175
+KillMode=mixed
176
+TimeoutStopSec=30
177
+PrivateTmp=true
178
+
52 179
 EOF
180
+```
53 181
 
182
+
183
+#### Fetch Timer
184
+```
185
+cat << EOF > /var/lib/pyheatpump/pyheatpump_fetch.service
186
+[Unit]
187
+Description=Timer to launch pyheatpump fetch every minute
188
+
189
+[Timer]
190
+OnStartSec=15sec
191
+OnUnitInactiveSec=1m
192
+
193
+[Install]
194
+WantedBy=timers.target
195
+
196
+EOF
197
+```
198
+
199
+#### Installation of the services
200
+```
54 201
 cd /etc/systemd/system
55 202
 ln -s /var/lib/pyheatpump/pyheatpump_api.service
56 203
 ln -s /var/lib/pyheatpump/pyheatpump_fetch.service
57 204
 ln -s /var/lib/pyheatpump/pyheatpump_fetch.timer
58
-ln -s /var/lib/pyheatpump/pyheatpump_supervise.service
59
-ln -s /var/lib/pyheatpump/pyheatpump_supervise.timer
60 205
 
61 206
 systemctl daemon-reload
62 207
 systemctl enable pyheatpump_api.service pyheatpump_fetch.timer pyheatpump_supervise.timer
63
-```
208
+```
209
+
210
+You may now reboot to see if everything works.

Loading…
Cancel
Save