Hi, I have been trying to do the same thing, blinking an led on the particle photon using smartthings app. But I keep getting the following error in the Smartthings IDE simulator:
groovyx.net.http.HttpResponseException: Unauthorized @line -1 (off)
I put in my access token and device ID into the device that I created under My Devices. So I am uncertain as to why I get the unauthorized error. Could it just mean my access token is wrong?
Here is my particle photon code:
int ledToggle(String command);
int led = D7;
void setup()
{
Particle.function("ledstate", ledToggle);
pinMode(led, OUTPUT);
}
void loop()
{}
int ledToggle(String command)
{
if (command == "1") {
digitalWrite(led, HIGH);
return 1;
} else {
digitalWrite(led, LOW);
return 0;
}
}`
Here is my device handler code
preferences {
input("token", "text", title:"Access Token")
input("deviceID", "text", title:"Device ID")
}
metadata {
definition (name: "Photon", author: "calmraptor") {
capability "Switch"
}
tiles {
standardTile("switch", "device.switch", width: 2, height: 2, canChangeIcon: true) {
state "on", label: '${name}', action: "switch.off", icon: "st.switches.switch.on", backgroundColor: "#79b821"
state "off", label: '${name}', action: "switch.on", icon: "st.switches.switch.off", backgroundColor: "#ffffff"
}
main "switch"
details "switch"
}
}
def parse(String description) {
log.error "This device does not support incoming events"
return null
}
def on() {
httpPost(
uri: "https://api.particle.io/v1/devices/${deviceId}/ledstate",
body: [access_token: token, command: '1'],
)
}
def off() {
httpPost(
uri: "https://api.particle.io/v1/devices/${deviceID}/ledstate",
body: [access_token: token, command: '0'],
)
}