Removed dependency on curls "--json" flag.
This commit is contained in:
parent
39323d772a
commit
c66362f87d
2 changed files with 16 additions and 10 deletions
|
@ -19,6 +19,5 @@ Change brightness:
|
||||||
|
|
||||||
## Requirements
|
## Requirements
|
||||||
|
|
||||||
*curl* version 7.82.0 or newer.
|
|
||||||
You have to be connected to the local network.
|
You have to be connected to the local network.
|
||||||
|
|
||||||
|
|
25
wled
25
wled
|
@ -31,14 +31,21 @@ commands:
|
||||||
-b,--brightness [1-255] set brightness"
|
-b,--brightness [1-255] set brightness"
|
||||||
}
|
}
|
||||||
|
|
||||||
curl_cmd() {
|
curl_fetch() {
|
||||||
curl --silent --show-error --fail --ipv4 --max-filesize 32K "$@"
|
curl --silent --show-error --fail --ipv4 --max-filesize 32768 \
|
||||||
|
--max-redirs 0 --header 'Accept: application/json' "$@"
|
||||||
|
}
|
||||||
|
|
||||||
|
curl_send() {
|
||||||
|
curl --silent --show-error --fail --ipv4 --max-filesize 1024 \
|
||||||
|
--max-redirs 0 --header 'Accept: application/json' \
|
||||||
|
--header 'Content-Type: application/json' "$@"
|
||||||
}
|
}
|
||||||
|
|
||||||
active_preset() {
|
active_preset() {
|
||||||
# Find number of active preset. API returns -1 if none is active, we return
|
# Find number of active preset. API returns -1 if none is active, we return
|
||||||
# an empty string.
|
# an empty string.
|
||||||
curl_cmd "http://$1/json" | \
|
curl_fetch "http://$1/json" | \
|
||||||
# -1 will be a no-match.
|
# -1 will be a no-match.
|
||||||
sed -n 's/.*"ps"[[:space:]]*:[[:space:]]*\(1\?[0-9]\).*/\1/p'
|
sed -n 's/.*"ps"[[:space:]]*:[[:space:]]*\(1\?[0-9]\).*/\1/p'
|
||||||
}
|
}
|
||||||
|
@ -69,10 +76,10 @@ esac
|
||||||
# Parse and execute command argument.
|
# Parse and execute command argument.
|
||||||
case "$2" in
|
case "$2" in
|
||||||
on) # Switch on.
|
on) # Switch on.
|
||||||
api_resp=$(curl_cmd --json '{"on":true}' "http://$wled_host/json")
|
api_resp=$(curl_send --data '{"on":true}' "http://$wled_host/json")
|
||||||
;;
|
;;
|
||||||
off) # Switch off.
|
off) # Switch off.
|
||||||
api_resp=$(curl_cmd --json '{"on":false}' "http://$wled_host/json")
|
api_resp=$(curl_send --data '{"on":false}' "http://$wled_host/json")
|
||||||
;;
|
;;
|
||||||
-b|--brightness) # Set brightness.
|
-b|--brightness) # Set brightness.
|
||||||
if test -z "$3"; then
|
if test -z "$3"; then
|
||||||
|
@ -88,15 +95,15 @@ case "$2" in
|
||||||
echo "Error: parameter for brightness is out of range." >&2
|
echo "Error: parameter for brightness is out of range." >&2
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
api_resp=$(curl_cmd --json "{'bri':$bright}" "http://$wled_host/json")
|
api_resp=$(curl_send --data "{'bri':$bright}" "http://$wled_host/json")
|
||||||
;;
|
;;
|
||||||
[1-9]|1[0-7]) # Switch to preset.
|
[1-9]|1[0-7]) # Switch to preset.
|
||||||
api_resp=$(curl_cmd --json "{'ps':$2}" "http://$wled_host/json")
|
api_resp=$(curl_send --data "{'ps':$2}" "http://$wled_host/json")
|
||||||
;;
|
;;
|
||||||
l|list) # List presets.
|
l|list) # List presets.
|
||||||
printf "loading ...\r"
|
printf "loading ...\r"
|
||||||
active_ps=$(active_preset "$wled_host")
|
active_ps=$(active_preset "$wled_host")
|
||||||
curl_cmd "http://$wled_host/presets.json" | \
|
curl_fetch "http://$wled_host/presets.json" | \
|
||||||
# Split into lines - one line per preset.
|
# Split into lines - one line per preset.
|
||||||
sed --sandbox 's/"1\?[0-9]"[[:space:]]*:/\n&/g' | \
|
sed --sandbox 's/"1\?[0-9]"[[:space:]]*:/\n&/g' | \
|
||||||
# Extract number and name of every preset. Right-align numbers.
|
# Extract number and name of every preset. Right-align numbers.
|
||||||
|
@ -115,7 +122,7 @@ case "$2" in
|
||||||
exit $?
|
exit $?
|
||||||
;;
|
;;
|
||||||
dump) # Dump JSON response from API.
|
dump) # Dump JSON response from API.
|
||||||
curl_cmd -w '\n' "http://$wled_host/json"
|
curl_fetch -w '\n' "http://$wled_host/json"
|
||||||
exit 0
|
exit 0
|
||||||
;;
|
;;
|
||||||
"") # Missing command.
|
"") # Missing command.
|
||||||
|
|
Loading…
Reference in a new issue