Combine WebClient and WebServer ?

Hi,

I would like to combine a webserver and a webclient on one ESP8266.

The example code for both functionalities uses "WiFiClient client;"

How can I distinguish in my Sketch between server-functionalities and client-functionalities ?

Server:
Get HTTP-Requests and send back temperature and RSSI()

Client:
Make HTTP POST against a webserver in my network every 5 mins

The server should be available all the time , the client should post its data on a regular base.
Is it sufficient to make two "sections" of code, one for the server that runs all the time, a second one for the client that executes only based on millis() ?

Do I have to execute WiFiClient client; twice in my Sketch ?

BR
Gawan

Is it sufficient to make two "sections" of code, one for the server that runs all the time, a second one for the client that executes only based on millis() ?

Yes.

Do I have to execute WiFiClient client; twice in my Sketch ?

No. That client is the one that is going to make requests of some other server. The one returned by Server.available() is the client making a request of the server. By all means, give them different names.

Hi,

is it possible to use two different clients ?

e.g.
WiFiClient client_post;
and
WiFiClient client_serv;

I thought "client" is a keyword that must not be changed.

At the moment I have one major-loop that splits the logic in two streams.

IF millis-logic tells me that 60 seconds have passed
THEN post a statement to the webservice once
ELSE act as a webserver

in both cases I use the same WiFiClient client;

is it possible to use two different clients ?

Yes.

I thought "client" is a keyword that must not be changed.

No. "client" is the name of the instance. It could just as easily have been named georgeHerbertBush.

At the moment I have one major-loop that splits the logic in two streams.

IF millis-logic tells me that 60 seconds have passed
THEN post a statement to the webservice once
ELSE act as a webserver

I don't understand that. I understand checking that 60 seconds has passed, and it it has, acting as client. I don't understand the else part, though. On any given pass through loop(), you may act as client AND process a client request. No else involved.

in both cases I use the same WiFiClient client;

You most certainly do not. What you use, confusingly, is two different WiFiClient instances with the same name. Ever see the Bob Newhart show, with my brother Daryll and my other brother Daryll?

IF --> client is supposed to make POST-Statement (once per minute)
ELSE --> act as a webserver, process HTTP requests (all the other time)

in both instances, IF and ELSE, I create a Wifi Client(); and do what ever I want to do

What you say is that I can create both clients, one for server on for posts at the beginning of the loop and then handle webserver and cliebt functionalities in parallel without IF and ELSE ?

What you say is that I can create both clients, one for server on for posts at the beginning of the loop and then handle webserver and cliebt functionalities in parallel without IF and ELSE ?

You can't do anything "in parallel" on a single processor system.

You can do something like:

void loop()
{
   // See if it is time to make another request
   if(millis() - lastRequestTime >= timeBetweenRequests)
   {
      // Make the request and read the response
   }

   // See if there are any pesky clients needing servicing
   WiFiClient beggar = server.available();
   if(beggar)
   {
      // Service the poor beggar
   }
}

Making the request is dependent on time. Servicing a client is dependent on there being a client to service; it is NOT dependent on time.