You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
#!/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.
The text was updated successfully, but these errors were encountered:
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.
then, this is working for me
then just save the file using CTRL-X then 'y' and 'enter' to save.
The text was updated successfully, but these errors were encountered: