I have one ESP(1) opening an AP and running a server on it. The other ESP(2) is running a client on it and is connecting to the AP and after that trying to connect to the host server. The connection to the AP does succeed but the connection to the host always fails and I cannot figure out what the problem is here. Testing the server via netcat and packetsender works fine. Connecting to it via telnet fails because the connections gets closed by the "foreign host".
Server 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);
}
Client
sketch you are setting the IP address of your host to"192.168.4.1"
, but in yourServer
sketch you never set an IP address, so how do you expect the connection to be established? There are multiple libraries for ESP8266, without clarifying which one you are using there is not much we can do about this... – Roberto Lo Giacco Sep 18 '16 at 11:13192.168.0.1
. – Roberto Lo Giacco Sep 18 '16 at 12:36#include <ESP8266WiFi.h>
isnt that visible through the sketch code? I'm gonna try to not rely on a default IP mybe that works. – xetra11 Sep 18 '16 at 13:49