Here's a quick snippet to use SS to control an Openshock/shocklink shocker. CC-BY-SA-NC
Code:
//
// copy this into any script
//
//==================================================================
final send_post = { _host, _data, _token ->
final post = new URL(_host).openConnection();
post.setRequestMethod("POST")
post.setDoOutput(true)
post.setRequestProperty("Content-Type", "application/json")
post.setRequestProperty("OpenShockToken", _token)
post.getOutputStream().write(_data.getBytes("UTF-8"));
final postRC = post.getResponseCode();
if(postRC.equals(200)) {
final text = post.getInputStream().getText("UTF-8")
final jsonSlurper = new groovy.json.JsonSlurper()
try {
final object = jsonSlurper.parseText(text)
return object
} catch (Exception ex) {
show(ex)
}
}
else
{
show("Openshock error")
wait(1)
}
return false
}
final send_shock = { _intensity, _duration ->
def shocker_id = loadString("openshock.shocker_id")
def token = loadString("openshock.token")
//TODO check if id or token are valid
def host = "hxxps-api-shocklink-net/2/shockers/control"
// def data = "{\"shocks\":[{\"id\": \"$shocker_id\",\"type\": \"Vibrate\",\"intensity\": $_intensity,\"duration\": $_duration,\"exclusive\": true}],\"customName\": \"string\"}"
def data = "{\"shocks\":[{\"id\": \"$shocker_id\",\"type\": \"Shock\",\"intensity\": $_intensity,\"duration\": $_duration,\"exclusive\": true}],\"customName\": \"string\"}"
send_post(host, data, token)
}
//==================================================================
//
Code:
final set_token = { _token ->
save("openshock.token", _token)
}
final set_shocker_id = { _id->
save("openshock.shocker_id", _id)
}
final test = { ->
send_shock(10,300)
}
def selection=0
while(selection != 3) {
selection = getSelectedValue("Select option",["Set token", "Set id", "Test", "Exit"])
if(selection==0) {
set_token(getString("New value?", ""))
}
else if(selection==1) {
set_shocker_id(getString("New value?", ""))
}
else if(selection==2){
test()
}
}
api url must be fixed because of forum limitations
Very bare bones and I haven't taken the effort to integrate it in scripts like Shock Yourself. Interested to see what this will lead to.