I'm about to connect two ESPs with each other but the one acting as a Client is not able to connect to the SERVER being run on the Server/AP ESP. The weird thing is that I'm able to launch messages via "netcat" and "packetsender" and they all are being received by the server specific sketch (server.available() etc. ...).
I'm sure I am not aware about issues running an ESP as an AP and running Server software on it simultaneously. The Server examples on github only explain a connection to an existing AP by the server sketch but not combining an AP and Server into one sketch.
Heres my Server ESP Sketch:
#include <ESP8266WiFi.h>
const char* ssid = "artex11";
const char* pw = "getmenow11";
WiFiServer server(80);
WiFiClient client;
void setup() {
Serial.begin(115200);
//setup AP
WiFi.softAP(ssid, pw);
Serial.println("AP started at: ");
Serial.print(WiFi.softAPIP());
server.begin();
Serial.println("Server started...");
}
void loop() {
client = server.available();
if(client){
Serial.println("Client connected!");
Serial.print("HasClient: ");
Serial.println(server.hasClient());
char message = client.read();
Serial.printf("Message: %c\n", message);
}
}
Client Sketch:
#include <ESP8266WiFi.h>
const char* ssid = "artex11";
const char* pw = "getmenow11";
const char* host = "192.168.4.1";
const int port = 80;
void setup() {
Serial.begin(115200);
WiFi.begin(ssid, pw);
Serial.println("Connecting to AP");
while(WiFi.status() != WL_CONNECTED){
delay(500);
Serial.print(".");
}
Serial.println(" connected");
}
void loop() {
WiFiClient client;
Serial.println("Connecting to host");
if(!client.connect(host, port)){
Serial.println("...connection failed!");
Serial.println("Retrying in 5 seconds...");
delay(5000);
return;
}
client.print("A");
Serial.println("...TCP message fired!");
delay(2000);
}