-->
Page 1 of 1

Delay before ESP HelloServer

PostPosted: Mon Nov 20, 2017 3:44 pm
by Marfun
Hey!
I try to add a five-second delay before the HelloServer script connects to my Wifi, but whatever I do it does not work, either there's a problem to compile or the ESP does not connect at all. Can anyone kick me in the right direction?


Code: Select all#include <ESP8266WiFi.h>
#include <WiFiClient.h>
#include <ESP8266WebServer.h>
#include <ESP8266mDNS.h>

const char* ssid = "WiFi";
const char* password = "Password";

    delay(5000): // here somewhere

ESP8266WebServer server(80);

void handleRoot() {
  digitalWrite(led, 1);
  server.send(200, "text/plain", "hello from esp8266!");
  digitalWrite(led, 0);
}

Re: Delay before ESP HelloServer

PostPosted: Sat Nov 25, 2017 10:49 am
by martinayotte
delay() needs to be inside setup() scope !

Re: Delay before ESP HelloServer

PostPosted: Mon Nov 27, 2017 7:37 am
by Narfel
If you use atom/platformio the time to reconnect the terminal session after a firmware upload is pretty close to 5seconds. That's why a lot of sketches stick something like
Code: Select all       
for(uint8_t t = 5; t > 0; t--)
        {
                Serial.printf("Starting in %d...\r\n", t);
                Serial.flush();
                delay(1000);
        }

in the setup()) to see the startup serial output. Not sure if that is the intention here, though.