Skip to content

Commit

Permalink
moving to python3.9 and updating dependencies
Browse files Browse the repository at this point in the history
* simplifying Hafas endpoint (removing hafasglue daemon and using pyhafas)
* updating versions for requests and Pillow
* install now auto-builds binaries if downloadables incompatible with RPi
* added some instructions about build dependencies to README
* upgrading meross_iot from 0.4 to 0.3 due to breaking API changes
* using meross_iot as pip package instead of as submodule
  • Loading branch information
benjaminsoellner committed Aug 13, 2023
1 parent c2ff408 commit 6c97fd7
Show file tree
Hide file tree
Showing 14 changed files with 147 additions and 318 deletions.
39 changes: 19 additions & 20 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,23 +18,16 @@ The application is developed as Python application that can be run as a linux
daemon and update the system at regular times (currently multiples of 5 minute steps
which I found best for the slow refresh cycles of the Waveshare display).

The application also talks to a concurrently running NodeJs application
(called **hafasglue**) in order to interface with the German "Deutsche Bahn" public
transit API "Hafas". You can forego this concurrently running application and configure
the corresponding widget to retrieve data from the Google Directions API instead - which
is unfortunately not for free but (given that API calls are not cached) rather pricey.

Here are some other libraries and projects that were helpful and/or whose code I
ended up incorporating into this project:

* [`rgerganov/py-air-control`](https://github.com/rgerganov/py-air-control/) - Command
Line App for controlling Philipps Air Purifier - modified version stored at
`quietpaper/iot/airctrl.py`
* [`public-transport/hafas-client`](https://github.com/public-transport/hafas-client/blob/4/docs/journeys.md) -
* [`FahrplanDatenGarten/pyhafas`](https://github.com/FahrplanDatenGarten/pyhafas) -
Hafas is the German "Deutsche Bahn" system that provides the electronic
public transit timetables and this is a NodeJs client of of their
rather clunky XML Webservice. The client is supplied as a much leaner
REST-API by my NodeJs servlet in `hafasglue`.
public transit timetables and this is a Python library for their
rather clunky XML Webservice.
* [`momorientes/istheutefeinstaubalarm`](https://github.com/momorientes/istheutefeinstaubalarm) -
my town Stuttgart, Germany provides "Smog Alerts" on which days we should
leave our cars at home, use public transit for lower price (in some cases
Expand All @@ -55,8 +48,9 @@ ended up incorporating into this project:

1. You need the following prequisites:
* Raspbian Stretch Image
* Python 3 Installation
* Node Version Manager or Node Package Manager
* Python 3.9 Installation:
* [`albertogeniola/MerossIot`](https://github.com/albertogeniola/MerossIot) needs at least 3.7, but this caused Segmentation Faults on my Raspbian Stretch image whenever `asyncio` functionality was used
* Loosely follow these instructions and use an up-to-date Python 3.9.x patch version, e.gp. I used 3.9.17: https://gist.github.com/matthiasroos/3c8f1e0265eff6b60f6a7bcf701daa14)
* Display connected to Raspberry

2. Next, if you want to use all widgets exactly in the layout I use you can just copy
Expand All @@ -68,20 +62,25 @@ situation.
re-arrange them. For this, see the next chapters. You might at least want to edit
the file `quietpaper/config.py` which sets the layout of the widgets on the display.

4. You can then install both the `quietpaper` daemon (Python app which updates the display)
and the `hafasglue` daemon (Node-JS servlet which talks to Hafas in order to retrieve
public transit information) by calling:
4. Installing will build a few packages from their Python Wheels Sources. For this
process you need (once, you can uninstall those programs after the installation process):
```bash
sudo apt-get install libjpeg-dev zlib1g-dev # for installing pip Pillow from source
sudo apt-get install python-dev libatlas-base-dev # for installing Numpy from source
```

5. You can then install the `quietpaper` daemon (Python app which updates the display)
by calling:
```bash
./install-and-autorun.bash
```

5. The display will now load! - You can start/stop/restart the daemons by calling
```
sudo service {start|stop|restart} {quietpaper|hafasglue}
6. The display will now load! - You can start/stop/restart the daemons by calling
```bash
sudo service {start|stop|restart} quietpaper
```
... or, after stopping the services, run them directly with:
```
./hafasglue.bash
```bash
./quietpaper.bash
```

Expand Down
10 changes: 0 additions & 10 deletions hafasglue.bash

This file was deleted.

1 change: 0 additions & 1 deletion hafasglue/.gitignore

This file was deleted.

56 changes: 0 additions & 56 deletions hafasglue/hafasglue.js

This file was deleted.

18 changes: 0 additions & 18 deletions hafasglue/package.json

This file was deleted.

76 changes: 0 additions & 76 deletions hafasglued

This file was deleted.

29 changes: 7 additions & 22 deletions install-and-autorun.bash
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,13 @@ here="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
fi

# install venv
if [ ! -d ./venv-quietpaper ]; then
python3 -m virtualenv venv-quietpaper
. venv-quietpaper/bin/activate
pip3 install -r requirements.txt
pip3 install MerossIot/
if [ ! -d ./venv3.9-quietpaper ]; then
python3.9 -m venv venv3.9-quietpaper
. venv3.9-quietpaper/bin/activate
pip install --upgrade "pip==23.2.1"
# I had problems installing Rust on Debian Stretch, so use an older version of
# cryptography that doesn't require it.
CRYPTOGRAPHY_DONT_BUILD_RUST=1 pip install -r requirements.txt
deactivate
fi

Expand All @@ -42,23 +44,6 @@ here="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
update-rc.d quietpaper defaults
fi

# install dependencies for hafasglue
(
pushd ./hafas-glue >/dev/null 2>&1
npm install .
popd >/dev/null
)

# install hafasglue daemon
if [ ! -f /etc/init.d/hafasglue ]; then
cp ./hafasglued /etc/init.d/hafasglue
sed -i -e "s%@APPDIR@%$here%g" /etc/init.d/hafasglue
sed -i -e "s%@APPBIN@%$here/hafasglue.bash%g" /etc/init.d/hafasglue
chmod +x /etc/init.d/hafasglue
update-rc.d hafasglue defaults
fi

service hafasglue start
service quietpaper start

popd >/dev/null 2>&1
Expand Down
4 changes: 2 additions & 2 deletions quietpaper.bash
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
here="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
(
pushd $here >/dev/null 2>&1
source venv-quietpaper/bin/activate
source venv3.9-quietpaper/bin/activate
while true ; do
PYTHONPATH=$here:$PYTHONPATH stdbuf -oL python3 quietpaper.py $@
PYTHONPATH=$here:$PYTHONPATH stdbuf -oL python3.9 quietpaper.py $@
done
exit $?
popd >/dev/null 2>&1
Expand Down
11 changes: 3 additions & 8 deletions quietpaper/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
)
from quietpaper.widgets.commute import (
CommuteWidget,
HafasCommuteStrategy
PyhafasCommuteStrategy
)
from quietpaper.widgets.room import RoomWidget
from quietpaper.widgets.smog import SmogWidget
Expand Down Expand Up @@ -61,15 +61,10 @@ def secret(key, default=""):
commute_y = 228
commute_hafas_glue = "http://localhost:3333/query"
commute_from_address = secret("QP_COMMUTE_FROM_ADDRESS")
commute_from_latitude = secret("QP_COMMUTE_FROM_LATITUDE")
commute_from_longitude = secret("QP_COMMUTE_FROM_LONGITUDE")
commute_to_address = secret("QP_COMMUTE_TO_ADDRESS")
commute_to_latitude = secret("QP_COMMUTE_TO_LATITUDE")
commute_to_longitude = secret("QP_COMMUTE_TO_LONGITUDE")
commute_bus_stations = secret("QP_COMMUTE_BUS_STATIONS")
commute_train_stations = secret("QP_COMMUTE_TRAIN_STATIONS")
commute_hafas = HafasCommuteStrategy(commute_hafas_glue, commute_from_address, commute_from_latitude, commute_from_longitude,
commute_to_address, commute_to_latitude, commute_to_longitude, commute_bus_stations, commute_train_stations)
commute_hafas = PyhafasCommuteStrategy(commute_from_address, commute_to_address, commute_bus_stations, commute_train_stations)
commute = CommuteWidget(commute_hafas, commute_leave_for_bus, commute_leave_for_train, commute_x, commute_y)

# Tado Connection
Expand Down Expand Up @@ -152,7 +147,7 @@ def secret(key, default=""):
secret("QP_LAUNDRY_DRYING_ACTIVE_POWER"))
laundry_x = 186
laundry_y = 22
laundry = LaundryWidget(laundry_x, laundry_y, washing_machine, drying_machine)
laundry = LaundryWidget(laundry_x, laundry_y, washing_machine, drying_machine, meross_connection)

# MockScreen
mock_png = "output/output.png"
Expand Down
Loading

0 comments on commit 6c97fd7

Please sign in to comment.