0

Here's my code

void loop() {
  if (analogRead(A0) > 500)
  {
    statuss = true ;
  }
  if (statuss)
  {
    digitalWrite(D7, HIGH);
    if (millis() - lasttime > 500)
    {
      digitalWrite(D8, etat);
      digitalWrite(D6, etat);
      etat = !etat;
      lasttime = millis();
    }
  }
  server.handleClient();
}

When I use only server.handleClient everything works fine but when I add any type of code to the loop() function the server goes down and I can't see the ESP8266 access point.

9
  • 2
    what is any type of code ? .... also, you have not asked a question.
    – jsotola
    Sep 26, 2018 at 15:17
  • 2
    when i use only server.handleClient .... your code has other commands ... your statement does not make sense
    – jsotola
    Sep 26, 2018 at 15:18
  • that's the problem with close reason "Unclear what you are asking". for me it is totally clear about what this question is. and I am glad it is not closed yet
    – Juraj
    Sep 26, 2018 at 17:19
  • @Juraj, i am trying to understand .... if, for example, the OP adds a serial.print() statement to the loop(), then the server goes down ..... how is that clear to you? .... have you had similar experience?
    – jsotola
    Sep 26, 2018 at 20:49
  • @jsotola, read my answer
    – Juraj
    Sep 27, 2018 at 4:12

1 Answer 1

4

The problem is analogRead. The esp8266 uses the ADC to evaluate the strength of the WiFi signal. Hard use of analogRead disturbs it and the signal goes down. Use millis() to time analogRead.

unsigned int tempSensRead() {

  const unsigned long MEASURE_INTERVAL = 2L * 1000 * 60; // 2 minutes
  static unsigned long lastMeasureMillis;
  static unsigned int lastValue;

  if (millis() - lastMeasureMillis > MEASURE_INTERVAL) {
    lastMeasureMillis = millis();
    lastValue = analogRead(A0);
  }
  return lastValue;
}
2
  • @fakherhabib, some feedback please
    – Juraj
    Sep 29, 2018 at 8:57
  • Nice answer. Do you know any sources which confirm the statement "esp8266 uses the ADC to evaluate the strength of the WiFi signal"? I couldn't find this on the datasheet
    – S.H.W
    Sep 22, 2021 at 2:09

Not the answer you're looking for? Browse other questions tagged or ask your own question.