Files
quectel-rgmii-toolkit/ipk-source/sdxpinn-quecmanager-beta/root/www/cgi-bin/home/log_signal_metrics.sh
Cameron Thompson 007b268b03 QuecManager BETA 1.0.7
- Resolved SMS Inbox Display Issue: Fixed a bug preventing messages from being displayed in the SMS inbox.

- Enhanced SMS Inbox Functionality: Optimized the SMS inbox to group messages with the same sender and timestamp.

- Corrected Signal Metrics Calculation: Addressed inaccuracies in the calculation of signal metrics.

- Updated Speedtest Cooldown: Increased the cooldown period for speed tests from 5 seconds to 10 seconds.

- Improved Speedtest Cleanup: Ensured the pipe is removed automatically after the speed test completes.

- Updated to NextJS 15

- Improved Quecwatch script

Co-Authored-By: Russel Yasol <73575327+dr-dolomite@users.noreply.github.com>
2024-12-22 13:12:20 -05:00

115 lines
3.3 KiB
Bash
Executable File

#!/bin/sh
# Ensure the directory exists
LOGDIR="/www/signal_graphs"
mkdir -p "$LOGDIR"
# Maximum number of entries
MAX_ENTRIES=10
# Interval between logs (in seconds)
INTERVAL=15
# 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 metric
log_signal_metric() {
local COMMAND="$1"
local FILENAME="$2"
local LOGFILE="$LOGDIR/$FILENAME"
# 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
SIGNAL_OUTPUT=$(echo "$COMMAND" | 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' "$SIGNAL_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"
}
# 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
# Log RSRP
log_signal_metric "AT+QRSRP" "rsrp.json"
# Log RSRQ
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