doc:appunti:hardware:raspberrypi_thermostat
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
doc:appunti:hardware:raspberrypi_thermostat [2022/01/03 16:56] – [Operating System Customization] niccolo | doc:appunti:hardware:raspberrypi_thermostat [2022/01/12 16:11] (current) – [Installing the old Adafruit LCD library] niccolo | ||
---|---|---|---|
Line 570: | Line 570: | ||
===== Installing on Raspberry Pi OS 2021-10-30 Bullseye ===== | ===== Installing on Raspberry Pi OS 2021-10-30 Bullseye ===== | ||
- | The latest version of the ProTherm software should work on Debian 11 Bullseye, this means using **Python 3.9** both for the **ProTherm** package and for the **Telegram bot** daemon. Also the **Adafruit libraries** | + | The latest version of the ProTherm software should work on Debian 11 Bullseye, this means using **Python 3.9** both for the **ProTherm** package and for the **Telegram bot** daemon. Also the **Adafruit libraries** |
I copied the **Raspberry Pi OS Lite** image onto the SD card, before the first bootstrap I enabled remote ssh and WiFi by creating two files into the boot partitions: | I copied the **Raspberry Pi OS Lite** image onto the SD card, before the first bootstrap I enabled remote ssh and WiFi by creating two files into the boot partitions: | ||
Line 597: | Line 597: | ||
This is a brief check-out list of customizations required by the operating system. See above for more details. | This is a brief check-out list of customizations required by the operating system. See above for more details. | ||
- | * Disabled the **serial line console** from **/ | + | * Disabled the **serial line console** from **/ |
* Disabled **login on serial console** with '' | * Disabled **login on serial console** with '' | ||
* Using **raspi-config**: | * Using **raspi-config**: | ||
Line 615: | Line 615: | ||
</ | </ | ||
- | I turned out that an idle eth0 causes that, just disable | + | I turned out that an idle eth0 causes that, just disable |
< | < | ||
ifconfig eth0 down | ifconfig eth0 down | ||
</ | </ | ||
+ | |||
+ | To leave the interface down at bootstrap you must configure the **dhcpcd** daemon, which is repsponsible for network configuration in Raspberry Pi OS. Edit the file **/ | ||
+ | |||
+ | < | ||
+ | denyinterfaces eth0 | ||
+ | </ | ||
* **[[https:// | * **[[https:// | ||
* **[[https:// | * **[[https:// | ||
- | ==== Installing the Adafruit LCD library ==== | + | === Nginx and PHP === |
+ | |||
+ | You can verify that the web server and PHP are running: | ||
+ | |||
+ | < | ||
+ | systemctl status nginx.service | ||
+ | systemctl status php7.4-fpm.service | ||
+ | </ | ||
+ | |||
+ | Check also if the socket **/ | ||
+ | |||
+ | < | ||
+ | index index.php index.html index.htm index.nginx-debian.html; | ||
+ | |||
+ | location ~ \.php$ { | ||
+ | include snippets/ | ||
+ | # With php-fpm (or other unix sockets): | ||
+ | fastcgi_pass unix:/ | ||
+ | } | ||
+ | </ | ||
+ | |||
+ | If you want Nginx to log to syslog instead that into a file, edit **/ | ||
+ | |||
+ | < | ||
+ | access_log syslog: | ||
+ | error_log syslog: | ||
+ | </ | ||
+ | |||
+ | ==== Installing the new Adafruit LCD library ==== | ||
+ | |||
+ | **WARNING**: | ||
+ | |||
+ | **WARNING**: | ||
+ | |||
+ | {{.: | ||
- | Nowdays (2021), to operate the Nokia LCD, we used the **[[https:// | + | Nowdays (2021), to operate the Nokia LCD, we should use the **[[https:// |
To download the library **adafruit-circuitpython-pcd8544** and its dependencies without installing them: | To download the library **adafruit-circuitpython-pcd8544** and its dependencies without installing them: | ||
Line 647: | Line 688: | ||
< | < | ||
pip3 install --no-deps adafruit_circuitpython_pcd8544-1.2.6-py3-none-any.whl | pip3 install --no-deps adafruit_circuitpython_pcd8544-1.2.6-py3-none-any.whl | ||
- | pip3 install --no-deps Adafruit_Blinka-6.17.0-py3-none-any.whl | + | pip3 install --no-deps Adafruit_Blinka-6.18.0-py3-none-any.whl |
pip3 install --no-deps adafruit_circuitpython_busdevice-5.1.1-py3-none-any.whl | pip3 install --no-deps adafruit_circuitpython_busdevice-5.1.1-py3-none-any.whl | ||
pip3 install --no-deps adafruit_circuitpython_framebuf-1.4.8-py3-none-any.whl | pip3 install --no-deps adafruit_circuitpython_framebuf-1.4.8-py3-none-any.whl | ||
- | pip3 install --no-deps Adafruit_PlatformDetect-3.18.0-py3-none-any.whl | + | pip3 install --no-deps Adafruit_PlatformDetect-3.19.1-py3-none-any.whl |
pip3 install --no-deps Adafruit_PureIO-1.1.9-py3-none-any.whl | pip3 install --no-deps Adafruit_PureIO-1.1.9-py3-none-any.whl | ||
pip3 install --no-deps pyftdi-0.53.3-py3-none-any.whl | pip3 install --no-deps pyftdi-0.53.3-py3-none-any.whl | ||
Line 666: | Line 707: | ||
Our LCD hardware works at best with **display.bias = 5** and **display.contrast = 57**. | Our LCD hardware works at best with **display.bias = 5** and **display.contrast = 57**. | ||
+ | |||
+ | ==== Installing the old Adafruit LCD library ==== | ||
+ | |||
+ | As reported above, the old and discontinued library **[[https:// | ||
+ | |||
+ | The library is not available from the **[[https:// | ||
+ | |||
+ | < | ||
+ | apt install python3-spidev | ||
+ | mkdir -p / | ||
+ | cd / | ||
+ | pip3 download Adafruit-GPIO | ||
+ | pip3 install Adafruit_PureIO-1.1.9-py3-none-any.whl | ||
+ | pip3 install Adafruit_GPIO-1.0.3-py3-none-any.whl | ||
+ | </ | ||
+ | |||
+ | We download the library from its **GitHub repository** and install it using **pip3**: | ||
+ | |||
+ | < | ||
+ | cd / | ||
+ | git clone https:// | ||
+ | cd Adafruit_Nokia_LCD/ | ||
+ | pip3 install . | ||
+ | </ | ||
+ | |||
+ | The dependencies tree is the following: | ||
+ | |||
+ | * Adafruit_Nokia_LCD | ||
+ | * Adafruit_GPIO | ||
+ | * Adafruit_PureIO | ||
+ | * spidev | ||
==== Installing the Telegram Bot Python library ==== | ==== Installing the Telegram Bot Python library ==== | ||
Line 691: | Line 763: | ||
pip3 install telepot-12.7-py3-none-any.whl | pip3 install telepot-12.7-py3-none-any.whl | ||
</ | </ | ||
+ | |||
+ | ==== Starting the protherm service at bootstrap ==== | ||
+ | |||
+ | Raspberry Pi OS based on **Debian 11 Bullseye** uses **systemd** to start services on bootstrap. The **protherm** service requires the **/ | ||
+ | |||
+ | First of all we create an //udev// rule; the rule will force //systemd// to create a " | ||
+ | |||
+ | < | ||
+ | # Inform systemd when the kernel device / | ||
+ | # Systemd will create a systemd device named " | ||
+ | # can be used to trigger the start of a service. | ||
+ | ACTION==" | ||
+ | </ | ||
+ | |||
+ | We use three keywords that must matched (because of the **%%==%%** sign) during an udev event. If the event is of type device **add**, the device belongs to the **spidev** subsystem and the kernel device name is **spidev0.0**, | ||
+ | |||
+ | Systemd includes the **systemd-udevd.service** which will notice every device tagged witht the string **systemd** and dynamically creates a **device unit**. In this case the unit will be called **dev-spidev0.0.device**. You can ask systemd to list all the existing device units (because of the **%%--all%%** option, also the short name is listed): | ||
+ | |||
+ | < | ||
+ | systemctl list-units --all --type=device | ||
+ | ... | ||
+ | dev-spidev0.0.device | ||
+ | ... | ||
+ | </ | ||
+ | |||
+ | If the systemd device does not exist, it probably means that the udev rule did not worked as expected. Thanks to this systemd device unit, we can write a protherm systemd unit that will start the service only after the device is instantiated by the kernel. The systemd unit will be **/ | ||
+ | |||
+ | < | ||
+ | [Unit] | ||
+ | Description=Programmable Thermostat Service | ||
+ | After=syslog.target | ||
+ | # Wait for spidev0.0 systemd device to be available. | ||
+ | After=dev-spidev0.0.device | ||
+ | Requires=dev-spidev0.0.device | ||
+ | |||
+ | [Service] | ||
+ | Type=simple | ||
+ | WorkingDirectory=/ | ||
+ | ExecStart=/ | ||
+ | |||
+ | [Install] | ||
+ | WantedBy=multi-user.target | ||
+ | </ | ||
===== Web references ===== | ===== Web references ===== |
doc/appunti/hardware/raspberrypi_thermostat.txt · Last modified: 2022/01/12 16:11 by niccolo