I want ESP8266 as a web server when a digital input (say D0) is 5V and as a client when that input is 0V. Restarting can be done to change the mode.
Can we do this by checking the input status of digital input at the setup() and changing the starting mode with an if statement?
Thank you
If I correctly understand what you are asking then you can do both without restarting etc.
If you have a look at my sketch here: esp32cam-demo/VeryBasicWebserver.ino at master · alanesq/esp32cam-demo · GitHub
It acts as a web server but at the same time it can access an external web site with the procedure "requestWebPage"
Yes you can. Something simple like
bool clientmode = false;
void setup() {
pinMode(switchPin, INPUT_PULLUP);
if (digitalRead(switchPin)) clientmode = true;
//(.... rest of setup()
}
void loop() {
if (clientmode) clientloop();
else serverloop();
}
void clientloop() {
}
void serverloop() {
}
Thank you. This is what I was searching for