Skip to content

Raspberry Pi

Marc-Olivier Arsenault edited this page Dec 29, 2022 · 5 revisions

Physical connection

To control the Humidifier, we do need a physical device. My Humidifier (Like most) require a dry connection between the Ground and signal wire, when those 2 are connected the unit start, when they are disconnected the unit stop.

As an example, this is my device. Connection can be achieved with a simple wire connector. 184F5014-4450-40C9-8F56-8539DE6B9618_1_105_c

I will replace the Wire connector by a Raspberry pi + Relay hat that will manage the connection automatically. To do this I will use:

Then I will connect the 2 wires (ground and signal) on one of the 3 Relay (I picked the 1st one) on the normally open circuit. _This imply, that when the pi is off, or that Tefnut is not running, the Relay will be open, in other words, the Humidifier will NOT work)

This is what it will look like

image image2

Software configuration

  • Install Raspberry pi OS
  • Install required software
# update pi
sudo apt-get update
sudo apt-get upgrade
sudo apt-get install pip3 git python3 

# Install poetry
curl -sSL https://install.python-poetry.org | python3 -

# get the code
git clone [email protected]:marcolivierarsenault/tefnut.git

cd tefnut

# install dependencies
poetry install

# copy configs 
cp _template.settings.toml settings.toml

Configure config file Configuration

# run program 
poetry run gunicorn --threads=2  -b 0.0.0.0:5000 main:app

# run the script even if logout of ssh
nohup poetry run gunicorn --threads=2  -b 0.0.0.0:5000 main:app &

Run as a Service

Optionally you can turn the python script in a Linux service. To do this:

  1. Create service file sudo vi /lib/systemd/system/tefnut.service
[Unit]
Description=Tefnut
After=multi-user.target

[Service]
WorkingDirectory=/home/marco/tefnut
ExecStart=/home/marco/.local/bin/poetry run gunicorn --threads=2  -b 0.0.0.0:5000 main:app
User=marco
KillSignal=SIGINT


Restart=always
RestartSec=300

[Install]
WantedBy=multi-user.target
  1. Configure the service
sudo systemctl daemon-reload
sudo systemctl enable tefnut.service
sudo init 6  # Reboot
  1. After reboot, verify it is working:
journalctl -u tefnut.service
sudo systemctl status tefnut.service

Use on port 80

Port 80 is blocked by the os, and tefnut uses port 5000. If you want to forward the traffic from port 80 you can set an internal rule in the pi:

sudo iptables -A PREROUTING -t nat -i eth0 -p tcp --dport 80 -j REDIRECT --to-port 5000
Clone this wiki locally