Sketch - Master / Server
#include <ESP8266WiFi.h>
const char* ssid = "test";
const char* pw = "12345678";
WiFiServer server(80);
WiFiClient client;
void setup() {
Serial.begin(9600);
//setup AP
WiFi.mode(WIFI_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());
if(client.available())
{
char message = client.read();
Serial.println(message);
Serial.println('A');
}
delay(1);
}
}
Sketch - Client
#include <ESP8266WiFi.h>
void setup() {
Serial.begin(9600);
WiFi.mode(WIFI_STA);
WiFi.begin("test","12345678");
Serial.println();
Serial.println();
Serial.print("Wait for WiFi... ");
while(WiFi.status() != WL_CONNECTED)
{
Serial.print(".");
delay(500);
}
Serial.println("");
Serial.println("WiFi connected");
Serial.println("IP address: ");
Serial.println(WiFi.localIP());
}
void loop()
{
//byte serdata[3]={5};
const int port=80;
const char ip[]="192.168.4.1";
WiFiClient client;
client.connect(ip,port);
/*Serial.print("connecting to ");
Serial.println(ip);*/
if (!client.connect(ip, port))
{
Serial.println("connection failed");
Serial.println("wait 5 sec...");
delay(2000);
return;
}
while (Serial.available()>0)
{
serin=Serial.read();
serdata=serin;
client.write(serdata);
Serial.println(serdata);
}
delay(1);
}