Esp8266 reboot after power failure


#1

hi there
i just wanted to know if i can set the gpio pin 3 low at reboot
i try with trigger when device go offline set gpio3 low but when it reboot, it go to the last know state, so il it was high, they will reboot high

i run esp8266-01 with solid state relay

need to reboot in low state for security reason

thanks in advance


#2

I would probably just do it in the setup function.

void setup()
{
  ...other stuff you need here
  digitalWrite(3, LOW);
}

#3

void setup()
{

Serial.begin(9600);
Cayenne.begin(token, ssid, password);
digitalWrite(3, LOW);
}

already tested… but not working…cayenne remain with the last know status in the cloud


#4

Hi @philippethibault,

You could maybe try something like this:

//includes and defines

int initialized;

void setup()
{
    //force it low immediately
    digitalWrite(3, LOW);

    //clear the initialized flag on reset
    initialized = 0;

    Serial.begin(9600);
    Cayenne.begin(token, ssid, password);
}

//loop function


//virtual in
CAYENNE_IN(V0)
{
    if(!initialized) //only once, may be could go in setup too
    {
        Cayenne.virtualWrite(V0,LOW);
        initialized = 1;

        //wait a second to allow force to set. May need longer.
        delay(1000);
    }

    // sets digital out to whatever the virtual is set to
    digitalWrite(3, getValue.asInt());
}

Cheers,

Craig


Cayenne with Pi and Sainsmart 8channel relay
#5

Hmm I’ve never actually had a situation where that would affect me, but I can now see that when the Arduino boots it checks the values of the dashboard before it does anything else confirming what you said. I guess on second thought it would make more sense to check the dashboard to see what the previous value was instead of taking default boot up values. What @Kreggly posted is definitely a step further and should set the value at the dashboard level solving the problem. I tested it and it worked for me, but as his comment says I had to increase the delay to 3 seconds for it to actually work. I used an LED and I didn’t see it flciker at all during the boot process so you should be good to go.