add watch scripts
This commit is contained in:
parent
e623e599d5
commit
ab9e90cb20
1
scripts/watch-in-signle-line.sh
Normal file
1
scripts/watch-in-signle-line.sh
Normal file
@ -0,0 +1 @@
|
|||||||
|
curl -s https://mercury.segin.one/sensor | jq -r '"🌡️ \(.temperature)°C 💧 \(.humidity)%"'
|
||||||
30
scripts/watch-sensor.sh
Executable file
30
scripts/watch-sensor.sh
Executable file
@ -0,0 +1,30 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
while true; do
|
||||||
|
# Fetch API response
|
||||||
|
response=$(curl -s https://mercury.segin.one/sensor)
|
||||||
|
temperature=$(echo "$response" | jq -r '.temperature')
|
||||||
|
humidity=$(echo "$response" | jq -r '.humidity')
|
||||||
|
timestamp=$(echo "$response" | jq -r '.timestamp')
|
||||||
|
formatted_time=$(date -d @$((timestamp / 1000)))
|
||||||
|
|
||||||
|
# Calculate "seconds ago"
|
||||||
|
current_time=$(date +%s)
|
||||||
|
timestamp_seconds=$((timestamp / 1000))
|
||||||
|
time_diff=$((current_time - timestamp_seconds))
|
||||||
|
|
||||||
|
# Format time difference
|
||||||
|
if [ "$time_diff" -lt 60 ]; then
|
||||||
|
time_ago="${time_diff} seconds ago"
|
||||||
|
else
|
||||||
|
time_ago="$((time_diff / 60)) minutes ago"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Clear screen and print results
|
||||||
|
clear
|
||||||
|
echo "🌡️ Temperature: ${temperature}°C"
|
||||||
|
echo "💧 Humidity: ${humidity}%"
|
||||||
|
echo "🕒 Timestamp: ${formatted_time}"
|
||||||
|
echo "🕒 Data fetched: ${time_ago}"
|
||||||
|
sleep 1
|
||||||
|
done
|
||||||
Loading…
Reference in New Issue
Block a user