-->
Page 1 of 1

Urgent Help Needed

PostPosted: Mon Feb 01, 2016 5:38 am
by Syed Ahsan Ghaffar
I need some help related to Esp8266-12 Project. I want to communicate two esp8266-12 via Wifi. My task is to send any messege (A) from server to client , after recieving "A" from server , the client should turn on the led . Please help me with this task.

Server Code:
‪#‎include‬ <ESP8266WiFi.h>
#include <WiFiClient.h>
#include <ESP8266WebServer.h>
‪#‎define‬ ssid "master"
#define password "1234"
ESP8266WebServer server(80);
void setup() {
delay(1000);
Serial.begin(115200);
Serial.println();
Serial.println("Configuring Access Point ...");
WiFi.softAP(ssid, password);
IPAddress myIP = WiFi.softAPIP();
Serial.print("AP IP address: ");
Serial.println(myIP);
server.begin();
Serial.println("HTTP server started");
}
void loop() {
server.handleClient();
server.send(200, "text/plain", "A");
}

Client Code:
#include <ESP8266WiFi.h>

#define ssid "master"
#define password "1234"
const char *host = "192.168.4.1";
char string1[100];

int led=12;

void setup() {
pinMode(led, OUTPUT);
Serial.begin(115200);
delay(10);
Serial.println();
Serial.println();
Serial.print("Connecting to ");
Serial.println(ssid);
WiFi.mode(WIFI_STA);
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("");
Serial.println("WiFi connected");
Serial.println("IP address: ");
Serial.println(WiFi.localIP());
}

void loop() {
delay(8000);
Serial.print("connecting to ");
Serial.println(host);
WiFiClient client;
const int httpPort = 80;
if (!client.connect(host, httpPort)) {
Serial.println("connection failed");
return;
}
Serial.print(client.read());
if((client.read())=='A')
{
digitalWrite(led, HIGH);
}
else
digitalWrite(led, LOW);
}