I have esp8266. Which I am trying to set up to be a self-contained access point and server (tcp). ESP8266 is connected to ports 2,3 of Arduino Uno. On Arduino, I want to process all information coming into esp8266. Here is my current connection diagram:
And a simple code like this:
ESP8266
/* Create a WiFi access point and provide a web server on it. */
#include<SoftwareSerial.h>
#include <ESP8266WiFi.h>
#include <WiFiClient.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);
WiFiClient client;
void setup()
{
delay(1000);
Serial.begin(9600);
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(200);
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:
if (!client) {
client = server.available();
}
else
{
if (client.status() == CLOSED) {
client.stop();
Serial.println("connection closed !");
}
if (!alreadyConnected) // when the client sends the first byte, say hello:
{
// 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.print(thisChar);
}
}
}
Arduino Uno
#include<SoftwareSerial.h>
SoftwareSerial esp8266(2,3);
String message = "";
bool messageReady = false;
void setup() {
// put your setup code here, to run once:
Serial.begin(115200);
esp8266.begin(9600);
}
void loop() {
while(esp8266.available() > 0) {
message = esp8266.readString();
messageReady = true;
}
if(messageReady) {
Serial.println(message);
messageReady = false;
return;
}
}
Unfortunately, I am not receiving any information from the ESP8266 (just a clear log on monitor port). I don't understand where the mistake.
