Your new topic does not fit any of the above??? Check first. Then post here. Thanks.

Moderator: igrr

User avatar
By marksmith
#58022 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:
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 allnetcat 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 allWiFi.softAP
I do
Code: Select allWiFi.mode(WIFI_STA); WiFi.begin("myHomeSsid", "password");
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.

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