add watch scripts

This commit is contained in:
Halit Aksoy 2025-01-19 18:17:37 +03:00
parent e623e599d5
commit ab9e90cb20
2 changed files with 31 additions and 0 deletions

View File

@ -0,0 +1 @@
curl -s https://mercury.segin.one/sensor | jq -r '"🌡️ \(.temperature)°C 💧 \(.humidity)%"'

30
scripts/watch-sensor.sh Executable file
View 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