Your new topic does not fit any of the above??? Check first. Then post here. Thanks.

Moderator: igrr

User avatar
By cyrusomerset
#82832 Hi all! First time posting on this forum!
I've got an interesting problem I'm trying to solve and I keep hitting dead-ends because it looks like the ESP8266WIFI.h library is limited, but I'm sure there is a solution.

So, say I've got 6 ESP8266 + Arduino UNO boards. I want to use 3 of them as "servers" (let's call them S1, S2, S3) and 3 of them as "clients" (C1, C2, C3) (I don't necessarily mean WiFiServer and WiFiClient objects).
Every "client" must be able to send a request to every server, and every server must be able to reply to every client, so the connections (S1C1, S1C2, S1C3, S2C1, S2C2, S2C3, S3C1, S3C2, S3C3) must be active.

At first, I thought about doing this:
Activate SoftAP mode on S1, S2, S3 and create a WiFiServer object on each.
If CX needs to send SX a request: Wifi.begin(SX_ssid, SX_pass) -> create a WifiClient object -> exchange data with server on SX -> close the WifiClient object -> WiFi.disconnect() -> repeat
So the connections are not ALWAYS active. They are opened when they are needed.

This was very similar to what I saw in the source code of the ESP8266WiFiMesh library.

The problem here is the time it takes for the begin and connect functions.
As an experiment, I used 2 ESP8266 boards: one is a server with a softAP, the other is a client. In the loop() function of the client board, I did a WiFi.begin -> WiFiClient.connect -> WiFiClient.close -> WiFi.disconnect sequence.
On average, it took 10 seconds to connect to a server board, but it could also be 20+ seconds sometimes, which is TERRIBLE for my application.
Using the server MAC address and manual IP addresses I managed to get 1-3 second connect times which is much better but I still sometimes got 10 seconds and the WiFiClient.connect() function would sometimes hang, so that my while(WiFiClient.connected() != true) loop would stop everything because the server wouldn't respond.

I have enclosed the source code if anyone would like to try it out and see the results themselves. There are two setup-loop pairs: one for the "server" board, the other for the "client" board. Don't forget to put in your own MAC address!
The main questions are:
- why might the WiFiServer "hang" (WiFiClient.connect() never connects)? Using MAC addresses and manual IP is OK, I can live with that.
- is it possible to actually open ALL connections between the clients and servers so that I don't need to do begin or disconnect ever again until the system is switched off?
- what would be a sensible "next step"? Should I try a different experiment?

Also:
If I create a WiFiServer object while my board is in softAP mode (like in my example), the server will be accessible by the softAP IP address. But what if I am in station + softAP mode? Imagine I have a softAP set up but did WiFi.begin with a different AP. Will the WiFiServer I create be accessible by the softAP IP address or the address I got from the other AP via DHCP?
You do not have the required permissions to view the files attached to this post.
User avatar
By ajaybnl
#82977 If you are going to use the project on house then add a Raspberry zero or Orange-Pi as a MQTT Server & Node-Red to Control Input Outputs.

It will ease your networking task for all esp8622 boards and Arduino boards (thru wifi or RF bridge).

This will cost you 1000+ Rupees but it will solve a TON of problems. It will let you communicate and control other things also.

You can choose Raspberry Pi (For Easiness) or Orange-Pi (For Better Prices) :D

Feel Free to ask.
User avatar
By rudy
#82981 Why don't you use a WiFi router as the access point. All the ESP8266 will connect to it. Then you wouldn't have the delays to connect to each ESP8266 AP. Thrift stores often have old routers for sale and cost almost nothing. It is your simplest solution.

EDIT:

I looked at the code. Why are you using mesh? I don't see it as necessary. But I don't know what you are trying to achieve, the big picture.
Last edited by rudy on Wed Jul 03, 2019 8:02 am, edited 1 time in total.
User avatar
By quackmore
#82982 ESP8266 servers don't necessarily have to run as SOFTAP.

Let all your servers and clients run as STATIONs connected to an existing wifi network

keep all of them connected to the wifi and you will save a lot of time