A Python service that relays a Raspberry Pi temperature to an external service for processing.
More info to come later!
- Raspberry Pi (current development on Raspberry Pi Zero)
- Adafruit MCP9808 Temperature sensor
- Virtualenv
Running this project becomes infinitely easier when run in a virtual environment.
Install virtualenv (assuming you have access to python3):
$> python3 -m venv venv
Once virtualenv is installed, activate it:
$> source venv/bin/activate
From here, you should be able to follow the Install
section.
-
Download repo
-
Go into project folder
$> cd beer_temp_monitor
-
Install required packages
$> pip install -r requirements.txt
-
Run the monitor! (Currently, receiving server must be up and running!)
$> python src/beer_temp_monitor.py
This project is meant to run on the Pi at boot, without intervention. To that end, I currently use systemd
to start the program on boot.
More info on systemd here.
Details on how to accomplish this can be found here and here.
I thought I'd share some particulars on the systemd service file that eventually worked for me. In the following service file:
[Unit]
Description=Beer Monitor Service
After=multi-user.target
[Service]
Type=forking
User=pi
ExecStart=/bin/bash /home/pi/scripts/beer-monitor.sh > /home/pi/ service-logs/monitor.log 2>&1
[Install]
WantedBy=multi-user.target
Type
was set to forking
, because I run this project in a detched
screen. My previous attempt had it set to simple
. It failed, however,
because simple
tells systemd that the main process is meant to run
forever. In contrast, Screen is doing the opposite; it starts a new
session and forks to background. Details on how I discovered this can be
read in the answer found here.
I wanted to run this script, and ultimately the project, as the user
that the pi is setup on, so User
is set to pi_user
, where pi_user
is whatever your user is.