-->
Page 1 of 1

Connect two ESPs, one as Server/AP the other as Client

PostPosted: Sun Sep 18, 2016 12:32 pm
by xetra11
Hey guys!

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:

Code: Select all#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:

Code: Select all#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);
}

Re: Connect two ESPs, one as Server/AP the other as Client

PostPosted: Tue Sep 20, 2016 12:54 pm
by mrburnette
I've used an AP/Server as a UDP GPS broadcaster to ESP8266 connected listeners, but I have not gone beyond that simple task.

A quick search indicates success in the forum, at least in these 2 cases:

viewtopic.php?f=19&t=1920#p11938
and
viewtopic.php?f=19&t=1920 - See more at: viewtopic.php?f=33&t=11836#p55429

You may also find some tidbits in this thread by Martin regarding the client side.
viewtopic.php?f=29&t=7627&hilit=esp8266+to+esp8266+client+server&start=12#p45776


Ray