Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MODULE: addition of raspberry pi temperature display #23

Open
flewid opened this issue Oct 24, 2024 · 0 comments
Open

MODULE: addition of raspberry pi temperature display #23

flewid opened this issue Oct 24, 2024 · 0 comments

Comments

@flewid
Copy link

flewid commented Oct 24, 2024

I wanted to display the temperature of the cpu on the rpi 4b, and lm-sensors doesn't work obviously, so here is the file I created. If it's under 75C it prints in green, otherwise it prints in red.

# touch ./modules/29-rpi-temp
# chmod +x ./moduls/29-rpi-temp 
# nano ./modules/29-rpi-temp 

then, this is working for me

#!/usr/bin/env bash

set -euo pipefail
# shellcheck source=./framework.sh
source "${BASE_DIR}/framework.sh"

# Define color codes
RED="\033[0;31m"
GREEN="\033[0;32m"
NC="\033[0m" # No color

temp_rpi() {
    local cpu_temp
    cpu_temp=$(vcgencmd measure_temp | sed "s/temp=//; s/'/°/")
    echo "${cpu_temp}"
}

# Extract numeric temperature value from the formatted temperature string
get_temp_value() {
    local temp_str="$1"
    echo "${temp_str}" | sed "s/[^0-9.]//g"  # Strip everything except numbers and decimals
}

cpu_temp=$(temp_rpi)  # Call the function to get the CPU temp (e.g., "57.9°C")
temp_value=$(get_temp_value "$cpu_temp")  # Extract numeric part (e.g., "57.9")

# Determine color based on the temperature value
if (( $(echo "$temp_value > 75" | bc -l) )); then
    color="${RED}"
else
    color="${GREEN}"
fi

# Print using the framework's print_columns
print_columns "CPU Temp" "${color}${cpu_temp}${NC}"

then just save the file using CTRL-X then 'y' and 'enter' to save.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant