I'm having problems using the "WiFiEvent" as described in guides online. As far as I can tell, a listener on these events is how an ESP8266 server may respond to events like clients connecting, disconnecting, etc. So I add a small listener in setup(), but I get compile errors on all of the event enums.
Please take a look at this excerpt from my code, which I hope contains the relevant code:
In function 'void WiFiEvent(WiFiEvent_t)':
lockServer:87:16: error: 'ARDUINO_EVENT_WIFI_AP_STACONNECTED' was not declared in this scope
87 | if (event == ARDUINO_EVENT_WIFI_AP_STACONNECTED) {
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
exit status 1
'ARDUINO_EVENT_WIFI_AP_STACONNECTED' was not declared in this scope
My server ESP is connecting to my home wifi, so it's not setting up a soft AP. The other ESPs (clients) are not connecting to the server, but simply sending POST requests to the server on its IP address. So, I guess I'm actually on a different approach; my clients aren't connecting to the server at all.
I've set it up like this because I want to be able to easily access a web dashboard on the server from my cellphone/computer, without having to change network (or do anything advanced in the router).
I probably could have the clients actually establish a TCP connection to the server (right?), but are there WiFiEvents which correspond to this? What's a good network design for something like this? Am I on the totally wrong track?
Yes, but then it's a matter of making/opening a websocket, which is establishing a persistent connection to the server. I think this is indeed what I'm looking for. For now, however, I'm experimenting with a simple "pulse" endpoint, where each client periodically (every 10 secs) sends a POST request. This way, the server may keep track of which clients are still out there.
I am indeed confusing these network things, so thanks for the pointers