SETUP.md 15.2 KB
Newer Older
Thomas Eimers's avatar
Thomas Eimers committed
1
2
# Software installieren

3
## Setup Raspberry Basis Betriebssystem
Thomas Eimers's avatar
Thomas Eimers committed
4

Thomas Eimers's avatar
Thomas Eimers committed
5
Die Steuerung basiert auf [Raspian Stretch Lite](https://www.raspberrypi.org/downloads/raspbian/), dieses wird als Image zur Verfügung gestellt.
Thomas Eimers's avatar
Thomas Eimers committed
6

7
### Linux "Raspian" installieren
Thomas Eimers's avatar
Thomas Eimers committed
8

Thomas Eimers's avatar
Thomas Eimers committed
9
```bash
Thomas Eimers's avatar
Thomas Eimers committed
10
cat /proc/partitions # Hier den devicenamen für den USB Stick ablesen
Thomas Eimers's avatar
Thomas Eimers committed
11
wget "https://downloads.raspberrypi.org/raspbian_lite_latest"
12
sudo -i
Thomas Eimers's avatar
Thomas Eimers committed
13
# Bei mir aktuell 2018-11-13-raspbian-stretch-lite.img 
14
# Das Verzeichnis /dev/mmcblk0 durch eueren devicenamen ersetzten
Thomas Eimers's avatar
Thomas Eimers committed
15
unzip -p raspbian_lite_latest | dd bs=1M of=/dev/mmcblk0
Thomas Eimers's avatar
Thomas Eimers committed
16
17
```

Thomas Eimers's avatar
Thomas Eimers committed
18
19
Nach dem abschluß des Befehls (dauert einige Minuten) die Speicherkarte einmal entfernen
und wieder in den PC stecken (noch nicht in den Raspberry!).
20
21
22
23

### SSH aktivieren und hostnamen vor dem ersten Bootvorgang anpassen

#### SSH
Thomas Eimers's avatar
Thomas Eimers committed
24

Thomas Eimers's avatar
Thomas Eimers committed
25
Quelle: https://www.raspberrypi.org/documentation/remote-access/ssh/
Thomas Eimers's avatar
Thomas Eimers committed
26
27
28

"For headless setup, SSH can be enabled by placing a file named ssh, without any extension, onto the boot partition of the SD card from another computer. When the Pi boots, it looks for the ssh file. If it is found, SSH is enabled and the file is deleted. The content of the file does not matter; it could contain text, or nothing at all."

Thomas Eimers's avatar
Thomas Eimers committed
29
Damit Raspbian SSH aktiviert nimmt man die SD Karte, nachdem man das Image auf die SD- Karte geschrieben hat, aus dem Rechner, steckt diese wieder ein 
30
31
32
33
34
35
36
37
38
39
und erstellt in der /boot-Partition des Raspbian-Systems eine leere Datei mit dem Namen ssh. 

```bash
cd /media/t-eimers/boot
sudo touch ssh
```

#### Hostname

Den Hostnamen auf `heating` ändern
Thomas Eimers's avatar
Thomas Eimers committed
40

Thomas Eimers's avatar
Thomas Eimers committed
41
```bash
42
43
cd /media/t-eimers/rootfs/etc
sudo mcedit hostname 
Thomas Eimers's avatar
Thomas Eimers committed
44
45
46
```


47
#### Raspberry mit neuer SD Karte bestücken und sich via SSH verbinden
Thomas Eimers's avatar
Thomas Eimers committed
48

49
Nun könnt ihr euch nach dem start des Raspberry via SSH verbinden. (Benutzer pi, Passwort raspberry).
Thomas Eimers's avatar
Thomas Eimers committed
50

Thomas Eimers's avatar
Thomas Eimers committed
51
```bash
52
ssh pi@heating
Thomas Eimers's avatar
Thomas Eimers committed
53
54
```

55
56
57
58
59
60
61
### Wifi/Wlan einrichten

Ich betreibe mein Raspberry dirket am Lan und muss daher nichts einrichten da dieser sich via DHCP konfiguriert.
Falls ihr WLAN benutz könnt ihr diese wie folgt einrichten:

```bash
sudo nano /etc/wpa_supplicant/wpa_supplicant.conf
Thomas Eimers's avatar
Thomas Eimers committed
62
```
63
64

```text
Thomas Eimers's avatar
Thomas Eimers committed
65
66
67
68
69
70
network={
    ssid="hotspot"
    psk="..."
}
```

71
## Basis Softwarepakte installieren
Thomas Eimers's avatar
Thomas Eimers committed
72

Thomas Eimers's avatar
Thomas Eimers committed
73
Leider hat Stretch keine direkte Unterstüzung für PHP 7.1, daher wird ein extra Repro für 7.3 eingebunden.
Thomas Eimers's avatar
Thomas Eimers committed
74
75
76

### Stretch Pakete
```bash
Thomas Eimers's avatar
Thomas Eimers committed
77
sudo -i
Thomas Eimers's avatar
Thomas Eimers committed
78
79
apt-get update && apt-get dist-upgrade -y

Thomas Eimers's avatar
Thomas Eimers committed
80
81
82
83
84
apt-get purge php7.2* -y
apt-get purge php7.1* -y
apt-get purge php7.0* -y

# raspi
Thomas Eimers's avatar
Thomas Eimers committed
85
86
87
88
apt install ca-certificates apt-transport-https 
wget -q https://packages.sury.org/php/apt.gpg -O- | apt-key add -
echo "deb https://packages.sury.org/php/ stretch main" | tee /etc/apt/sources.list.d/php.list
apt-get update && apt-get dist-upgrade -y
Thomas Eimers's avatar
Thomas Eimers committed
89

Thomas Eimers's avatar
Thomas Eimers committed
90
apt-get install -y php7.3-cli php7.3-xml php7.3-mbstring php-xdebug php7.3-mysql mysql-server mysql-client php-mysql \
Thomas Eimers's avatar
Thomas Eimers committed
91
    mc atop htop secure-delete php-apcu libapache2-mod-php7.3 git php7.3-mbstring php7.3-xml mariadb-server mariadb-client \
Thomas Eimers's avatar
Thomas Eimers committed
92
    php7.3-mysql rrdtool php-curl php7.3-zip php7.3-memcached memcached
Thomas Eimers's avatar
Thomas Eimers committed
93
apt autoremove -y
Thomas Eimers's avatar
Thomas Eimers committed
94
apt-get clean
Thomas Eimers's avatar
Thomas Eimers committed
95
rpi-update
Thomas Eimers's avatar
Thomas Eimers committed
96
97
```

Thomas Eimers's avatar
Thomas Eimers committed
98
### Quellcode auschecken (installieren)
Thomas Eimers's avatar
Thomas Eimers committed
99

Thomas Eimers's avatar
Thomas Eimers committed
100
```bash
Thomas Eimers's avatar
Thomas Eimers committed
101
102
cd /home/pi
git clone https://gitlab.com/notdefine/heating-control.git
Thomas Eimers's avatar
Thomas Eimers committed
103
104
105
106
# works only if you have properly set up your environment with the necessary SSH keys and whatnot, but in return you will 
# get a repository that permits you to commit/push the changes back to the remote repo.
# git clone git@gitlab.com:notdefine/heating-control.git
```
Thomas Eimers's avatar
Thomas Eimers committed
107

Thomas Eimers's avatar
Thomas Eimers committed
108
### RRD Digramm initalisieren
Thomas Eimers's avatar
Thomas Eimers committed
109

110
111
112
113
```bash
~/heating-control/bin/init-rrd.sh
```
 aufrufen
Thomas Eimers's avatar
Thomas Eimers committed
114

Thomas Eimers's avatar
Thomas Eimers committed
115
116
117
### Setup Node/npm

```bash
Thomas Eimers's avatar
Thomas Eimers committed
118
wget -qO- https://raw.githubusercontent.com/creationix/nvm/v0.34.0/install.sh | bash
Thomas Eimers's avatar
Thomas Eimers committed
119
120
```

121
relogin to the system!
Thomas Eimers's avatar
Thomas Eimers committed
122
123

```bash
Thomas Eimers's avatar
Thomas Eimers committed
124
nvm install node #v12.0.0
Thomas Eimers's avatar
Thomas Eimers committed
125
126
```

Thomas Eimers's avatar
Thomas Eimers committed
127
128
129
130
### Apache einrichten

Einmal den Apache konfigurieren und neustarten und den Raspi aktualisieren.

131
#### /etc/apache2/sites-enabled/000-default.conf anpassen
Thomas Eimers's avatar
Thomas Eimers committed
132

133
134
```bash
sudo mcedit /etc/apache2/sites-enabled/000-default.conf
Thomas Eimers's avatar
Thomas Eimers committed
135
```
136

Thomas Eimers's avatar
Thomas Eimers committed
137
```text
138
<VirtualHost *:88>
Thomas Eimers's avatar
Thomas Eimers committed
139
140
	# PHP Backend

Thomas Eimers's avatar
Thomas Eimers committed
141
142
143
	#ServerName www.example.com

	ServerAdmin webmaster@localhost
144
	DocumentRoot /home/pi/heating-control/backend/public
Thomas Eimers's avatar
Thomas Eimers committed
145
146
147

	ErrorLog ${APACHE_LOG_DIR}/error.log
	CustomLog ${APACHE_LOG_DIR}/access.log combined
148

Thomas Eimers's avatar
Thomas Eimers committed
149
150
</VirtualHost>

151
<VirtualHost *:80>
Thomas Eimers's avatar
Thomas Eimers committed
152
153
	# Compiled Frontend

154
155
156
157
158
159
160
161
162
163
164
165
	#ServerName www.example.com

	ServerAdmin webmaster@localhost
	DocumentRoot /home/pi/heating-control/frontend/dist

	ErrorLog ${APACHE_LOG_DIR}/error.log
	CustomLog ${APACHE_LOG_DIR}/access.log combined

</VirtualHost>
```

#### /etc/apache2/ports.conf anpassen
Thomas Eimers's avatar
Thomas Eimers committed
166

167
168
```bash
sudo mcedit /etc/apache2/ports.conf
169
```
170

Thomas Eimers's avatar
Thomas Eimers committed
171
```text
172
173
174
175
176
# If you just change the port or add more ports here, you will likely also
# have to change the VirtualHost statement in
# /etc/apache2/sites-enabled/000-default.conf

Listen 80
177
Listen 88
178
179
180
181
182
183
184
185
186

<IfModule ssl_module>
	Listen 443
</IfModule>

<IfModule mod_gnutls.c>
	Listen 443
</IfModule>

Thomas Eimers's avatar
Thomas Eimers committed
187
188
# vim: syntax=apache ts=4 sw=4 sts=4 sr noet
```
Thomas Eimers's avatar
Thomas Eimers committed
189

190
#### .htaccess overwrite aktivieren
Thomas Eimers's avatar
Thomas Eimers committed
191

Thomas Eimers's avatar
Thomas Eimers committed
192
Hiermit stellen wir ein, dass .htaccess Dateien in Unterordnern auch Optionen setzen können. Folgenden Teil hinzufügen
193

194
195
```bash
sudo mcedit /etc/apache2/apache2.conf
Thomas Eimers's avatar
Thomas Eimers committed
196
```
197
198
199

An das Ende anfügen:

Thomas Eimers's avatar
Thomas Eimers committed
200
```text
Thomas Eimers's avatar
Thomas Eimers committed
201
202
203
204
205
206
207
<Directory /home/pi/>
    Options Indexes FollowSymLinks
    AllowOverride All
    Require all granted
</Directory>
```

208
209
210
#### PHP Fehlerausgaben aktivieren

```bash
Thomas Eimers's avatar
Thomas Eimers committed
211
sudo mcedit /etc/php/7.3/apache2/php.ini
212
213
214
215
216
```

Und den Wert display_errors anpassen auf: `display_errors = On`


Thomas Eimers's avatar
Thomas Eimers committed
217
218
219
220
221
#### Apache Restart
```bash
sudo a2enmod expires
sudo a2enmod headers
sudo a2enmod rewrite
Thomas Eimers's avatar
Thomas Eimers committed
222
sudo systemctl restart apache2
Thomas Eimers's avatar
Thomas Eimers committed
223
sudo service apache2 restart
Thomas Eimers's avatar
Thomas Eimers committed
224
```
Thomas Eimers's avatar
Thomas Eimers committed
225

Thomas Eimers's avatar
Thomas Eimers committed
226
227
Jetzt sollte unter http://heating.fritz.box:88/ eine leere Seite erscheienen
und im error_log:
228
229

```text
Thomas Eimers's avatar
Thomas Eimers committed
230
cat /var/log/apache2/error.log 
231
232
233
234
235
236
237
Warning: require(/home/pi/heating-control/backend/public/../vendor/autoload.php):
```

Wenn diese Ausgabe nicht kommt sollte man nicht weitermachen sondern nochmal das Setup des Apache Webservers
prüfen.


Thomas Eimers's avatar
Thomas Eimers committed
238
### Composer lokal installieren
Thomas Eimers's avatar
Thomas Eimers committed
239

Thomas Eimers's avatar
Thomas Eimers committed
240
241
Nicht als Root ausführen!

Thomas Eimers's avatar
Thomas Eimers committed
242
```bash
243
cd ~
Thomas Eimers's avatar
Thomas Eimers committed
244
245
246
247
248
249
250
251
252
# Get composer from https://getcomposer.org
php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
php composer-setup.php
php -r "unlink('composer-setup.php');"

# Install composer global and remove local installation
php composer.phar global require composer/composer
export PATH=~/.config/composer/vendor/bin:$PATH
rm composer.phar
Thomas Eimers's avatar
Thomas Eimers committed
253

Thomas Eimers's avatar
Thomas Eimers committed
254
echo "export PATH=~/.config/composer/vendor/bin:$PATH" >> ~/.bashrc
Thomas Eimers's avatar
Thomas Eimers committed
255
```
Thomas Eimers's avatar
Thomas Eimers committed
256

257
Nach Aufruf von `composer --version` sollte etwas ähnliches wie `Composer 1.8.0 2018-12-03 10:31:16` erscheinen. 
Thomas Eimers's avatar
Thomas Eimers committed
258

Thomas Eimers's avatar
Thomas Eimers committed
259
### Mysql einrichten
Thomas Eimers's avatar
Thomas Eimers committed
260

Thomas Eimers's avatar
Thomas Eimers committed
261
```bash
Thomas Eimers's avatar
Thomas Eimers committed
262
263
264
sudo mysql_secure_installation
```

265
266
267
268
269
270
271
- Das Root passwort ist leer
- Set root password? [Y/n] y
- Neues Passwort raspberrypi
- Remove anonymous users? [Y/n] y
- Remove test database and access to it? [Y/n] y
- Reload privilege tables now? [Y/n]  y

Thomas Eimers's avatar
Thomas Eimers committed
272
Das root Passwort sollte man sich merken (z.B. raspberrypi) ;)
Thomas Eimers's avatar
Thomas Eimers committed
273

Thomas Eimers's avatar
Thomas Eimers committed
274
```bash
Thomas Eimers's avatar
Thomas Eimers committed
275
sudo mysql -u root -p
276
277
278
```

```mariadb
Thomas Eimers's avatar
Thomas Eimers committed
279
280
281
create database heating;
CREATE USER 'heating'@'localhost' IDENTIFIED BY 'testing';
GRANT ALL PRIVILEGES ON heating.* TO 'heating'@'localhost';
Thomas Eimers's avatar
Thomas Eimers committed
282
283
284
285
286
287
288
289
290
291
quit
```
### Datbenbank für zugriff von außen freigeben

 if external access is needed. Then also set bind-adress to 0.0.0.0 in /etc/mysql/mariadb.conf.d/50-server.cnf

```bash
sudo mysql -u root -p
```

Thomas Eimers's avatar
Thomas Eimers committed
292
```mariadb
Thomas Eimers's avatar
Thomas Eimers committed
293
294
CREATE USER 'heating'@'%' IDENTIFIED BY 'testing';
GRANT ALL PRIVILEGES ON heating.* TO 'heating'@'%';
Thomas Eimers's avatar
Thomas Eimers committed
295
quit
Thomas Eimers's avatar
Thomas Eimers committed
296
297
```

Thomas Eimers's avatar
Thomas Eimers committed
298
[IDE Url](jdbc:mariadb://heating.fritz.box:3306/heating)
Thomas Eimers's avatar
Thomas Eimers committed
299

Thomas Eimers's avatar
Thomas Eimers committed
300
301
### mqtt Anbindung an OpenHab2 mittels mosquitto (nicht optional, auch wenn openhab nicht verwendet wird)

Thomas Eimers's avatar
Thomas Eimers committed
302
303
Leider kann das Paket nicht via PEAR installiert werden (mit PHP7.1 ging es noch), daher installation
aus den Quellen:
Thomas Eimers's avatar
Thomas Eimers committed
304

Thomas Eimers's avatar
Thomas Eimers committed
305
```bash
Thomas Eimers's avatar
Thomas Eimers committed
306
sudo apt-get install -y php7.3-dev php-pear libmosquitto1 libmosquitto-dev mosquitto
Thomas Eimers's avatar
Thomas Eimers committed
307
308
309
#mosquitto-clients for debugging
sudo pecl channel-update pecl.php.net
sudo pecl install Mosquitto-alpha
Thomas Eimers's avatar
Thomas Eimers committed
310
```
311
# Then add `extension=mosquitto.so` to both php.ini. (after [PHP])
Thomas Eimers's avatar
Thomas Eimers committed
312

Thomas Eimers's avatar
Thomas Eimers committed
313
```bash
Thomas Eimers's avatar
Thomas Eimers committed
314
315
sudo mcedit /etc/php/7.3/cli/php.ini 
sudo mcedit /etc/php/7.3/apache2/php.ini 
Thomas Eimers's avatar
Thomas Eimers committed
316

317
318
319
320
sudo systemctl enable mosquitto
sudo systemctl start mosquitto
sudo systemctl status mosquitto  
```
Thomas Eimers's avatar
Thomas Eimers committed
321

322
### Heizungssteuerung einrichten
Thomas Eimers's avatar
Thomas Eimers committed
323

Thomas Eimers's avatar
Thomas Eimers committed
324
325
326
327
328
329
330
331
- Benötigte PHP Pakte installieren
- Datenbankstruktur einrichten
- Frontend bauen

```bash
cd ~/heating-control/backend/
composer up
composer doctrine-init
332

Thomas Eimers's avatar
Thomas Eimers committed
333
cd ~/heating-control/frontend/
Thomas Eimers's avatar
Thomas Eimers committed
334
335
336
337
338
339
340

npm install -g -p @angular/cli # 7.3.8
    
#npm install node-gyp@latest
#npm install node-sass
#npm install typescript@">=3.1.1 <3.3"

Thomas Eimers's avatar
Thomas Eimers committed
341
npm install
Thomas Eimers's avatar
Thomas Eimers committed
342
343
344
345
346

# danach liegt in ~/heating-control/frontend/dist das kompilierte Frontend
# ng build --prod  (klappt aufgrund von speicherporblemen nicht, daher ersatzbefehl)

node --max_old_space_size=512 node_modules/@angular/cli/bin/ng build --prod
Thomas Eimers's avatar
Thomas Eimers committed
347
348
```

Thomas Eimers's avatar
Thomas Eimers committed
349
Unter http://heating.fritz.box erscheint nun die Oberfläche der Steuerung (statische Ansicht mit Beispieldaten/-diagrammen)
Thomas Eimers's avatar
Thomas Eimers committed
350
351
352

### System aufrufen

Thomas Eimers's avatar
Thomas Eimers committed
353
http://heating.fritz.box?api=http://heating.fritz.box:88
Thomas Eimers's avatar
Thomas Eimers committed
354

Thomas Eimers's avatar
Thomas Eimers committed
355
356
## Sensoren einrichten

Thomas Eimers's avatar
Thomas Eimers committed
357
### 1-Wire Bus Kernelmodule automatisch laden
Thomas Eimers's avatar
Thomas Eimers committed
358
359
360
361
362
363
364
365

Dazu in der Datei `/etc/rc.local` folgende zwei Zeilen vor dem "exit 0" hinzufügen:

```bash
modprobe w1-gpio
modprobe w1-therm
``` 

Thomas Eimers's avatar
Thomas Eimers committed
366
### GPIO-Pullup aktivieren 
Thomas Eimers's avatar
Thomas Eimers committed
367

368
Folgendes am Ende der Datei `/boot/config.txt` hinzufügen.
Thomas Eimers's avatar
Thomas Eimers committed
369
```text
Thomas Eimers's avatar
Thomas Eimers committed
370
371
dtoverlay=w1-gpio-pullup
```
Thomas Eimers's avatar
Thomas Eimers committed
372

373
374
375
376
377
378
379
380
381
Und den Ton abschalten
```text
dtparam=audio=off
```
Einmal neu starten.

Jetzt sollte  `cat /sys/bus/w1/devices/w1_bus_master1/28-*/w1_slave | grep t=`

etwas ähnliches wie `13 02 4b 46 7f ff 0d 10 e7 t=33187` ausgeben.
Thomas Eimers's avatar
Thomas Eimers committed
382

383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
```bash

cd heating-control/
php backend/src/cli.php show-sensors
```

sollte die Sensoren anzeigen die die Heizung erkannt hat

```text
array:6 [
  "10-00080282b5f8" => HeatingControl\Entity\SensorValueEntity {#102
    #identification: "10-00080282b5f8"
    #value: 7.06
    #name: "Sensor 10"
    #id: 10
    #configured: false
  }
  ...
```
Thomas Eimers's avatar
Thomas Eimers committed
402
403
404
405
406
407
408
409
410
411
412
## Relaikarte vorbereiten

Dazu in der Datei `/etc/rc.local` folgende Code vor dem "exit 0" hinzufügen:

```bash
echo 26 > /sys/class/gpio/export
echo 20 > /sys/class/gpio/export
echo 21 > /sys/class/gpio/export
echo out > /sys/class/gpio/gpio26/direction
echo out > /sys/class/gpio/gpio20/direction
echo out > /sys/class/gpio/gpio21/direction
Thomas Eimers's avatar
Thomas Eimers committed
413

414
# Nach dem booten erstmal alles einschalten (so wie die relais auch eingestellt sind, wenn die spannung weg ist)
Thomas Eimers's avatar
Thomas Eimers committed
415
416
417
418
419
420
421
422
echo 1 > /sys/class/gpio/gpio26/value
echo 1 > /sys/class/gpio/gpio20/value
echo 1 > /sys/class/gpio/gpio21/value
```

```bash
sudo adduser www-data gpio
sudo systemctl restart apache2
Thomas Eimers's avatar
Thomas Eimers committed
423
424
```

425
426
Einmal neu starten.

Thomas Eimers's avatar
Thomas Eimers committed
427
## Setup Cron
Thomas Eimers's avatar
Thomas Eimers committed
428
429
430
431

Um die Cronjobs der Steuerung einzurichten, müssen folgende beiden Zeilen an die `/etc/crontab` angehangen werden.
Wichtig ist, dass die Datei mit einer leeren Zeile endet. Nach der Anpassung muss der Cron einmal neu gestartet werden
via `sudo /etc/init.d/cron restart`
Thomas Eimers's avatar
Thomas Eimers committed
432

Thomas Eimers's avatar
Thomas Eimers committed
433
```text
Thomas Eimers's avatar
Thomas Eimers committed
434
* * * * * pi cd /home/pi/heating-control/backend && php src/cli.php log-sensors
Thomas Eimers's avatar
Thomas Eimers committed
435
* * * * * pi cd /home/pi/heating-control/backend && php src/cli.php burner-control
Thomas Eimers's avatar
Thomas Eimers committed
436
*/5 * * * * pi cd /home/pi/heating-control/backend && php src/cli.php graph
Thomas Eimers's avatar
Thomas Eimers committed
437
0 1 * * * root rm /var/log/openhab2/*.log
Thomas Eimers's avatar
Thomas Eimers committed
438
```
439

Thomas Eimers's avatar
Thomas Eimers committed
440
## Zeitzone setzen
Thomas Eimers's avatar
Thomas Eimers committed
441

Thomas Eimers's avatar
Thomas Eimers committed
442
```bash
Thomas Eimers's avatar
Thomas Eimers committed
443
sudo dpkg-reconfigure tzdata
Thomas Eimers's avatar
Thomas Eimers committed
444
sudo dpkg-reconfigure locales
Thomas Eimers's avatar
Thomas Eimers committed
445
446
```

Thomas Eimers's avatar
Thomas Eimers committed
447
Wähle Europe/Berlin und [*] de_DE.UTF-8 UTF-8
Thomas Eimers's avatar
Thomas Eimers committed
448

Thomas Eimers's avatar
Thomas Eimers committed
449

Thomas Eimers's avatar
Thomas Eimers committed
450
## Watchdog installieren
Thomas Eimers's avatar
Thomas Eimers committed
451

Thomas Eimers's avatar
Thomas Eimers committed
452
Restart Raspberry if it hangs.
Thomas Eimers's avatar
Thomas Eimers committed
453

Thomas Eimers's avatar
Thomas Eimers committed
454
http://blog.ricardoarturocabral.com/2013/01/auto-reboot-hung-raspberry-pi-using-on.html
Thomas Eimers's avatar
Thomas Eimers committed
455
456

```bash
Thomas Eimers's avatar
Thomas Eimers committed
457
sudo apt-get install watchdog
Thomas Eimers's avatar
Thomas Eimers committed
458
459
460
461
echo "bcm2835_wdt" | sudo tee -a /etc/modules
sudo nano /etc/watchdog.conf
sudo systemctl enable watchdog.service
sudo systemctl start watchdog.service
Thomas Eimers's avatar
Thomas Eimers committed
462
```
Thomas Eimers's avatar
Thomas Eimers committed
463

464
`sudo mcedit /etc/watchdog.conf`
465

Thomas Eimers's avatar
Thomas Eimers committed
466
```text
Thomas Eimers's avatar
Thomas Eimers committed
467
468
469
470
471
472
watchdog-device = /dev/watchdog
min-memory=1
watchdog-timeout	= 15
retry-timeout           = 60
repair-maximum          = 1
```
473

474
## Reduce writes on SD-Card (optional, erhöht die SD Lebenszeit)
475

Thomas Eimers's avatar
Thomas Eimers committed
476
Using iotop -bktoqqq I figured out most frequent write access. It turns out that also /var/cache/samba/ is frequently written to. So this also has to go to RAM in addition to /var/tmp/ where the new log files will be.
477

Thomas Eimers's avatar
Thomas Eimers committed
478
SD Karten sind nicht für dauernde Schreibzyklen ausgelegt, daher die Schreibvorgänge minimieren.
Thomas Eimers's avatar
Thomas Eimers committed
479

Thomas Eimers's avatar
Thomas Eimers committed
480
`sudo mcedit /etc/systemd/journald.conf`
Thomas Eimers's avatar
Thomas Eimers committed
481

Thomas Eimers's avatar
Thomas Eimers committed
482
```text
Thomas Eimers's avatar
Thomas Eimers committed
483
484
[Journal]
Storage=volatile
485
```
Thomas Eimers's avatar
Thomas Eimers committed
486

Thomas Eimers's avatar
Thomas Eimers committed
487
488
Disable Swap writes
`sudo apt-get purge dphys-swapfile`
489

Thomas Eimers's avatar
Thomas Eimers committed
490
491
Put an entry in /etc/fstab
```
Thomas Eimers's avatar
Thomas Eimers committed
492
493
494
tmpfs /tmp tmpfs defaults,noatime,nosuid,nodev,noexec,mode=0755,size=50M 0 0
tmpfs /var/tmp tmpfs defaults,noatime,nosuid,nodev,noexec,mode=0755,size=10M 0 0
tmpfs /var/log tmpfs defaults,noatime,nosuid,nodev,noexec,mode=0755,size=50M 0 0
Thomas Eimers's avatar
Thomas Eimers committed
495
```
Thomas Eimers's avatar
Thomas Eimers committed
496

Thomas Eimers's avatar
Thomas Eimers committed
497
Add to `/etc/rc.local`
Thomas Eimers's avatar
Thomas Eimers committed
498
499

```bash
Thomas Eimers's avatar
Thomas Eimers committed
500
501
mkdir -p /var/log/apache2
mkdir -p /var/log/openhab2/tmp
Thomas Eimers's avatar
Thomas Eimers committed
502
mkdir -p /var/log/mosquitto
Thomas Eimers's avatar
Thomas Eimers committed
503
504

touch /var/log/mosquitto/mosquitto.log
Thomas Eimers's avatar
Thomas Eimers committed
505
chmod -R 777 /var/log/mosquitto
Thomas Eimers's avatar
Thomas Eimers committed
506
507
```

Thomas Eimers's avatar
Thomas Eimers committed
508
## Switch to external HD (optional but recommendend)
Thomas Eimers's avatar
Thomas Eimers committed
509
510
511
512
513
514
515
516

With a USB to SATA Adapter it is possible to boot the Rapsberry from a hard disk like a SSD.
For this you need to boot once from a SD Card and toogle the Raspberry to boot from USB.

https://www.giga.de/zubehoer/raspberry-pi/tipps/raspberry-pi-3-booten-von-usb-stick/

And then you could copy your SD card to an usb-drive/usb-stick.

Thomas Eimers's avatar
Thomas Eimers committed
517
518
519
520
## Disable bluetooth
https://scribles.net/disabling-bluetooth-on-raspberry-pi/

sudo nano /boot/config.txt
Thomas Eimers's avatar
Thomas Eimers committed
521

Thomas Eimers's avatar
Thomas Eimers committed
522
523
Add below, save and close the file.
`dtoverlay=pi3-disable-bt`
Thomas Eimers's avatar
Thomas Eimers committed
524
525

```bash
Thomas Eimers's avatar
Thomas Eimers committed
526
527
528
529
530
531
532
sudo systemctl disable hciuart.service
sudo systemctl disable bluealsa.service
sudo systemctl disable bluetooth.service

sudo apt-get purge bluez -y
sudo apt-get autoremove -y
sudo systemctl mask serial-getty@ttyAMA0.service
Thomas Eimers's avatar
Thomas Eimers committed
533
534
```

Thomas Eimers's avatar
Thomas Eimers committed
535
536
537
## zsh installieren (optional)

Ich bevorzuge die bash kompatible zsh Bash
538
539

```bash
Thomas Eimers's avatar
Thomas Eimers committed
540
sudo apt-get install zsh -y
Thomas Eimers's avatar
Thomas Eimers committed
541
542
sh -c "$(curl -fsSL https://raw.github.com/robbyrussell/oh-my-zsh/master/tools/install.sh)"
```
Thomas Eimers's avatar
Thomas Eimers committed
543

Thomas Eimers's avatar
Thomas Eimers committed
544
545
546
547
548
549
550
551
552
553
554
555
556
und .zshrc befüllen mit
```bash
export ZSH="/home/pi/.oh-my-zsh"
ZSH_THEME="agnoster"
plugins=(
  git
  sudo
  z
)
source $ZSH/oh-my-zsh.sh
export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"
[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion"
Thomas Eimers's avatar
Thomas Eimers committed
557
558

export PATH=~/.config/composer/vendor/bin:/home/pi/.nvm/versions/node/v12.0.0/bin:/usr/local/bin:/usr/bin:/bin:/usr/games
559
560
```

Thomas Eimers's avatar
Thomas Eimers committed
561
562
563
564
Shell auf zsh umstellen
```bash
chsh -s /bin/zsh
```
565

Thomas Eimers's avatar
Thomas Eimers committed
566
## openhab2 installieren (optional)
567

Thomas Eimers's avatar
Thomas Eimers committed
568
[OpenHab Setup Doku](./docs/openhab2-settings/SETUP.md)
569

Thomas Eimers's avatar
Thomas Eimers committed
570
571
572
## reverse tunnel setup (optional)

[Setup autossh](docs/autossh.md)
573

Thomas Eimers's avatar
Thomas Eimers committed
574
575
576
577
578
579
580
581
## Oberfläche Aufrufen

### Frontend 

[Fronted NG App](http://heating.fritz.box)

### Backend

582
[Backend PHP App](http://heating.fritz.box:88)
Thomas Eimers's avatar
Thomas Eimers committed
583
584
585

### Frontend & Backend

586
[Gemeinsam ergeben diese die Heizungssteuerung](http://heating.fritz.box/?api=http:%2F%2Fheating.fritz.box:88)
Thomas Eimers's avatar
Thomas Eimers committed
587
588


Thomas Eimers's avatar
Thomas Eimers committed
589
# motes ( to be removed)
Thomas Eimers's avatar
Thomas Eimers committed
590

Thomas Eimers's avatar
Thomas Eimers committed
591
592
593
## boot/config.txt

```ini
Thomas Eimers's avatar
Thomas Eimers committed
594
cdtparam=audio=off
Thomas Eimers's avatar
Thomas Eimers committed
595
dtoverlay=pi3-disable-bt
Thomas Eimers's avatar
Thomas Eimers committed
596
597
598
599
600

# Add Power to the 1-wire bus
dtoverlay=w1-gpio-pullup
```

Thomas Eimers's avatar
Thomas Eimers committed
601
602
#notes

Thomas Eimers's avatar
Thomas Eimers committed
603
ng serve --host=0.0.0.0 --disable-host-check
604
http://localhost:4200/?api=http:%2F%2Fheating.fritz.box
605
606
607
608
609

sudo apt-get install wiringpi python-imaging
sudo apt-get install -y git-core python-dev
sudo apt-get install python-pip
sudo pip install spidev
Thomas Eimers's avatar
Thomas Eimers committed
610

Thomas Eimers's avatar
Thomas Eimers committed
611
## Image der SD Karte erstellen und Wiederherstellen:
Thomas Eimers's avatar
Thomas Eimers committed
612

Thomas Eimers's avatar
Thomas Eimers committed
613
614
### Backup erstellen
`sudo dd bs=1M if=/dev/sdd of=heating_control_2018_10_14.img`
Thomas Eimers's avatar
Thomas Eimers committed
615

Thomas Eimers's avatar
Thomas Eimers committed
616
617
### Backup wieder herstellen
`sudo dd bs=1M if=heating_control_2018_10_14.img.img of=/dev/sdd`
Thomas Eimers's avatar
Thomas Eimers committed
618

Thomas Eimers's avatar
Thomas Eimers committed
619
# Quellen
Thomas Eimers's avatar
Thomas Eimers committed
620

Thomas Eimers's avatar
Thomas Eimers committed
621
https://sven-s.de/mosquitto-mqtt-on-raspberry-pi-fails-on-startup/
Thomas Eimers's avatar
Thomas Eimers committed
622
http://www.marcsblog.de/2016/01/mit-openhab-werte-speichern-und-in-charts-darstellen-am-beispiel-der-zwischensteckdose-mit-leistungsmessung/