This repository was archived by the owner on Sep 30, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 17
Expand file tree
/
Copy pathled.sh
More file actions
61 lines (53 loc) · 1.32 KB
/
led.sh
File metadata and controls
61 lines (53 loc) · 1.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#!/bin/bash
# This is the bash script that will be run on the echo
# It will receive the value from the remote server, any of the following:
#
# - "mics-off_on"
# - "mics-off_start"
# - "mics-off_end"
# - "error"
# - "off"
# - "solid_blue"
# - "solid_cyan"
# - "solid_green"
# - "solid_orange"
# - "solid_red"
# - "solid_white
# - "zzz_disco"
# - "zzz_rainbow"
# - "zzz_turbo-boost"
HOST="http://192.168.1.81" # Replace with the local IP of the machine running the server script.
LAST_RESPONSE=""
send_request() {
local response
response=$(/data/local/tmp/curl -sSL "$HOST/led") # Capture the response output
# Compare with the previous response
if [[ "$response" != "$LAST_RESPONSE" ]]; then
# Print the response body only if it's different from the last one
ledctrl -c
ledctrl -s $response
LAST_RESPONSE="$response" # Update the last response
fi
local status_code=$?
return $status_code
}
handle_unsuccessful_req() {
while true; do
send_request
status_code=$?
if [[ $status_code -eq 0 ]]; then
break
else
sleep 30
fi
done
}
while true; do
send_request
status_code=$?
if [[ $status_code -ne 0 ]]; then
echo "Request failed. Retrying..."
handle_unsuccessful_req
fi
sleep 5
done