Skip to content

Instantly share code, notes, and snippets.

@LutfiTekin
Created September 30, 2021 09:46
Show Gist options
  • Save LutfiTekin/fe0ffa361232d989ca072a90aadd0452 to your computer and use it in GitHub Desktop.
Save LutfiTekin/fe0ffa361232d989ca072a90aadd0452 to your computer and use it in GitHub Desktop.
Control Lights with Gradle Build
//under project level gradle
classpath 'org.codehaus.groovy.modules.http-builder:http-builder:0.5.2'
//app level gradle under android {}
def put = new URL("http://[hue bridge ip]/api/[hue username key]/lights/[light number]/state").openConnection();
def message = '{"on": true,"xy":[0.400,0.922]}'
put.setRequestMethod("PUT")
put.setDoOutput(true)
put.setRequestProperty("Content-Type", "application/json")
put.getOutputStream().write(message.getBytes("UTF-8"))
def postRC = put.getResponseCode()
println(postRC)
if(postRC.toString().equals("200")) {
println(put.getInputStream().getText())
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment