Socket connection drops with ESP in softAP mode
Posted: Sat Nov 12, 2016 5:45 am
Hi,
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:
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
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
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
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:
Code: Select all
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
Code: Select all
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
Code: Select all
I do WiFi.softAP
Code: Select all
then the ESP connects to my home WiFi, I can make the socket connection to it, AND it is reliable - stays up for as long as I've tested it.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