ESP WifiServer blocks the rest of my program

Hi everybody,

I am currently working on a project where I give input to an ESP8266 via network. My problem is:
I want to have the rest of the program running even if no client is connected yet.

When I use the "WiFiClient client= server.available()" I have to wait until a client actually connects before my program can continue. Is there a solution to that, just running the rest of my code and frequently check if a client wants to connect?

if (!client.connected())
    {                              // if client not connected
      client = server.available(); // wait for it to connect
      return;
    }

The snippet above is from an example I found online and It works great. The problem is just that I have to wait for the connection to be made before I can move on...

I hope my question is understandable, thank you for your help!

(I'm currently using a NodeMCU 1.0)

If the ESP8266 has the OS freeRTOS, then the connection routine could be a seperate running task.

Thank you for that hint. I'm using VS Code + PlatformIO at the moment and I found a freeRTOS library that I can add to my project. Unfortunately the source files of this library give me a ton of errors even when I am not using any of it in my code yet. Do you know what I am missing there?
The problems seem to be in "list.h", "queue.h" and "task.h". I know that is a very fuzzy question but maybe there is an easy mistake I made or something I have to configure in PlatformIO?

freeRTOS is already built into the ESP32. You do not need to add a freeROS library to the ESP32.

Unfortunately my pcb contains a ESP8266..

In my opinion it's not great because using return in loop() is poor code structure. Not quite as bad as using goto, but lazy structuring. It prevents later code from running by ending loop() prematurely.

So I would recommend removing return but do take care to check that a client is available before using anything like client.connected() etc. It's hard to give more detailed advice based on only a snipet rather than complete code. You can check if a client is available with

client = server.available();
if(client) {
  ...

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.