I have a stupid problem ...
I would like to setup a tcp socket connection between an android phone and an ESP8266 running in AP mode.
Here is the code I currently use :
/* Create a WiFi access point and provide a web server on it. */
#include <ESP8266WiFi.h>
#include <WiFiClient.h>
#include <ESP8266WebServer.h>
/* Set these to your desired credentials. */
const char *ssid = "JP_TestAP";
int status = WL_IDLE_STATUS;
boolean alreadyConnected = false; // whether or not the client was connected previously
WiFiServer server(23);
void setup()
{
delay(1000);
Serial.begin(115200);
Serial.println();
Serial.print("Configuring access point...");
/* You can remove the password parameter if you want the AP to be open. */
WiFi.softAP(ssid);
delay(10000);
IPAddress myIP = WiFi.softAPIP();
Serial.print("AP IP address: ");
Serial.println(myIP);
Serial.println("\nStarting server...");
// start the server:
server.begin();
}
void loop()
{
// wait for a new client:
WiFiClient client = server.available();
// when the client sends the first byte, say hello:
if (client)
{
if (!alreadyConnected)
{
// clead out the input buffer:
client.flush();
Serial.println("We have a new client");
client.println("Hello, client!");
alreadyConnected = true;
}
if (client.available() > 0) {
// read the bytes incoming from the client:
char thisChar = client.read();
// echo the bytes back to the client:
server.write(thisChar);
// echo the bytes to the server as well:
Serial.write(thisChar);
}
}
}
This code "almost" works...
The AP is dicovered by my Android, I can connect
I can as well open a socket on port 23 with IP 192.168.4.1
the ESP sends back the "Hello Client" message to android.
The problem is that if I try to send a message to ESP from Android nothing happens...
Here is the log
Configuring access point...AP IP address: 192.168.4.1
Starting server...
We have a new client
There should be an obviou bug , but I can't find where...
Thank you for your help
JP