Hi,
I am just trying to toggle the D7 Led using smartthings app. I have the following code for the photon below.
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;
}
}
The code for the device handler is written below.
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'],
)
}
In Devices on the Smartthings IDE, I have put in the DeviceID and the token which I got from ‘particle token create’.
When I click the ‘on’ button in smartthings app, I get the following error on the IDE saying
groovyx.net.http.HttpResponseException: Unauthorized @line -1 (off)
There were others in the community that did the same thing as above, but I can’t seem to get rid of my error.
Thanks