Skip to content
This repository has been archived by the owner on May 18, 2024. It is now read-only.

Commit

Permalink
Weather fixes plus more (#446)
Browse files Browse the repository at this point in the history
* Updated EC to use latest module.  Added rich module for better looking logging

* Updated OWM to use One Call 2.5 API. Added diskcache to store location and OWM curr obs

* Update apt requirements to allow for virtual env creation

* Add blacklist of sound module and also note of new python location to run commands

* update boot to enforce isolcpus=3

* Update aptfile

* Update requirements.txt

update RPi.GPIO requirements

* tweaks to install_venv for autoactivating venv

* more tweaks to install_venv

* Remove extra nhl-led-scoreboard directory that was create incorrectly

* Update apt-requirements

Typos

* Update install_venv.sh
  • Loading branch information
falkyre authored Feb 17, 2024
1 parent 652324f commit 026b479
Show file tree
Hide file tree
Showing 18 changed files with 415 additions and 150 deletions.
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.7.0
1.8.0
10 changes: 7 additions & 3 deletions apt-requirements
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,20 @@ update

# install some packages
package "build-essential"
package "libdbus-glib-1-dev"
package "libgirepository1.0-dev"
package "git"
package "python3-setuptools"
package "python3-pip"
package "python3-dev"
package "python3-virtualenv"
package "python3-pillow"
package "python3-numpy"
package "python3-gpiozero"
package "python3-cairosvg"
package "libatlas3-base"
package "python3-lxml"
package "libopenblas0"
package "libatlas-base-dev"
package "libraqm-dev"
package "direnv"
#For the issueUpload.sh
package "jq"
package "pastebinit"
Expand All @@ -26,6 +27,9 @@ package "neofetch"
package "zsh"
#For dietpi users without dbus
package "dbus"
package "libdbus-glib-1-dev"
package "libgirepository1.0-dev"
package "libdbus-1-dev"

# you can also execute arbitrary bash
echo "🚨 ALL GOOD TO GO"
1 change: 0 additions & 1 deletion nhl-led-scoreboard
Submodule nhl-led-scoreboard deleted from 333636
23 changes: 11 additions & 12 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,22 +1,21 @@
env-canada==0.0.35
ephem==3.7.7.0
env-canada
ephem
fastjsonschema>=2.14.4
geocoder==1.38.1
geocoder>=1.38.1
gpiozero==1.6.2
httpx==0.20.0
nhl-api-py
noaa-sdk>=0.1.18
printtools==1.2
PyInstaller==3.6
pyowm>=3.0.0
python-tsl2591==0.2.0
questionary==1.9.0
regex==2020.11.13
requests==2.22.0
RPi.GPIO==0.7.0
regex>=2020.4.4
RPi.GPIO>=0.7.1
APScheduler==3.10.4
lastversion>=1.1.6
nameparser==1.0.6
pillow
nameparser>=1.0.6
pillow>=9.5.0
dbus-python
iso6709
cairosvg
tzlocal
rich
diskcache
135 changes: 110 additions & 25 deletions scripts/aptfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#!/usr/bin/env bash
set -eo pipefail; [[ $TRACE ]] && set -x && export TRACE=$TRACE
set -eo pipefail
[[ $TRACE ]] && set -x && export TRACE=$TRACE

version() {
local VERSION="dev-master"
Expand Down Expand Up @@ -46,7 +47,8 @@ abs_dirname() {
}

expand_path() {
{ cd "$(dirname "$1")" 2>/dev/null
{
cd "$(dirname "$1")" 2>/dev/null
local dirname="$PWD"
cd "$OLDPWD"
echo "$dirname/$(basename "$1")"
Expand Down Expand Up @@ -74,18 +76,18 @@ done

for option in "${options[@]}"; do
case "$option" in
"h" | "help" )
help
exit 0
;;
"v" | "version" )
version
exit 0
;;
* )
usage >&2
exit 1
;;
"h" | "help")
help
exit 0
;;
"v" | "version")
version
exit 0
;;
*)
usage >&2
exit 1
;;
esac
done

Expand All @@ -98,12 +100,12 @@ if [ "${#arguments[@]}" -eq 0 ]; then
set -- "aptfile" "$@"
fi

export APTFILE_COLOR_OFF="\033[0m" # unsets color to term fg color
export APTFILE_RED="\033[0;31m" # red
export APTFILE_GREEN="\033[0;32m" # green
export APTFILE_YELLOW="\033[0;33m" # yellow
export APTFILE_MAGENTA="\033[0;35m" # magenta
export APTFILE_CYAN="\033[0;36m" # cyan
export APTFILE_COLOR_OFF="\033[0m" # unsets color to term fg color
export APTFILE_RED="\033[0;31m" # red
export APTFILE_GREEN="\033[0;32m" # green
export APTFILE_YELLOW="\033[0;33m" # yellow
export APTFILE_MAGENTA="\033[0;35m" # magenta
export APTFILE_CYAN="\033[0;36m" # cyan

logfile=$(basename "$0")
TMP_APTFILE_LOGFILE=$(mktemp "/tmp/${logfile}.XXXXXX") || {
Expand All @@ -127,20 +129,62 @@ log_info() {
update() {
[[ $TRACE ]] && set -x
log_info "Running update"
apt-get update > "$TMP_APTFILE_LOGFILE" 2>&1
apt-get update >"$TMP_APTFILE_LOGFILE" 2>&1
[[ $? -eq 0 ]] || log_fail "Failed to run update"
}

package() {
[[ $TRACE ]] && set -x
[[ -z $1 ]] && log_fail "Please specify a package to install"
local pkg="$1"
dpkg --force-confnew -s "$pkg" > "$TMP_APTFILE_LOGFILE" 2>&1 && log_info "${APTFILE_CYAN}[OK]${APTFILE_COLOR_OFF} package $pkg" && return 0
apt-get -o Dpkg::Options::="--force-confdef" -o Dpkg::Options::="--force-confnew" -qq -y --force-yes install "$pkg"
dpkg --force-confnew -s "$pkg" >"$TMP_APTFILE_LOGFILE" 2>&1 && log_info "${APTFILE_CYAN}[OK]${APTFILE_COLOR_OFF} package $pkg" && return 0
apt-get -o Dpkg::Options::="--force-confdef" -o Dpkg::Options::="--force-confnew" -qq -y install "$pkg"
[[ $? -eq 0 ]] || log_fail "${APTFILE_RED}[FAIL]${APTFILE_COLOR_OFF} package $pkg"
log_info "${APTFILE_GREEN}[NEW]${APTFILE_COLOR_OFF} package $pkg"
}

package_from_url() {
[[ $TRACE ]] && set -x
[[ -z $2 ]] && log_fail "Please specify a name and a download url to install the package from"
local name=$1
local url=$2
if type curl >/dev/null 2>&1; then
local dl_cmd="curl"
local dl_options="-so"
elif type wget >/dev/null 2>&1; then
local dl_cmd="wget"
local dl_options="-qO"
else
log_fail "Neither curl nor wget found. Unable to download $url"
fi
dpkg --force-confnew -s "$name" >"$TMP_APTFILE_LOGFILE" 2>&1 && log_info "${APTFILE_CYAN}[OK]${APTFILE_COLOR_OFF} package $name" && return 0
tempdir=$(mktemp -d)
$dl_cmd $dl_options $tempdir/${name}.deb $url \
&& apt-get -o Dpkg::Options::="--force-confdef" -o Dpkg::Options::="--force-confnew" -qq -y install "$tempdir/${name}.deb"
if [[ $? -ne 0 ]]; then
rm -r $tempdir
log_fail "${APTFILE_RED}[FAIL]${APTFILE_COLOR_OFF} package $name"
fi
rm -r $tempdir
log_info "${APTFILE_GREEN}[NEW]${APTFILE_COLOR_OFF} package $name"
}

packagelist() {
[[ $TRACE ]] && set -x
[[ -z $1 ]] && log_fail "Please specify at least one package to install"
local input_packages=$@
local install_packages=()
for pkg in $input_packages; do
dpkg --force-confnew -s "$pkg" >"$TMP_APTFILE_LOGFILE" 2>&1 && log_info "${APTFILE_CYAN}[OK]${APTFILE_COLOR_OFF} package $pkg" && continue
install_packages+=($pkg)
done
if [[ ${#install_packages[@]} -gt 0 ]]; then
apt-get -o Dpkg::Options::="--force-confdef" -o Dpkg::Options::="--force-confnew" -qq -y install ${install_packages[@]}
[[ $? -eq 0 ]] || log_fail "${APTFILE_RED}[FAIL]${APTFILE_COLOR_OFF} packages ${install_packages[@]}"
log_info "${APTFILE_GREEN}[NEW]${APTFILE_COLOR_OFF} packages ${install_packages[@]}"
fi
}

ppa() {
[[ $TRACE ]] && set -x
[[ -z $1 ]] && log_fail "Please specify a repository to setup"
Expand All @@ -158,7 +202,45 @@ repository() {
if [[ -d /etc/apt/sources.list.d/ ]]; then
grep ^ /etc/apt/sources.list /etc/apt/sources.list.d/* | grep -Fq "$repo" && log_info "${APTFILE_CYAN}[OK]${APTFILE_COLOR_OFF} repository $repo" && return 0
fi
add-apt-repository -y "$repo" > "$TMP_APTFILE_LOGFILE" 2>&1
add-apt-repository -y "$repo" >"$TMP_APTFILE_LOGFILE" 2>&1
[[ $? -eq 0 ]] || log_fail "${APTFILE_RED}[FAIL]${APTFILE_COLOR_OFF} repository $pkg"
update
log_info "${APTFILE_GREEN}[NEW]${APTFILE_COLOR_OFF} repository $repo"
}

repository_file() {
[[ $TRACE ]] && set -x
[[ -z $2 ]] && log_fail "Please specify a filename and sourceline to setup"
local repofile="$1"
local repo="$2"
# sourceline is not a complete repo configuration, needs modifying
# i.e. not sourceline="deb http://domain.invalid/debian buster main extra"
if [[ "$repo" != "deb "* ]]; then
releasename=$(lsb_release -sc)
if [[ "$repo" == *" "* ]]; then
# Components given in sourceline, adding suite
# i.e. sourceline="http://domain.invalid/debian main"
repo="deb ${repo/ / $releasename }"
else
# only URL given, adding suite and component
# i.e. sourceline="http://domain.invalid/debian"
repo="deb ${repo} $releasename main"
fi
fi

if [[ "$repofile" != *.list ]]; then
# Adding extension to enable parsing file
repofile=${repofile}.list
fi
# Adding path
repofile="/etc/apt/sources.list.d/$repofile"

[[ -d "/etc/apt/sources.list.d" ]] || mkdir -p /etc/apt/sources.list.d

grep ^ /etc/apt/sources.list /etc/apt/sources.list.d/* | grep -Fq "$repo" && log_info "${APTFILE_CYAN}[OK]${APTFILE_COLOR_OFF} repository $repo" && return 0

echo "Writing '$repo' to file '$repofile'" >"$TMP_APTFILE_LOGFILE"
echo "$repo" >"$repofile" 2>>"$TMP_APTFILE_LOGFILE"
[[ $? -eq 0 ]] || log_fail "${APTFILE_RED}[FAIL]${APTFILE_COLOR_OFF} repository $pkg"
update
log_info "${APTFILE_GREEN}[NEW]${APTFILE_COLOR_OFF} repository $repo"
Expand All @@ -183,7 +265,7 @@ APTFILE_TMPNAME="$APTFILE_TMPDIR/aptfile.$$"
APTFILE_OUTPUT="${APTFILE_TMPNAME}.out"

aptfile_preprocess_source() {
tail -n +2 "$1" > "$APTFILE_OUTPUT"
tail -n +2 "$1" >"$APTFILE_OUTPUT"
trap "aptfile_cleanup_preprocessed_source" err exit
trap "aptfile_cleanup_preprocessed_source; exit 1" int
}
Expand All @@ -197,8 +279,11 @@ aptfile_preprocess_source "$APTFILE_INPUT"

export -f update
export -f package
export -f package_from_url
export -f packagelist
export -f ppa
export -f repository
export -f repository_file
export -f debconf_selection
export -f log_fail
export -f log_info
Expand Down
112 changes: 112 additions & 0 deletions scripts/install_venv.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
#!/bin/bash

# Make script work regardless of where it is run from
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
cd "${DIR}/.." || exit

tput bold; echo "$(tput setaf 2)Installing required OS dependencies. This may take some time (10-20 minutes-ish)...$(tput setaf 9)" ; tput sgr0

#Install all apt requirements using aptfile
sudo scripts/aptfile apt-requirements

tput bold; echo "$(tput setaf 2)Creating python virtual environment...$(tput setaf 9)" ; tput sgr0

#Install all apt requirements using aptfile
#sudo scripts/aptfile apt-requirements

# Update system pip3 to latest version
python3 -m pip install --upgrade pip --break-system-packages

# Install virtual enviroment, required for upcoming bookworm release
# Use already installed site-packages that were installed as part o fthe apt OS dependencies
python3 -m venv $HOME/nhlsb-venv --system-site-packages

# Activate the direnv to allow for automatic activate and deactivate of venv
tput bold; echo "$(tput setaf 2)Activating direnv for python venv...$(tput setaf 9)" ; tput sgr0

echo "export VIRTUAL_ENV=~/nhlsb-venv" >> .envrc
echo "source ~/nhlsb-venv/bin/activate" >> .envrc
direnv allow .

# Update bashrc
tee -a ~/.bashrc << 'TEXT0'
show_virtual_env() {
if [[ -n "$VIRTUAL_ENV" && -n "$DIRENV_DIR" ]]; then
echo "($(basename $VIRTUAL_ENV)) "
fi
}
export -f show_virtual_env
PS1='$(show_virtual_env)'$PS1
eval "$(direnv hook bash)"
TEXT0

echo "$(tput setaf 6)Activating python virtual environment...$(tput setaf 9)"

source $HOME/nhlsb-venv/bin/activate

echo "$(tput setaf 6)Updating pip in virtual environment...$(tput setaf 9)"
# Update pip in the virtual enviroment
python3 -m pip install --upgrade pip
#Install all pip3 requirements using the requirements.txt file
#This will install into the virtual environment

tput bold; echo "$(tput setaf 2)Installing scoreboard python requirements in virtual environment...$(tput setaf 9)" ; tput sgr0
pip3 install -r requirements.txt

# Pull submodule and ignore changes from script
git submodule update --init --recursive
git config submodule.matrix.ignore all

tput bold; echo "$(tput setaf 4)Running rgbmatrix installation...$(tput setaf 9)" ; tput sgr0

# No longer needed for newer version of the rgb matric repo as of Dec 2021
# Recompile the cpp files to build library with newest cython. See https://github.com/hzeller/rpi-rgb-led-matrix/issues/1298

cd submodules/matrix/ || exit

# python3 -m pip install --no-cache-dir cython
# python3 -m cython -2 --cplus *.pyx

# cd ../../ || exit

make build-python PYTHON="$(command -v python3)"
make install-python PYTHON="$(command -v python3)"

cd ../../ || exit

# Blacklist the snd_bcm2835 sounds module
sudo tee /etc/modprobe.d/blacklist-rgbmatrix.conf <<TEXT1
## Make sure the sound module does not load as it causes issues with the timing for the rgb matrix library
blacklist snd_bcm2835
# The next time the loading of the module is attempted, the /bin/false
# will be executed instead. This will prevent the module from being
# loaded on-demand.
install snd_bcm_2835 /bin/false
TEXT1

# Unload the sound module
sudo modprobe -r snd_bcm2835

# Rebuild module dependacy
sudo depmod -a

sudo sed -i 's/$/ isolcpus=3/' /boot/cmdline.txt

git reset --hard
git fetch origin --prune
git pull

tput bold; echo "$(tput setaf 6)If you didn't see any errors above, everything should be installed!"; tput sgr0
echo "$(tput bold)$(tput smso)$(tput setaf 2)Installation complete!$(tput sgr0) Play around with the examples in nhl-led-scoreboard/submodules/matrix/bindings/python/samples to make sure your matrix is working."
tput bold; echo "$(tput setaf 4)...................................................$(tput setaf 9)" ; tput sgr0
tput bold; echo "$(tput setaf 4)TAKE NOTE OF NEXT LINES...$(tput setaf 9)" ; tput sgr0
tput bold; echo "$(tput setaf 4)WITh A VENV, Your python is now located differently...$(tput setaf 9)" ; tput sgr0
tput bold; echo "$(tput setaf 4)TO RUN WITH SUDO, YOU MUST USE THE VENV LOCATION...$(tput setaf 9)" ; tput sgr0
tput bold; echo "$(tput setaf 4).................PYTHON LOOKS LIKE.....................$(tput setaf 9)" ; tput sgr0
tput bold; echo "$(tput setaf 1)sudo $HOME/nhlsb-venv/bin/python3 $(tput setaf 9)" ; tput sgr0
tput bold; echo "$(tput setaf 4)...................................................$(tput setaf 9)" ; tput sgr0
1 change: 1 addition & 0 deletions src/api/weather/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ The name of the board that can be added to the different states is : **weather**
| scroll\_alert | Bool | true,false | Scroll the text of the alert on the initial alert page. If you select false, a static page will be displayed that is the same as the 4th page on the weather board |
| alert\_duration | INT | 5 | How long to show alert board (in seconds). This is for the non-scrolling alert board. |
| show\_on\_clock | Bool | true,false | Add the last observed temperature and humidity to the bottom of the clock board |
| view | String | full, summary | Weather board full (3 page) or summary view (1 page) |

> ***NOTE*** When you register for an OWM API key, it can take up to a day before it is activated. Select the Current Weather Data one as that's what the pyowm library uses. Also, you are limited on the number of API calls you can make, so choose your update time accordingly. 5 minutes makes the most sense as the lowest amonunt of time you can do API calls.
Expand Down
Loading

0 comments on commit 026b479

Please sign in to comment.