horchi / linux-p4d

Deamon which fetch sensor data of the 'Lambdatronic s3200' and store to a MySQL database
GNU General Public License v2.0
50 stars 22 forks source link

Linux - P4 Daemon (p4d)

This daemon is fetching data from the S 3200 and store it in a MariaDb database.

Written by: Jörg Wendel (linux at jwendel dot de)

Homepage: https://github.com/horchi/linux-p4d

License

This code is distributed under the terms and conditions of the GNU GENERAL PUBLIC LICENSE. See the file LICENSE for details.

Disclaimer

USE AT YOUR OWN RISK. No warranty. This software is a private contribution and not related Fröling. It may not work with future updates of the S3200 firmware and can also cause unintended behavior. Use at your own risk! THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Die Software wurde für den Eigengebrauch erstellt. Sie wird kostenlos unter der GPLv2 veröffentlicht.

Es ist kein fertiges Produkt, die Software entstand als Studie was hinsichtlich der Kommunikation mit der s3200 Steuerung möglich ist und kann Bastlern als Basis und Anregung für eigene Projekte dienen.

Es besteht kein Anspruch auf Funktion, jeder der sie einsetzen möchte muss das Risiko selbst abschätzen können und wissen was er tut, insbesondere auch in Hinblick auf die Einstellungen der Heizungsparameter und den damit verbundenen Risiken hinsichtlich Fehlfunktion, Störung, Brand, etc. Falsche Einstellung können unter anderem durch Bedienfehler und Fehler in dieser Software ausgelöst werden! Die Vorgaben, Vorschriften und AGB des Herstellers der Heizung bleiben maßgebend! Ich kann nicht ausschließen das es zu Fehlfunktionen oder unerwartetem Verhalten, auch hinsichtlich der zur Heizung übertragenen Daten und damit verbundenen, mehr oder weniger kritischen Fehlfunktionen derselben kommen kann!

Donation

If this project help you, you can give me a cup of coffee :)

paypal

Prerequisits:

Installation by package (actually available for Raspian Buster)

install

wget www.jwendel.de/p4d/install-deb.sh -O /tmp/install-deb.sh
sudo bash /tmp/install-deb.sh

uninstall

dpkg --remove p4d

uninstall (with remove of all configurations, data and the p4d database)

dpkg --purge p4d

Installation by source (working for most linux plattforms)

Preliminary:

Update your package data: sudo apt update and, if you like, update your installation: sudo apt dist-upgrade

Prerequisits:

Install libwebsockets (https://github.com/warmcat/libwebsockets)

at least version 4.1 or above you can clone it from git at https://libwebsockets.org/repo/libwebsockets

Installation of the MariaDb Database:

It's not required to host the database on the Raspberry. A remote database is supported as well! Perform all the following steps as root user! Either by getting root or by prefix each command with sodo.

apt install mariadb-server

(set database password for root user during installation)

Local database setup:

If the database server is located localy on same host as the p4d:

> mysql -u root -Dmysql -p
  CREATE DATABASE p4 charset utf8;
  CREATE USER 'p4'@'localhost' IDENTIFIED BY 'p4';
  GRANT ALL PRIVILEGES ON p4.* TO 'p4'@'localhost' IDENTIFIED BY 'p4';
  flush privileges;

Remote database setup:

if the database is running remote (on a other host or you like to habe remote access):

> mysql -u root -Dmysql -p
 CREATE DATABASE p4 charset utf8;
 CREATE USER 'p4'@'%' IDENTIFIED BY 'p4';
 GRANT ALL PRIVILEGES ON p4.* TO 'p4'@'%' IDENTIFIED BY 'p4';
 flush privileges;

Install and enable mosquitto

apt install mosquitto
systemctl start mosquitto
systemctl enable mosquitto

if you like to ceck mosquitto or use it from scripts install mosquitto client package

install mosquitto-clients

Installation of the p4d daemon:

install the build dependencies

apt install build-essential pkg-config libssl-dev libjansson-dev libcurl4-openssl-dev libmariadb-dev uuid-dev libcap-dev liblua5.3-dev

get the p4d and build it

cd /usr/src/
git clone https://github.com/horchi/linux-p4d/
cd linux-p4d
make clean all
make install

For older linux distributions which don't support the systemd init process use this instead of 'make install'

make install INIT_SYSTEM=sysV

If you like a other destination than '/usr/local' append PREFIX=your-destination (e.g. PREFIX=/usr) to all make calls above

Time to first start of p4d

systemctl start p4d

to check it's state call

systemctl status p4d

it should now 'enabled' and in state 'running'!

also check the syslog about errors of the p4d, this will show all its current log messages

grep "p4d:" /var/log/syslog

Aggregation / Cleanup

The samples will recorded in the configured interval (at the setup page), the default is 60 Seconds. After a while the database will grow and the selects become slower. Therefore you can setup a automatic aggregation by adjusting 'Historie' and 'Danach aggregieren über'

A 'Historie' of 365 means that all samples older than 365 days will be aggregated to one sample per ''Danach aggregieren über' minutes (for example 15 minutes) If you like to completely delete 'old' samples you have to do the cleanup job by hand, actually I don't see the need to delete anything, I like to hold my data (forever :) ?).

WEB interface:

The default port of the WEB interface is 1111, The default username and password for the login is User: p4 Pass: p4

Fist steps to enable data logging:

  1. Log in to the web interface
  2. Goto Setup -> Commands
    • click 'Init Sensors'
  3. Goto Setup -> IO Setup
    • Select the values you like to record and store your selection (click 'Speichern')
  4. Goto Setup -> Commands
    • click 'Init Service Menü'

After this you can set up the schema configuration. The schema configuration is done by drag&drop and isn't working on mobile devices! Also deleting of chart bookmarks isn't supported on mobile devices.

Setup and configure sending mails:

The next steps are an example to setup the sending of mails. If another tool is preferred it can be used as well.

If the heating values are added as attachment to the mail please check the next steps.

Configure Time sync:

With the next steps you can enable a time synchronization of the p4d and the heating: If you enable this feature you can set the max time difference between the p4d systemtime and the time of the heating. The p4d will set the time of the heating (once a day) to his the systemtime. Therefore it is recommended to hold your system time in sync, e.g. by running the ntp daemon or systemd-timesyncd.

MQTT Interface

Configure the parameters at the WEBIF

One Wire Sensors:

The p4d checks automatically if there are 'One Wire Sensors' connected, each detected sensor will be configurable via the web interface after reading the sensor facts by clicking [init].

To make the sensors availaspble to the raspi you have to load the w1-gpio module, this can be done by calling modprobe w1-gpio or automatically at boot by registering it in /etc/modules:

echo "w1-gpio" >> /etc/modules
echo "w1_therm" >> /etc/modules
echo "dtoverlay=w1-gpio,gpioin=4,pullup=on" >> /boot/config.txt

Style

You can chose the Web Interface Style at 'Setup' -> 'Allg. Konfiguration' with the options 'Farbschema' and 'Icon Style Set'. The 'Farbschema' option include all CSS styles which are found in your web folder and fit the naming scheme 'stylesheet-.css' where the wildcard '' is used as the name of the style. The 'Icon Style Set' option includes the name of all suborders of img/state/* in your web folder. You can place additional custom styles and icon sets which automatically appear in the settings. The default web folder is /var/lib/p4/.

Points to check

Use https for WEB interface:

Backup

Backup the data of the p4 database including all recorded values:

p4d-backup.sh

This will create a dump file for each table like:

<tablename>-dump.sql.gz

To import the backup:

gunzip NAME-dump.sql.gz
mysql -u p4 -pp4 -Dp4 < *-dump.sql

Alternative installation using Docker

https://hub.docker.com/r/n3m3515/docker-p4d

ATTENTION:

The import deletes at first all the data and then imports the dumped data. To append the dumped data you have to modify the SQL statements inside the dump files manually.

Additional information

MariaDb HINTS

If you cannot figure out why you get Access denied, remove all entries from the user table that have Host values with wildcars contained (entries that match % or _ characters). A very common error is to insert a new entry with Host='%' and User='some_user', thinking that this allows you to specify localhost to connect from the same machine. The reason that this does not work is that the default privileges include an entry with Host='localhost' and User=''. Because that entry has a Host value localhost that is more specific than %, it is used in preference to the new entry when connecting from localhost! The correct procedure is to insert a second entry with Host='localhost' and User='some_user', or to delete the entry with Host='localhost' and User=''. After deleting the entry, remember to issue a FLUSH PRIVILEGES statement to reload the grant tables.

To analyze this you can show all users:

use mysql
SELECT host, user FROM user;

Problems - anything is not working