I'm doing a project which involves running the ESP as an access point, connecting a PC to that access point, and making a socket from the PC to the ESP.
Very much abbreviated, I do this:
WiFi.softAP(CONFIG_SSID, CONFIG_PSK);
WiFiServer wifiServer = new WiFiServer(1234);
wifiServer->begin();
while (! wifiServer->hasClient()) { delay(10); }
WiFiClient wifiClient = new WiFiClient(wifiServer->available());
// ...some more stuff involving reading from and writing to wifiClient...
When I run this, the access point appears, my PC can connect to it, and I can make the socket connection to it from my PC (Linux) on port 1234 using something like
netcat 192.168.4.1 1234
but the connection drops about a second later, every time. If I'm quick I can transfer data in and out, proving that the connection works.
If, instead of doing
WiFi.softAP
WiFi.mode(WIFI_STA); WiFi.begin("myHomeSsid", "password");
Should what I'm doing work, or have I misunderstood something? I am relying on the small amount of documentation in the source and header files to understand how to use this, as I haven't been able to find an example which does this sort of thing - they mostly seem to use the ESP in AP mode, and/or run HTTP servers which is more complex than I want/need - but if there is more extensive documentation and/or an example I haven't found, i'd be glad to see it.
Thanks!
-Mark