Strange issue tonight

I had a strange issue with one of my particle devices tonight. They didn’t all do it but just this one. Basically I have a particle function that turns on relays to open or close a water valve when I send a 1 it opens the valve and when I send a 0 it closes the valve.

I mainly control this through my smartthings hub by sending an http request to particle. This has been stably running for probably a good six months now. Til tonight I noticed my pool overflowing and I looked in smartthings it showed the valve was closed but water was clearly running. Craaaaaap at first I faulted smartthings cause they have had issues lately.

I ran a few tests to find the culprit. If i turned off the device from smartthings my valve would close as its supposed to then immediately open back up. If i sent my 1 or 0 to my particle function directly from the console it behaved as expected without doing the extra unexpected command. And at first this solidified my conviction that smartthings was at fault however, when I looked in the smartthings log it only sent the commands that it was supposed to.

I have several photons controlling relays through smartthings using the same method so I thought I would test those and they behaved as expected. To make sure it wasn’t a fluke and didn’t just fix itself before I tested the other devices I tried the problem device one more time and the same thing happened. On a hunch I decided the first thing I would try is power cycling my photon. After I power cycled that photon it is back to behaving as suspected…

This is definitely a strange error. Is it possible that it somehow had two registered instances in the cloud or something like that until I forced it to reconnect? It’s definitely odd behavior and was on the particle side of things. I’ll definintely put some more checks and balances in my code to make sure it wont leave the valve open too long for any reason even if it thinks it had an external command to do so.

Any thoughts on what could have caused this? I know that AWS had some issues or something today but I never saw anything put out by particle as having any incidents.

Did you managed to see the RGB status on the Photon when the incident happened?

What were you triggering to test this? Calling a Particle function from the smartthings platform?

I didn’t think to look at the led status but I’m pretty sure it was breathing cyan like normal or I would have noticed. Yeah basically I make an http request through smartthings to control my devices with this bit of code on the smartthings side

private put(relaystate) {
    //particle API Call
	httpPost(
		uri: "https://api.particle.io/v1/devices/${deviceId}/poolon",
        body: [access_token: token, command: relaystate],  
	) {response -> log.debug (response.data)}
}

relaystate being the one or the zero. so when I controlled it with that the weird behavior happened. however, if I used the particle console to send the one or zero to my particle function it behaved normally. It only reacted strangely with the http post. Like I said power cycling the photon has everything working again normally even the http post… I’m kind of dumbfounded as I normally have been able to trust this thing 100 percent with the valve.

Just to have some more parts to the puzzle.
Is your Particle.function() mirroring back the incoming value?
What does the log.debug() give away?
How have you implemented the Particle.function() callback?

I’m guessing if you mean by mirroring back a value then you mean returning the 1 or 0 so I know that it was succesful? If so yes here’s the but of the code that handles my particle function. It sets a flag in the main loop to accomplish the task and then the flag variable gets reset at the end. I did this to avoid the cloud getting hung up before returning the return value.

int poolonfunc(String command)
{
  if (command == "1") 
    {   
    ponflag = 1;
    return 1;
    } 
  else 
    {               
    poffflag = 1;
    return 0;
    }
}

log.debug in smartthings just showed said that it successfully sent and received the value as I expected. It wasn’t doubled down or anything everything their behaved like normal like I would expect. The strange behavior was not able to be seen with my smartthings debug file at all. Power cylccling the photon brought everything back to normal.