-->
Page 1 of 1

How can i send some data to my esp8266 v7 in IDE environment

PostPosted: Tue Jan 31, 2017 4:23 am
by saeedhtwo
Hi to all,

I have a some problems ...

I would like to setup a tcp socket connection between an android phone and an ESP8266 running in AP mode . and i could send some command to client but my main problem it is that i cant send command(data like number or char.....) from client to esp and see it in socket protocol my smart phone answer from server section....

Here is the code i currently use and i want to have more code add in this code to improve my sketch


### Sketch

`#include <ESP8266WiFi.h>
#include <WiFiClient.h>

/* Set these to your desired credentials. */
const char *AP_ssid = "AP_chas";
const char *AP_passkey = "12345678";

int status = WL_IDLE_STATUS;
boolean alreadyConnected[2] ; // whether or not the client was connected previously

WiFiServer server(6000);
WiFiClient client[2];

#define Config_Led D2

void setup()
{
delay(1000);
Serial.begin(115200);
Serial.println();
Serial.println("\nConfiguring access point...");

WiFi.softAP(AP_ssid, AP_passkey);
delay(10000);
IPAddress myIP = WiFi.softAPIP();
Serial.print("AP IP address: ");
Serial.println(myIP);

Serial.println("\nStarting server...");
// start the server:
server.begin();
Serial.println("\nServer Started.");
}

void loop()
{
unsigned int i;
for (i= 0; i<2; i++)
{
// wait for a new client:
if (!client[i])
{
client[i] = server.available();
}
else
{
if (client[i].status() == CLOSED)
{
client[i].stop();
Serial.print("\nConnection closed on client: " );
Serial.println(i);
Serial.println();
alreadyConnected[i] = false;
}

else
{
if(!alreadyConnected[i]) // when the client sends the first byte, say hello:
{
// clean out the input buffer:
client[i].flush();
Serial.print("\nNew client: ");
client[i].println("Hello, client !");
Serial.println(i);
alreadyConnected[i] = true;
}

if (client[i].available())
{
// read the bytes incoming from the client:
String data = client[i].readString();

// echo the bytes to the server as well:
Serial.println(data);
}
}
}
}
}

i have removed echo form in my code . but i need to config my esp in AP mode and after that i send data, client to server. above code can send data from server(esp) to client but i need both operation in one code. my android software is socket protocol...........
Thank you for your help