Update QuecManager Beta to 1.0.5

- Improved signal metrics script so that it will not overlap with data usage that also uses smd7
- Improved signal metrics refresh speed to 15 seconds
- Fixed speedtest get logic that causes a bug when using tailscale
- Improved signal metrics refresh animation

Co-Authored-By: Russel Yasol <73575327+dr-dolomite@users.noreply.github.com>
This commit is contained in:
Cameron Thompson
2024-12-18 23:35:25 -05:00
parent 0298242849
commit df6b4114a8
44 changed files with 98 additions and 44 deletions

View File

@@ -1,17 +1,22 @@
#!/bin/sh
# Ensure the directory exists
LOGDIR="/tmp/signal_graphs"
mkdir -p "$LOGDIR"
# Maximum number of entries
MAX_ENTRIES=10
# Interval between logs (in seconds)
INTERVAL=25
# Function to clean and extract actual output from atinout
clean_atinout_output() {
# Remove first line (echoed command), last line (OK), and trim whitespace
sed -n '2,/^OK$/p' | sed '$d' | tr -d '\r' | xargs
}
# Function to log signal metrics
# Function to log signal metric
log_signal_metric() {
local COMMAND="$1"
local FILENAME="$2"
@@ -40,21 +45,60 @@ log_signal_metric() {
--arg output "$ESCAPED_OUTPUT" \
'
# Ensure the input is always an array
if type == "array" then .
else []
if type == "array" then .
else []
end |
# Add new entry
. + [{"datetime": $datetime, "output": $output}] |
. + [{"datetime": $datetime, "output": $output}] |
# Trim to max entries
.[-'"$MAX_ENTRIES"':]
' "$LOGFILE" > "${LOGFILE}.tmp" && mv "${LOGFILE}.tmp" "$LOGFILE"
}
# Function to log data usage
log_data_usage() {
local LOGFILE="$LOGDIR/data_usage.json"
# Ensure log directory exists
mkdir -p "$(dirname "$LOGFILE")"
# Get current timestamp
TIMESTAMP=$(date "+%Y-%m-%d %H:%M:%S")
# Run the AT command and capture its output, then clean it
DATA_OUTPUT=$(echo "AT+QGDCNT?;+QGDNRCNT?" | atinout - /dev/smd7 - | clean_atinout_output)
# Ensure the file exists and is a valid JSON array
if [ ! -s "$LOGFILE" ]; then
echo "[]" > "$LOGFILE"
fi
# Prepare new JSON entry
ESCAPED_TIMESTAMP=$(printf '%s' "$TIMESTAMP" | sed 's/"/\\"/g')
ESCAPED_OUTPUT=$(printf '%s' "$DATA_OUTPUT" | sed 's/"/\\"/g')
# Use jq with a more robust approach
jq --arg datetime "$ESCAPED_TIMESTAMP" \
--arg output "$ESCAPED_OUTPUT" \
'
# Ensure the input is always an array
if type == "array" then .
else []
end |
# Add new entry
. + [{"datetime": $datetime, "output": $output}] |
# Trim to max entries
.[-'"$MAX_ENTRIES"':]
' "$LOGFILE" > "${LOGFILE}.tmp" && mv "${LOGFILE}.tmp" "$LOGFILE"
}
# Trap to handle script termination gracefully
cleanup() {
echo "Stopping signal logging..."
exit 0
}
trap cleanup SIGINT SIGTERM
# Continuous logging loop
echo "Starting continuous signal metrics logging (Press Ctrl+C to stop)..."
while true; do
@@ -64,6 +108,8 @@ while true; do
log_signal_metric "AT+QRSRQ" "rsrq.json"
# Log SINR
log_signal_metric "AT+QSINR" "sinr.json"
# Log data usage after signal stats
log_data_usage
# Wait for the specified interval
sleep "$INTERVAL"
done