So, basically I have a device setup that when I go to a specific IP:port address it is running a server that gives JSON info.
What do I do to make a device handler for this device? Do I need to make a smartapp as well?
Obviously code written in groovy on my computer isn’t directly transferable to smartthings, but I have tested it and it works.
Here is the code I can run on my computer and it works fine this way, but I am having trouble figuring out how to make a GET request for the JSON data in smartthings.
//import
import groovy.json.JsonSlurper
//print the url to get full JSON data
//println "http://192.168.2.127:3003/getData?authToken=vhbyvw".toURL().text;
def i = 100
//Timer
Thread y = new Thread();
try{
while(i>0)
{
def jsonSlurper = new JsonSlurper()
def object = jsonSlurper.parseText('http://192.168.2.127:3003/getData?authToken=vhbyvw'.toURL().text)
//print the light sensor data
println"Light Sensor: "+object.lightValue
String movement = object.movement
//check if motion is false and print false and also print correct temp data
if(movement=="false"){
println"No Motion"
}
// check if the motion is true and print true and also print correct temp data
if(movement=="true"){
println"Motion"
}
println (object.temperature+" F")
//timer run for 1 second
y.sleep(1000)
i--
}
}catch(ConnectException ex){
println "Caught ConnectException, check that turned on and developer mode is active"
}
I have been trying to figure this out for almost a week and I just feel like I am getting lost. Any help or pointers is greatly appreciated.