Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How can i send some data to my esp8266 v7 in IDE environment by arduino code #2912

Closed
saeedhtwo opened this issue Jan 31, 2017 · 1 comment
Closed

Comments

@saeedhtwo
Copy link

saeedhtwo commented Jan 31, 2017

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...");

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

@saeedhtwo 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 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
@devyte
Copy link
Collaborator

devyte commented Oct 3, 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 .

@devyte devyte closed this as completed Oct 3, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants