Heater: Difference between revisions

From FlowerHouseWiki
 
(79 intermediate revisions by the same user not shown)
Line 1: Line 1:
{{ContainerInfo
{{ContainerInfo
|title = Heater-LXC
|image = Froeling.jpg
|image = Froeling.jpg
|Domain = [https://heater.flowerhouse.at heater.flowerhouse.at]
|Domain = [https://heater.flowerhouse.at heater.flowerhouse.at]
|IP = 192.168.88.12
|IP = 192.168.88.11
|MAC = DA:62:17:83:4E:8F
|MAC = DA:62:17:83:4E:8F
|Privileged = No
|Privileged = No
|OS = Debian Buster
|OS = Debian Bullseye
|RAM = 512MB
|RAM = 512MB
|Cores = 1
|Cores = 1
}}
}}


<p>The Heater-LXC is reachable under <syntaxhighlight lang="Bash" inline>192.168.88.12</syntaxhighlight> which is located in the ServerVLAN.</p>
<p>The Heater-LXC is reachable under <syntaxhighlight lang="Bash" inline>192.168.88.11</syntaxhighlight> which is located in the ServerVLAN.</p>
<p>The subdomain is [https://heater.flowerhouse.at heater.flowerhouse.at] which is handled by the [[ReverseProxy]].</p>
<p>The subdomain is [https://heater.flowerhouse.at heater.flowerhouse.at] which is handled by the [[ReverseProxy]].</p>
<p>The Serial-IP-Konverter is reachable under <syntaxhighlight lang="Bash" inline>192.168.88.18</syntaxhighlight> which is located in the ServerVLAN.</p>
<p>The Serial-IP-Konverter is reachable under <syntaxhighlight lang="Bash" inline>192.168.88.12</syntaxhighlight> which is located in the ServerVLAN.</p>
__TOC__
__TOC__
== Basic Setup ==
== Basic Setup ==
Line 24: Line 23:
<p>Install required packages:</p>
<p>Install required packages:</p>
<syntaxhighlight lang="console">
<syntaxhighlight lang="console">
apt install pkg-config cmake
apt install pkg-config cmake git build-essential libssl-dev liblua5.3-dev
</syntaxhighlight>
</syntaxhighlight>


Line 37: Line 36:
cd libwebsockets
cd libwebsockets
mkdir build
mkdir build
cd build
</syntaxhighlight>
</syntaxhighlight>


Line 57: Line 57:
</syntaxhighlight>
</syntaxhighlight>


=== Configure Database ===
=== p4d daemon ===
<p>Install required packages:</p>
<p>Install required packages:</p>
<syntaxhighlight lang="console">
<syntaxhighlight lang="console">
apt install mariadb-server
apt install libssl-dev libjansson-dev libxml2-dev libcurl4-openssl-dev libssl-dev libmariadb-dev-compat uuid-dev python3-dev libcap-dev
</syntaxhighlight>
</syntaxhighlight>


<p>Create database and user:</p>
<p>Download latest version:</p>
<syntaxhighlight lang="console" line>
<syntaxhighlight lang="console" line>
mysql -u root -Dmysql -p
wget https://github.com/horchi/linux-p4d/archive/refs/tags/0.8.8.tar.gz
CREATE DATABASE p4 charset utf8;
tar -xvf 0.8.8.tar.gz
CREATE USER 'p4'@'localhost' IDENTIFIED BY 'p4';
rm 0.8.8.tar.gz
GRANT ALL PRIVILEGES ON p4.* TO 'p4'@'localhost' IDENTIFIED BY 'p4';
mv linux-p4d-0.8.8 linux-p4d
flush privileges;
cd linux-p4d
</syntaxhighlight>
</syntaxhighlight>


=== p4d daemon ===
<p>Build it:</p>
<p>Install required packages:</p>
<syntaxhighlight lang="console" line>
<syntaxhighlight lang="console">
make clean all NO_RASPBERRY_PI=1
apt install build-essential libssl-dev libjansson-dev libxml2-dev libcurl4-openssl-dev libssl-dev libmariadbclient-dev libmariadb-dev-compat uuid-dev
make install NO_RASPBERRY_PI=1
</syntaxhighlight>
</syntaxhighlight>


<p>Get p4d repo and build it:</p>
<p>Delete build files:</p>
<syntaxhighlight lang="console" line>
<syntaxhighlight lang="console" line>
cd /usr/src/
cd /usr/src
git clone https://github.com/horchi/linux-p4d/
rm -r linux-p4d
cd linux-p4d
make clean all
make install
</syntaxhighlight>
</syntaxhighlight>


<p>Edit ''p4d.conf'':</p>
<p>Create database at [[DataBase]] and add credentials to ''daemon.conf'':</p>
<syntaxhighlight lang="console">
<syntaxhighlight lang="console">
nano /etc/p4d.conf
nano /etc/p4d/daemon.conf
</syntaxhighlight>
</syntaxhighlight>


Line 98: Line 95:


=== Serial-IP-Converter ===
=== Serial-IP-Converter ===
<p>Access the Serial-IP-Converter-UI under <syntaxhighlight lang="Bash" inline>192.168.88.18</syntaxhighlight> with <syntaxhighlight lang="Bash" inline>user: admin</syntaxhighlight> and <syntaxhighlight lang="Bash" inline>pw: admin</syntaxhighlight> and set the UART-settings:</p>
<p>Access the Serial-IP-Converter-UI under <syntaxhighlight lang="Bash" inline>192.168.88.12</syntaxhighlight> with <syntaxhighlight lang="Bash" inline>user: admin</syntaxhighlight> and <syntaxhighlight lang="Bash" inline>pw: admin</syntaxhighlight> and set the UART-settings:</p>
 
[[File:Serial settings.png|1000px|center]]
 
<p>Install socat:</p>
<syntaxhighlight lang="console">
apt install socat
</syntaxhighlight>
 
<p>Connect to Serial-IP-Converter with:</p>
<syntaxhighlight lang="console">
socat pty,link=/dev/ttyUSB0,raw tcp:192.168.88.12:8899&
</syntaxhighlight>
 
<p>For it to connect at boot we have create an service:</p>
<syntaxhighlight lang="console">
nano /etc/systemd/system/socat.service
</syntaxhighlight>
 
<p>Add to file:</p>
<syntaxhighlight lang="console" line>
 
[Unit]
Description=SOCAT Listen Service
After=network.target redis.service
Wants=redis.service
 
[Service]
Type=simple
StandardOutput=journal
StandardError=journal
SyslogIdentifier=socat-serial-log
User=root
ExecStart=/bin/bash -c '/usr/bin/socat pty,link=/dev/ttyUSB0,raw tcp:192.168.88.12:8899'
Restart=on-failure
 
[Install]
WantedBy=multi-user.target
</syntaxhighlight>
 
<p>Start and check if service is running:</p>
<syntaxhighlight lang="console" line>
systemctl start socat
systemctl status socat
</syntaxhighlight>
 
<p>Enable service to start at boot:</p>
<syntaxhighlight lang="console">
systemctl enable socat
</syntaxhighlight>
 
=== Web Interface Setup ===
<p>The default port of the web interface is 1111, the default username is <syntaxhighlight lang="Bash" inline>p4</syntaxhighlight> and the password is <syntaxhighlight lang="Bash" inline>p4</syntaxhighlight>.</p>
<p>Fist steps to enable data logging:</p>
# Log in to the web interface
# Click ''Init Messwerte''
# Go to ''Aufzeichnung'' and select the values you like to record and store your selection and save
# Go to ''Setup'' and click 'Init Service Menü'
 
== Update Script ==
<p>Bash script to update p4d:</p>
<syntaxhighlight lang="bash" line>
#!/bin/bash
 
# Variables
name="P4D"
repo="horchi/linux-p4d"
 
binary_path="/usr/local/bin"
binary_name="p4d"
 
# ===== VERSION CHECKING, CUSTOMIZE VARIBLES FOR IT =====
# Get current version
current=$($binary_path/$binary_name -v)
 
# Retain everything after last space
current=${current//[!0-9.]/}
 
# Get latest release tag
latest=$(curl -sL https://api.github.com/repos/$repo/tags | jq -r '.[0].name')
 
# Check if new version available
if (("$(expr ${current//[!0-9]/} + 0)" == "$(expr ${latest//[!0-9]/} + 0)")); then
        echo -e "--------------------------------------"
        echo -e "- Installed ${current} is up to date"
        echo -e "--------------------------------------"
        exit 0
fi
 
# Check if repo is deprecated
if (("$(expr ${current//[!0-9]/} + 0)" > "$(expr ${latest//[!0-9]/} + 0)")); then
        echo -e "--------------------------------------------------------------------------------"
        echo -e "- Installed ${current} is newer than available version, repository deprecated?"
        echo -e "--------------------------------------------------------------------------------"
        exit 0
fi
 
# Write information
echo -e "--------------------------------------------"
echo -e "- Update ${name} ${current} to ${latest}?"
echo -e "--------------------------------------------"
 
echo -e -n "Continue? [y/N]"
echo ""
read -n 1 c
 
if [ "${c}" != "y" ]; then
exit 0
fi
 
# ===== INSTALLATION PART, CUSTOMIZE FOR EACH SOFTWARE =====
# Go to folder
cd /usr/src
 
# Download files
wget https://github.com/horchi/linux-p4d/archive/refs/tags/${latest}.tar.gz || exit 1
 
# Untar files
tar -xvf ${latest}.tar.gz || exit 1
 
# Enter folder
cd linux-p4d-${latest} || exit 1
 
# Start compiling
make clean all NO_RASPBERRY_PI=1 || exit 1
make install NO_RASPBERRY_PI=1 || exit 1
 
# Exit folder
cd .. || exit 1
 
# Restart p4d
systemctl restart p4d || exit 1
 
# Remove old files
rm ${latest}.tar.gz || exit 1
rm -r linux-p4d-${latest} || exit 1
 
# ===== FINISH INSTALLATION SCRIPT ====
echo -e "-----------------------------------"
echo -e "- Update to ${latest} completed!"
echo -e "-----------------------------------"
</syntaxhighlight>
 
== Additional Configuration ==
=== Mail Notification ===
<p>Install required packages:</p>
<syntaxhighlight lang="Bash">
apt install msmtp-mta bsd-mailx
</syntaxhighlight>
 
<p>Create the msmspt configuration file:</p>
<syntaxhighlight lang="Bash">
nano /etc/msmtprc
</syntaxhighlight>
 
<p>And paste following entry:</p>
<syntaxhighlight lang="Bash" line>
# Set default values for all following accounts.
defaults
port 587
tls on
tls_trust_file /etc/ssl/certs/ca-certificates.crt
 
account flowerhouse
host smtp.world4you.com
from heater@flowerhouse.at
auth on
user heater@flowerhouse.at
password XXXXXXX
 
# Set a default account
account default : flowerhouse
</syntaxhighlight>
 
<p>The setup can be tested with:</p>
<syntaxhighlight lang="Bash">
mail -s "test" address@email.com < /dev/null
</syntaxhighlight>


[[File:Serial settings.png|400px|center]]
<p>If the setup is working, go to the webinterface and configure the mail notifications in the setup page.</p>
socat pty,link=/dev/HeaterCOM,raw  tcp:192.168.88.18:8899&


== Sources ==
== Sources ==
Line 107: Line 280:
* [https://stackoverflow.com/questions/22624653/create-a-virtual-serial-port-connection-over-tcp SoCat]
* [https://stackoverflow.com/questions/22624653/create-a-virtual-serial-port-connection-over-tcp SoCat]
* [https://forum.iobroker.net/topic/24792/gel%C3%B6st-adapter-smartmeter-per-ser2net-und-socat/3 SoCat-Service]
* [https://forum.iobroker.net/topic/24792/gel%C3%B6st-adapter-smartmeter-per-ser2net-und-socat/3 SoCat-Service]
* [https://wiki.debian.org/msmtp Mail-Service]

Latest revision as of 21:52, 24 February 2024

Froeling.jpg

Network


IP: 192.168.88.11
MAC: DA:62:17:83:4E:8F
Domain: heater.flowerhouse.at

System


OS: Debian Bullseye
RAM: 512MB
Cores: 1
Privileged: No

The Heater-LXC is reachable under 192.168.88.11 which is located in the ServerVLAN.

The subdomain is heater.flowerhouse.at which is handled by the ReverseProxy.

The Serial-IP-Konverter is reachable under 192.168.88.12 which is located in the ServerVLAN.

Basic Setup

Change locales to de_DE.UTF-8:

dpkg-reconfigure locales

libwebsockets

Install required packages:

apt install pkg-config cmake git build-essential libssl-dev liblua5.3-dev

Clone libwebsockets repo:

cd /usr/src
git clone https://libwebsockets.org/repo/libwebsockets

Create build directory:

cd libwebsockets
mkdir build
cd build

Run make to build libwebsockets:

cmake ..
make
make install

Create the necessary links and cache:

ldconfig

Delete unnecessary files:

cd /usr/src
rm -r libwebsockets

p4d daemon

Install required packages:

apt install libssl-dev libjansson-dev libxml2-dev libcurl4-openssl-dev libssl-dev libmariadb-dev-compat uuid-dev python3-dev libcap-dev

Download latest version:

wget https://github.com/horchi/linux-p4d/archive/refs/tags/0.8.8.tar.gz
tar -xvf 0.8.8.tar.gz
rm 0.8.8.tar.gz
mv linux-p4d-0.8.8 linux-p4d
cd linux-p4d

Build it:

make clean all NO_RASPBERRY_PI=1
make install NO_RASPBERRY_PI=1

Delete build files:

cd /usr/src
rm -r linux-p4d

Create database at DataBase and add credentials to daemon.conf:

nano /etc/p4d/daemon.conf

Start p4d:

systemctl start p4d

Serial-IP-Converter

Access the Serial-IP-Converter-UI under 192.168.88.12 with user: admin and pw: admin and set the UART-settings:

Serial settings.png

Install socat:

apt install socat

Connect to Serial-IP-Converter with:

socat pty,link=/dev/ttyUSB0,raw tcp:192.168.88.12:8899&

For it to connect at boot we have create an service:

nano /etc/systemd/system/socat.service

Add to file:

[Unit]
Description=SOCAT Listen Service
After=network.target redis.service
Wants=redis.service

[Service]
Type=simple
StandardOutput=journal
StandardError=journal
SyslogIdentifier=socat-serial-log
User=root
ExecStart=/bin/bash -c '/usr/bin/socat pty,link=/dev/ttyUSB0,raw tcp:192.168.88.12:8899'
Restart=on-failure

[Install]
WantedBy=multi-user.target

Start and check if service is running:

systemctl start socat
systemctl status socat

Enable service to start at boot:

systemctl enable socat

Web Interface Setup

The default port of the web interface is 1111, the default username is p4 and the password is p4.

Fist steps to enable data logging:

  1. Log in to the web interface
  2. Click Init Messwerte
  3. Go to Aufzeichnung and select the values you like to record and store your selection and save
  4. Go to Setup and click 'Init Service Menü'

Update Script

Bash script to update p4d:

#!/bin/bash

# Variables
name="P4D"
repo="horchi/linux-p4d"

binary_path="/usr/local/bin"
binary_name="p4d"

# ===== VERSION CHECKING, CUSTOMIZE VARIBLES FOR IT =====
# Get current version
current=$($binary_path/$binary_name -v)

# Retain everything after last space
current=${current//[!0-9.]/}

# Get latest release tag
latest=$(curl -sL https://api.github.com/repos/$repo/tags | jq -r '.[0].name')

# Check if new version available
if (("$(expr ${current//[!0-9]/} + 0)" == "$(expr ${latest//[!0-9]/} + 0)")); then
        echo -e "--------------------------------------"
        echo -e "- Installed ${current} is up to date"
        echo -e "--------------------------------------"
        exit 0
fi

# Check if repo is deprecated
if (("$(expr ${current//[!0-9]/} + 0)" > "$(expr ${latest//[!0-9]/} + 0)")); then
        echo -e "--------------------------------------------------------------------------------"
        echo -e "- Installed ${current} is newer than available version, repository deprecated?"
        echo -e "--------------------------------------------------------------------------------"
        exit 0
fi

# Write information
echo -e "--------------------------------------------"
echo -e "- Update ${name} ${current} to ${latest}?"
echo -e "--------------------------------------------"

echo -e -n "Continue? [y/N]"
echo ""
read -n 1 c

if [ "${c}" != "y" ]; then
	exit 0
fi

# ===== INSTALLATION PART, CUSTOMIZE FOR EACH SOFTWARE =====
# Go to folder
cd /usr/src

# Download files
wget https://github.com/horchi/linux-p4d/archive/refs/tags/${latest}.tar.gz || exit 1

# Untar files
tar -xvf ${latest}.tar.gz || exit 1

# Enter folder
cd linux-p4d-${latest} || exit 1

# Start compiling
make clean all NO_RASPBERRY_PI=1 || exit 1
make install NO_RASPBERRY_PI=1 || exit 1

# Exit folder
cd .. || exit 1

# Restart p4d
systemctl restart p4d || exit 1

# Remove old files
rm ${latest}.tar.gz || exit 1
rm -r linux-p4d-${latest} || exit 1

# ===== FINISH INSTALLATION SCRIPT ====
echo -e "-----------------------------------"
echo -e "- Update to ${latest} completed!"
echo -e "-----------------------------------"

Additional Configuration

Mail Notification

Install required packages:

apt install msmtp-mta bsd-mailx

Create the msmspt configuration file:

nano /etc/msmtprc

And paste following entry:

# Set default values for all following accounts.
defaults
port 587
tls on
tls_trust_file /etc/ssl/certs/ca-certificates.crt

account flowerhouse
host smtp.world4you.com
from heater@flowerhouse.at
auth on
user heater@flowerhouse.at
password XXXXXXX

# Set a default account
account default : flowerhouse

The setup can be tested with:

mail -s "test" address@email.com < /dev/null

If the setup is working, go to the webinterface and configure the mail notifications in the setup page.

Sources