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
|
||||
|
||||
*curl* version 7.82.0 or newer.
|
||||
You have to be connected to the local network.
|
||||
|
||||
|
|
25
wled
25
wled
|
@ -31,14 +31,21 @@ commands:
|
|||
-b,--brightness [1-255] set brightness"
|
||||
}
|
||||
|
||||
curl_cmd() {
|
||||
curl --silent --show-error --fail --ipv4 --max-filesize 32K "$@"
|
||||
curl_fetch() {
|
||||
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() {
|
||||
# Find number of active preset. API returns -1 if none is active, we return
|
||||
# an empty string.
|
||||
curl_cmd "http://$1/json" | \
|
||||
curl_fetch "http://$1/json" | \
|
||||
# -1 will be a no-match.
|
||||
sed -n 's/.*"ps"[[:space:]]*:[[:space:]]*\(1\?[0-9]\).*/\1/p'
|
||||
}
|
||||
|
@ -69,10 +76,10 @@ esac
|
|||
# Parse and execute command argument.
|
||||
case "$2" in
|
||||
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.
|
||||
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.
|
||||
if test -z "$3"; then
|
||||
|
@ -88,15 +95,15 @@ case "$2" in
|
|||
echo "Error: parameter for brightness is out of range." >&2
|
||||
exit 1
|
||||
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.
|
||||
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.
|
||||
printf "loading ...\r"
|
||||
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.
|
||||
sed --sandbox 's/"1\?[0-9]"[[:space:]]*:/\n&/g' | \
|
||||
# Extract number and name of every preset. Right-align numbers.
|
||||
|
@ -115,7 +122,7 @@ case "$2" in
|
|||
exit $?
|
||||
;;
|
||||
dump) # Dump JSON response from API.
|
||||
curl_cmd -w '\n' "http://$wled_host/json"
|
||||
curl_fetch -w '\n' "http://$wled_host/json"
|
||||
exit 0
|
||||
;;
|
||||
"") # Missing command.
|
||||
|
|
Loading…
Reference in a new issue