Skip to content

Commit

Permalink
Use the Wink API to control IOT enabled devices
Browse files Browse the repository at this point in the history
  • Loading branch information
Shawn Woodford committed Jul 11, 2015
1 parent aa690c3 commit 1796ddc
Show file tree
Hide file tree
Showing 3 changed files with 96 additions and 14 deletions.
16 changes: 3 additions & 13 deletions LICENSE
Original file line number Diff line number Diff line change
Expand Up @@ -174,19 +174,9 @@
of your accepting any such warranty or additional liability.

END OF TERMS AND CONDITIONS

APPENDIX: How to apply the Apache License to your work.

To apply the Apache License to your work, attach the following
boilerplate notice, with the fields enclosed by brackets "{}"
replaced with your own identifying information. (Don't include
the brackets!) The text should be enclosed in the appropriate
comment syntax for the file format. We also recommend that a
file or class name and description of purpose be included on the
same "printed page" as the copyright notice for easier
identification within third-party archives.

Copyright {yyyy} {name of copyright owner}

Copyright 2015 Shawn Woodford
https://github.com/swoodford

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,6 @@
# wink
wink
=======

Wink API tools

- **wink.sh** Use the Wink API to control IOT enabled devices
88 changes: 88 additions & 0 deletions wink.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
#!/usr/bin/env bash
# This script uses the Wink API to control IOT enabled devices

# Set Required Variables
client_id="consumer_key_goes_here"
client_secret="consumer_secret_goes_here"
username="user@example.com"
password="password_goes_here"
APIURL="https://winkapi.quirky.com/"

# Functions
function check_command {
type -P $1 &>/dev/null || fail "Unable to find $1, please install it and run this script again."
}

function fail(){
tput setaf 1; echo "Failure: $*" && tput sgr0
exit 1
}

function getToken(){
getToken=$(curl -sX POST "$APIURL"oauth2/token \
-H "Content-Type: application/json" \
-d '
{
"client_id": "'"$client_id"'",
"client_secret": "'"$client_secret"'",
"username": "'"$username"'",
"password": "'"$password"'",
"grant_type": "password"
} ')

# echo $getToken | jq .

access_token=$(echo $getToken | jq '.access_token' | cut -d '"' -f 2)
# echo $access_token
# refresh_token=$(echo $getToken | jq '.refresh_token' | cut -d '"' -f 2)
# echo $refresh_token
}

function linkedServices(){
linkedServices=$(curl -s "$APIURL"/users/me/linked_services \
-H "Authorization: Bearer $access_token")

echo $linkedServices | jq .
}

function retrieveAllDevices(){
retrieveAllDevices=$(curl -s "$APIURL"/users/me/wink_devices \
-H "Authorization: Bearer $access_token")

echo $retrieveAllDevices | jq .
}

function getRobots(){
getRobots=$(curl -s "$APIURL"/users/me/robots \
-H "Authorization: Bearer $access_token")

echo $getRobots | jq .
}

# Turn a light bulb on or off and set brightness level
function updateDevice(){
updateDevice=$(curl -vX PUT "$APIURL"/"$1"/"$2" \
-H "Authorization: Bearer $access_token" \
-H "Content-Type: application/json" \
--data-binary '{
"desired_state": {
"powered": "'"$3"'",
"brightness": "1.00"
}
}')

echo $updateDevice | jq .
}

# Check required commands
check_command "jq"

# Get Token
getToken

# List all your devices
retrieveAllDevices

# Do Something - Turn on a lightbulb
updateDevice light_bulbs {your_lightbulb_id_000000} true

0 comments on commit 1796ddc

Please sign in to comment.