I have a Arduino UNO WiFi Rev2 board that runs WiFiServer serving as a web server. The server listens and accepts clients using server.available()
. I also want a loop that controls a servo in concurrent of the server.
I looked at ArduinoThread and tried to implement my web server with it.
class WebServer : public Thread
{
private:
// Some method definition omitted
WiFiServer server;
void accept_and_process();
public:
void run() override;
}
void WebServer::accept_and_process()
{
Serial.println("Waiting for client");
// listen for incoming clients
WiFiClient client = server.available();
// Process client
}
void WebServer::run()
{
this->accept_and_process();
this->runned();
}
But the code does not run in parallel with code in void loop()
it only ran code inside loop function and does not accept client as expected
This is the code I ran the server with
void setup()
{
Serial.begin(9600);
WebServer webserver = WebServer();;
webserver.setInterval(100);
webserver.run();
}
void loop()
{
Serial.println("Hello");
delay(1000);
}
How would I run the server concurrent to another function.
server.available()
intovoid loop()
to unblock the execution. I'm still experimenting with it but now everything should work as expected. – sqz Aug 26 '20 at 17:40server.available()
to be non-blocking because I assume it's basicallysocket.accept()
in other languages which for most of the time, is blocking. – sqz Aug 26 '20 at 17:45