Go Down

Topic: How to use multiple connections on esp modules?  (Read 477 times) previous topic - next topic

Stevemoretz

Hello I have bought some wemos about 10 for my house I also bought an ESP32 I heard that it gets 16 clients at the same time but now I don't get anywhere I don't know how to make a sever on esp32 and let all the wemoses use it there is, no satisfying tutorial on the Internet please guide me I need all my client wemoses be connected to esp32 and all send and receive data from it.
Tnx.

PaulS

Quote
I don't know how to make a sever on esp32
The WiFi library in the ESP package includes a server example.

Quote
and let all the wemoses use it there is
That will involve programming the wemoses to connect to your server and make GET requests. As you don't have a server yet, and haven't said what it will be capable of, or what the clients are to actually do, you can't expect much help with the programming.

You really should forget about the number 16. At any given time, the server will be dealing with 0 or 1 client. What the hardware allows is for up to 16 clients to connect at the same time. The hardware manages the queue of clients. You only need to detect that there is a client connected, and to process that client.
The art of getting good answers lies in asking good questions.

Stevemoretz

Yeah I should explain more as you said. Tnx for the reply BTW.The wemoses are supposed to send some analog values to the main server on esp32 and then it updates those values on the server so the phones can use those values and show them (I'm not asking anything about Android programming here just wanted to explain more)also some values should be sent from esp32 to esp8266 on the wemoses so they detect a change and change the way themselves work.So the hardware acceptes 16 connection right?What do you mean only one or zero at a time how much time does it take to switch to a new client so?Do you mean the clients get available only when they connect to the esp32 at the first time or with the 16 connection stablished I still can switch between clients and receive and send data?
Tnx.

PaulS

Quote
So the hardware acceptes 16 connection right?
That's what you said. I do not know.

Quote
What do you mean only one or zero at a time
The queue of clients might be empty. So, the server would have zero clients to deal with.

There might be one client in the queue, which the server pops and deals with, emptying the queue.

There might be 12 clients in the queue, so the server pops one and deals with it, leaving 11 in the queue.

Quote
how much time does it take to switch to a new client
Between completing dealing with a client and getting the next one? A few microseconds.

Between getting one client and the next? That depends on what the server has to do. If the client asked for Pi to 3 decimal places, that won't take long. If the client asked for Pi to the number of decimal places stored in a table in a MySQL database hosted on a Raspberry Pi, and that value turns out to just fit in an unsigned long, it could take quite a while.

Quote
Do you mean the clients get available only when they connect to the esp32 at the first time or with the 16 connection stablished I still can switch between clients and receive and send data?
Clients get in line. Only 16 can be in line at any given time. If a client makes a request when the queue is full, they are turned away.
The art of getting good answers lies in asking good questions.

Stevemoretz

Great explanation Tnx.Ok just something how does this queue thing work?can you provide me some codes putting some clients in queue.No I'm not going to use too much calculations so it wont take a lot I was just worried if switching to the clients would take quite a while which as you explained it doesn't.And I have heard that too as well as you esp doesn't really mention or any other router providers even they don't mention the maximum number of connections exactly and clearly I heard it from people.Just give me more info about the queue and how to use it?TNx pal.

Stevemoretz

I'm looking all the Internet I could find nothing about the queue. Could you please help me Paul?!

rw950431

The queue is managed by the underlying library. All your code needs to do is respond to each client request in turn. Imagine your code is a ticket seller and the clients are people lining up to buy tickets.  The ticket seller doesnt worry about the line of people, he or she just deals with the first person, gives them want they want then waits for the next person.


Although the names may differ slightly the basic scheme goes something like.


Code: [Select]
void loop() {
  // Check if a client has connected
  WiFiClient client = server.available();
  if (client) {
    // process data from the client
  }
    
}


If you post your code you will likely get more help.

Stevemoretz

The queue is managed by the underlying library. All your code needs to do is respond to each client request in turn. Imagine your code is a ticket seller and the clients are people lining up to buy tickets.  The ticket seller doesnt worry about the line of people, he or she just deals with the first person, gives them want they want then waits for the next person.


Although the names may differ slightly the basic scheme goes something like.


Code: [Select]
void loop() {
  // Check if a client has connected
  WiFiClient client = server.available();
  if (client) {
    // process data from the client
  }
   
}


If you post your code you will likely get more help.
Nice Tnx for the code.so each time through the loop I can get one client from
WiFiClient client = server.available();
Nice info and thank you so much I thought the application would be more complicated then this.

rw950431

Correct!

Although technically you either get a reference to the next client or 0 if there are no clients waiting.  Which is why the "ïf (client) {}" bit is important.



The very clever people who wrote the libraries made it all that nice and easy.

Your next challenge will be getting the actual info that your clients send out of the HTTP request you read from the client stream.

https://www.tutorialspoint.com/http/http_requests.htm is a good primer on what to expect on an incoming client connection (spoiler alert- theres lots of stuff to skip over before you get the data you want)


Stevemoretz


Go Up