Greetings!
I have studied several videos and themes there, but I am not sure how to properly form my search request, so couldnt find what I am looking for. Thank you in advance for attention and help!
Current state of things: Currently I have 5 wireless buttons, that are based on ESP32-C3. Their purpose is to connect to wifi and only send push-event when any button is pushed. Currently, their connection and event tracking is pretty complicating: I need to pass wifi login/pass into firmware configuration, that needs to be written to each button separately via cable. Also I need to have static IP, that will be served as adress for connection. So everytime I change wifi network, I need to flash each button with new credentials.
What I want to achieve: My idea is to have one more ESP32 (or any other microcontroller) as an access-point hub, to which all buttons will connect wirelessly. "Hub" itself will have always same credentials, so I wont need to re-write config for each button after configuring them to correct credentials once. "Hub" needs to receive signals from buttons and send "button-pushed" event to PC (any device, that hub is connected to via USB), so event can be observed in browser, so web-app/web-page will process it.
Questions:
Is esp32 powerfull enough to handle this task? (5+ connected to it devices and event transfering to PC)
can I have esp32 without any additional modules as a hub? i.e. do I still require battery connected as power for esp32, or power from USB connection to pc will be enough?
do I need to setup any webserver for intercepting events and transfering them to PC? if yes, i would apreciate a guide (if there is any) how to do it properly
I am new with engineering (not new with programming though), so you can treat me as a beginner and explain things as for beginner
Yes. The ESP can act as an access point (AP) for the other ESP. This would be an independent WiFi network with it's own SSID & password.
The disadvantage would be that the range would probably not be as good as your home network router. If your home network consists of multiple access points to cover a wider area, the ESP would not be able to take advantage of this. They would be able to connect only to the hub ESP's network.
Yes, the hub ESP could act as a web server to handle incoming requests. There are many tutorials and example code for using ESP as a web server and as an access point.
But what you have not explained is how your buttons work today without such a server?
Have you considered using WiFi Manager library? With this, when you change your WiFi password, and the buttons are no longer able to connect, they will open an access point of their own, which you can connect to with a smartphone or laptop, and enter the new password that way.
But what you have not explained is how your buttons work today without such a server?
On each button I have arduino code that is sending message with what button is pressed via http request:
#include <WiFi.h>
const char* ssid = "name". //wifi ID
const char* password = "pass"; //wifi pass
#define BTN_PIN0 2
char* host = "192.168.0.33"; //ip address, first three valuest between dots are same as fixed IP in router
uint16_t port = 80;
WiFiClient client;
void setup() {
WiFi.mode(WIFI_STA);
WiFi.begin(ssid, password);
Serial.begin(115200);
pinMode(BTN_PIN0, INPUT_PULLUP);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
}
void loop() {
if (client.connected()) {
if (digitalRead(BTN_PIN0) == LOW) {
client.print("Red_On"); //each button has its own value here (by color) //Green_On//Blue_On//Yellow_On//White_On
Serial.println("Red_On");
while (digitalRead(BTN_PIN0) == LOW) {
delay(50);
}
}
} else {
client.connect(host, port);
delay(10);
Serial.println("Disconect");
}
//Serial.println("Connect");
//delay(1000);
}
Currently on PC I have an app written in C#, that starts simple TCP server on specific IP and PORT and checks for messages from buttons sent to it and after this processing them (code is too long to past here, but idea is simple: listen to http messages on specific address and process them afterwards).
Have you considered using WiFi Manager library? With this, when you change your WiFi password, and the buttons are no longer able to connect, they will open an access point of their own, which you can connect to with a smartphone or laptop, and enter the new password that way.
That can be a solution (and thank you a lot for idea!), but in the same time it will require same amount of actions to be done (through it would be much faster then current solution for sure). So I would be glad to develop more convenient one with one central hub
What happens when the PC is not running?
I guess, buttons are sending messages to specific address, but they are just ignored, since no server is listening to this address
Hard coded anything that isn't guarenteed to be unique is going to result in collision problems.
You won't even be able to run two of your systems side by side for comparison purposes.
Better to have the hub ESP32 scan for existing SSIDs then generate a SSID then use serial, infrared, NFC or whatever to distribute it to the other ESP32s.
There is a hard limit set on the number of devices that can connect to an ESP32 when it is in AP mode, and it's 10 (for an ESP8266 it's 8) so
So i would say, like that you can connect 9 buttons if you still want to be able to connect to the AP with 1 user device.
If you get a version with an external antenna, you will have plenty of range. A real router will obviously provide you with more devices to connect.
It seems to me that an ESP32 is serious overkill for such a simple task, and that an ESP8266 can also easily perform this task (it is still overkill i think, but i can't think of anything smaller or cheaper) The price difference is not that much between an ESP32 and ESP8266 in units, but it is percentage wise.
A router is the simplest, but you could also consider creating a sort of mesh, or even just a chain. 1 ESP connecting to the next, which connects to the next etc etc. or in a sort of tree.
Hard coded anything that isn't guarenteed to be unique is going to result in collision problems.
You won't even be able to run two of your systems side by side for comparison purposes.
Better to have the hub ESP32 scan for existing SSIDs then generate a SSID then use serial, infrared, NFC or whatever to distribute it to the other ESP32s.
Sorry, what have you spotted to be not-unique hardcoded? couldnt understrand what are you about.
And also about SSID - I also didn't get the idea. Elaborate more, if you can, please.
If you get a version with an external antenna, you will have plenty of range.
Wondering, if I can customly attach external antena to existing ESP32 device?
A router is the simplest
It looks so from first glance, but it is serious overkill (even more overkill then using ESP32 instead of ESP8266 ) I will need to bring entire router with me everytime I need my buttons used? small hub should be more convenient
Each system you deploy will need a SSID that doesn't conflict with SSIDs that are already being used in that particular geographic location.
You said you wanted the credentials to be the same on every ESP32. By definition two test systems running side by side and with same code will create two access points with the same SSID. The ESP32s with the switches will not be able to distinguish one access point from the other.
Prior to setting up any access point, you need to first scan for SSIDs that are being broadcast by existing access points. You cannot use any of these SSID names either accidentally or intentionally for your system. The SSID for your system must be unique within that group. The set of SSIDs that you see will vary depending on your geographic location.
Yes if you can cut the trace to the pcb antenna as close to the MCU as possible, then you can. The ESP32 boards i get have a 0R resistor that i can remove and then bridge the connection to the antenna connector (or move the 0R resistor there, but it 805, and bridging the gap with some solder is easier.
In that case i suggest you daisy chain them. It is anyway a one way street, or if you are willing to accept a maximum of 10 buttons, just a single ESP in bot AP and STA mode forwarding to it's nodes. You will have to send some more info along i guess, since the re-issuing of IP addresses may not always go the same way, or i guess you could use static IP addresses The AP + STA will be 192.168.4.1 and the others will be 192.168.4.2 - 11 (or more there is no limit other than the gateway i think)