ESP Client/Server strategy

I am trying to think of the best way to have 10 slave nodes send/recv messages to the master node. The project i have in mind consists of 11 ESP'S in total. There would be 1 master and 10 slave nodes. All 10 slave nodes are in charge of generating a PWM signal. The slave nodes would just stay connected and output a PWM signal and periodically the master would send out a message to A specific slave or all 10 slaves at once to adjust the PWM signal and the slave would respond back to the server by means of homemade ACK that confirms the new value has been set.

My question is what would be the best way to do this with an ESP. I have both ESP8266 and ESP32 i can work with. I would like the master node to host the wifi network for the slaves to connect to and at the same time the master node would connect to my home wifi so i could send messages to the master and control the salves.

What happens if 2 or 10 slaves send a message to the master at once?

Could i send messages to 2 or 10 slaves at once?

Should all the nodes use the same server port? "I was thinking UDP"

I already have a master/slave setup working with 1 slave device and the slave sends a structure containing the variables i want to monitor to the master. I have not implemented 2 way communication yet because i'm not sure what direction to go with this.

Someone please give me some guidance here thankyou!!

I would like the master node to host the wifi network for the slaves to connect to and at the same time the master node would connect to my home wifi

I don't think that's possible, unless the master node is actually two esp, communicating over serial/SPI/I2C, with one connected to your home WiFi and the other acting as an access point for the slave nodes. But why not allow the slaves to connect to your home WiFi? You could allocate them, and the master node, fixed IP addresses on your router.

What happens if 2 or 10 slaves send a message to the master at once?

Why would that ever happen? The slaves would only respond when the master sends an instruction.

Could i send messages to 2 or 10 slaves at once?

Why do you want/need to do that? If the master sends messages to each slave in turn, I guess it would take ~5s to complete, maybe less. Do you need changes to happen concurrently?

I am more familiar with HTTP, so I would probably try that if it were my project. The master node would be an HTTP client and the slaves would be HTTP servers. When the master wants to send a message to a slave it can use POST and include the new PWM value as a parameter. The slaves could respond with the response body containing some status or error message which the master can then check. Port 80 would be used for everything by default.

notsolowki:
I would like the master node to host the wifi network for the slaves to connect to and at the same time the master node would connect to my home wifi...

PaulRB:
I don't think that's possible...

I have sort of a setup like that.
The smartphone/laptop/PC connects to the router, which is connected to a master ESP8266, which also has an Access Point that sends (or broadcasts) UDP messages to several slaves, that have a PCA9685 with 16-channel PWM, with an optional second 16-channel slave board.
The smartphone can also directly connect to the master's AP, in case the router is unavailable during a power cut.
Leo..

PaulRB:
I don't think that's possible, unless the master node is actually two esp, communicating over serial/SPI/I2C, with one connected to your home WiFi and the other acting as an access point for the slave nodes. But why not allow the slaves to connect to your home WiFi? You could allocate them, and the master node, fixed IP addresses on your router.

That is an option but id prefer to have it the other way around. I know you can run the esp is STA and AP mode but i don't know much other than that. I think i wanted to go that route initially because or simplicity of them connecting to different named wifi networks without modifying the code. I imagined that as long as the master was up and running i would be able to talk to any slave node that's powered on in range without having to program then each individually.

Ideally in the future i would like for them to behave like this,

power on slave nodes, if nodes don't see the network for them to connect to then go into AP mode and wait to be connected to and configured by an android phone/app or the master.

In the mean time i need to think about first coming up with a plan that's not going to have me chasing my tail in the first place.

[/quote]

PaulRB:
Why would that ever happen? The slaves would only respond when the master sends an instruction.
Why do you want/need to do that? If the master sends messages to each slave in turn, I guess it would take ~5s to complete, maybe less. Do you need changes to happen concurrently?

Basically these will be controlling the output of a LED driver via PWM. I would prefer for them to respond to a change in brightness close to if not the same time as the rest of the slaves. However its not required to be that way and the salves don;t always all 10 get commands at the same time. Sometimes the slave nodes will be individually addressed by the master node.

notsolowki:
I would like the master node to host the wifi network for the slaves to connect to and at the same time the master node would connect to my home wifi so i could send messages to the master and control the salves.

That can be done: the ESP8266 can be both master and slave at the same time. You won't be able to run https in that case, you will have memory issues. Must do plain http.

The ESP32 can probably do that plus encryption, as it has so much more processing power and memory. No experience with it myself.

notsolowki:
power on slave nodes, if nodes don't see the network for them to connect to then go into AP mode and wait to be connected to and configured by an android phone/app or the master.

Check out the WiFiManager library, it does just that.

"My question is what would be the best way to do this with an ESP. I have both ESP8266 and ESP32 i can work with. I would like the master node to host the wifi network for the slaves to connect to and at the same time the master node would connect to my home wifi so i could send messages to the master and control the salves."

The real question is not the "best" way, but "is there a way". There is example code for "mesh" networks that might play into your project idea. The "and at the same time" might prove challenging as I haven't seen example code that would allow the ESP to act as a bridge between its AP functions and to a network it is connected to (ESP functioning like a network hub). You might need to involve a router in your setup.