You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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
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
The text was updated successfully, but these errors were encountered:
saeedhtwo
changed the title
How i can to send some data to my esp8266 v7 in IDE environment by arduino code
How i can send some data to my esp8266 v7 in IDE environment by arduino code
Jan 31, 2017
saeedhtwo
changed the title
How i can send some data to my esp8266 v7 in IDE environment by arduino code
How can i send some data to my esp8266 v7 in IDE environment by arduino code
Jan 31, 2017
@saeedhtwo you seem to have a usage error. Your server should .listen() and hace a callback when something is received, then send back on the same socket. There are examples in the repo on how to use WiFiServer and WiFiClient, please search and study them.
In any case, this is not the right place to ask for help for your particular project.
Closing as off-topic, please see #3655 .
Hi to all,
I have 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...");
}
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;
}
}
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
The text was updated successfully, but these errors were encountered: