Projet de remplacement du "RPiPasserelle" d'Otec.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

INSTALL.md 4.3KB

Install instructions

Resources

You’ll need a rasbpiOs image, and the kernel and dtb for qemu

Procedure

Enlarge img

The downloaded img is resized on the SD card during the installation. We will need more space on the img. Qemu has command for that :

qemu-img resize rpi.img +1G

After booting

Log-in : rpi Password : raspberry

Login as root :

sudo su

Create udev rules :

cat << EOF > /etc/udev/rules.d/42-rs485.rules
SUBSYSTEMS=="usb-serial", DRIVERS=="ftdi_sio", SYMLINK+="rs485"
EOF

Dependencies

apt install git sqlite3 python3-pip python3-click python3-requests python3-netifaces python3-serial

Deployment

Deploy pyHeatpump. Replace MONITORING_SERVER with the address of your server :

mkdir /var/lib/pyheatpump
echo 'pip3 install --upgrade git+https://git.yannweb.net/cli/pyHeatpump.git' > /var/lib/pyheatpump/pyheatpump_upgrade.sh
chmod +x /var/lib/pyheatpump/pyheatpump_upgrade.sh
/var/lib/pyheatpump/pyheatpump_upgrade.sh

Database initialisation

cat << EOF > /var/lib/pyheatpump/pyheatpump.sql

CREATE TABLE IF NOT EXISTS var_type (
  slabel CHAR(1) UNIQUE PRIMARY KEY,
  label VARCHAR(10) UNIQUE,
  type VARCHAR(10) NOT NULL,
  start_address INT NOT NULL DEFAULT 0,
  end_address INT NOT NULL DEFAULT 250
);

CREATE TABLE IF NOT EXISTS variable (
  type CHAR(1) NOT NULL,
  address INT NOT NULL,
  unit VARCHAR(5) NULL,
  last_update INT NULL,


  FOREIGN KEY (type) REFERENCES var_type(slabel)
    ON DELETE CASCADE,
  PRIMARY KEY(type, address)
);

CREATE TABLE IF NOT EXISTS var_value (
  type CHAR(1) NOT NULL,
  address INT NOT NULL,
  time INT DEFAULT (strftime('%s', datetime('now'))),
  value INT NOT NULL,

  FOREIGN KEY (type) REFERENCES variable(type)
    ON DELETE CASCADE,
  FOREIGN KEY (address) REFERENCES variable(address)
    ON DELETE CASCADE,
  PRIMARY KEY(type, address, time)
);

INSERT INTO var_type (slabel, label, type, start_address, end_address) VALUES (
  'A', 'Analog', 'float', 1, 5000);
INSERT INTO var_type (slabel, label, type, start_address, end_address) VALUES (
  'I', 'Integer', 'int', 5002, 10002);
INSERT INTO var_type (slabel, label, type, start_address, end_address) VALUES (
  'D', 'Digital', 'bool', 1, 2048);

CREATE TRIGGER variable_last_update AFTER INSERT ON var_value
FOR EACH ROW
BEGIN
  UPDATE variable
  SET last_update = NEW.time
  WHERE
    type = NEW.type
    AND
    address = NEW.address;
END;

EOF

sqlite3 -init /var/lib/pyheatpump/pyheatpump.sql /var/lib/pyheatpump/pyheatpump.sqlite3

PyHeatpump configuration file

cat << EOF > /var/lib/pyheatpump/pyheatpump.ini
[heatpump]
database = /var/lib/pyheatpump/pyheatpump.sqlite3
serial_port = /dev/rsa485

[supervisor]
scheme = https
host = MONITORING_SERVER
port = 8081
post_path = /Symfony/web/app_dev.php/boardws/insert
get_path = /Symfony/web/app_dev.php/boardws/orders
interval = 60
heatpump_id = 42

[api]
host = 0.0.0.0
port = 80

EOF

API Service (no-need in production)

cat << EOF > /var/lib/pyheatpump/pyheatpump_api.service
[Unit]
Description=API to fetch data from heatpump with HTTP
After=network.target

[Service]
Type=simple
WorkingDirectory=/var/lib/pyheatpump/
Environment="LOGLEVEL=INFO"
ExecStart=/usr/bin/env pyheatpump run
KillMode=mixed
TimeoutStopSec=30
PrivateTmp=true

[Install]
WantedBy=multi-user.target

EOF

Fetch Service

cat << EOF > /var/lib/pyheatpump/pyheatpump_fetch.service
[Unit]
Description=pyHeatpump fetch - retrieve the data from the serial port with modbus
Wants=dev-rs485.device

[Service]
Type=simple
WorkingDirectory=/var/lib/pyheatpump/
Environment="LOGLEVEL=INFO"
ExecStart=/usr/bin/env pyheatpump fetch -t D -t A -t I
ExecStop=/usr/bin/env pyheatpump supervise --since
KillMode=mixed
TimeoutStopSec=30
PrivateTmp=true

EOF

Fetch Timer

cat << EOF > /var/lib/pyheatpump/pyheatpump_fetch.service
[Unit]
Description=Timer to launch pyheatpump fetch every minute

[Timer]
OnStartSec=15sec
OnUnitInactiveSec=1m

[Install]
WantedBy=timers.target

EOF

Installation of the services

cd /etc/systemd/system
ln -s /var/lib/pyheatpump/pyheatpump_api.service
ln -s /var/lib/pyheatpump/pyheatpump_fetch.service
ln -s /var/lib/pyheatpump/pyheatpump_fetch.timer

systemctl daemon-reload
systemctl enable pyheatpump_api.service pyheatpump_fetch.timer pyheatpump_supervise.timer

You may now reboot to see if everything works.