Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Correct use of ESP.reset() when using Async Libs? #16

Closed
gjt211 opened this issue Jun 24, 2018 · 1 comment
Closed

Correct use of ESP.reset() when using Async Libs? #16

gjt211 opened this issue Jun 24, 2018 · 1 comment

Comments

@gjt211
Copy link

gjt211 commented Jun 24, 2018

Thanks for such a fantastic library. I have a question and have not been able to find an answer.

As far as I can work out, when using any of the Async libraries you should never use the delay(nn) function which I understand.

What I am unable to work out is what is the correct way to use the ESP.reset() function.
All examples I have found always seem to follow this (note that the delay times vary depending on where you find your example).

delay(3000);
ESP.reset();
delay(2000);

So with the idea that we can't use the delay() function, what is the correct way to do this?

@me-no-dev
Copy link
Owner

me-no-dev commented Jul 24, 2018

usually you set a flag in the async callback and then execute in the loop:

static bool rebootRequested = false;

void onData(void* arg, AsyncClient* client, void *data, size_t len){
  char strData[len+1];
  memcpy(strData, data, len);
  strData[len] = 0;
  if(strcmp("reset", strData) == 0){
    rebootRequested = true;
    client->close(true);
  }
}

void loop(){
  if(rebootRequested){
    ESP.reset();
  }
  //other loop code
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants