-->
Page 1 of 1

Basic sketch to comunicate with esp in AP mode with phone

PostPosted: Wed Feb 27, 2019 12:51 pm
by sigmarpriest
Hi,
I just started with programing, arduino and stuff. I watched and read a lot of tutorials and examples of comunicateing esp8266 with multiple devices, but I think I'm missing some important thing, so my project doesn't work. :/

I want to use TCP connection to send message to esp by phone app.
I think that in void loop() should be something like if(XXX.available()){readStringUntil('\r');} but usually I got error "available is not member of ESP8266WiFi library"(something like that). In tutorials XXX part is usually called a server or client and define in multiple ways. :/


My code:
Code: Select all#include <ESP8266WiFi.h>


#define APSSID "ARDUINO UNO"
#define APPSK  "12345678"

const char *ssid = APSSID;
const char *password = APPSK;

IPAddress local_IP(192,168,0,1);
IPAddress gateway(192,168,1,1);
IPAddress subnet(255,255,255,0);

 WiFiServer server(80);

void setup()
{delay(500);

 pinMode(LED_BUILTIN, OUTPUT);
 digitalWrite(LED_BUILTIN, HIGH);
 
  Serial.begin(115200);
  Serial.println();

  WiFi.softAP(ssid,password);
  WiFi.begin();
  WiFi.softAPConfig(local_IP, gateway, subnet);
  IPAddress myIP = WiFi.softAPIP();
  Serial.print("AP IP address: ");
  Serial.println(myIP);
  Serial.println("");
  Serial.print("Connected to ");
  Serial.println(ssid);
  Serial.print("IP address: ");
  Serial.println(WiFi.localIP());
  Serial.println(WiFi.softAPIP());
 
  server.begin();
}

void loop() {
 WiFiClient client = server.available();

  if (client) {
    digitalWrite(LED_BUILTIN, LOW);
  String req = client.readStringUntil('\r');
  Serial.println(req);
  client.flush(); 
  }
  if(!client){
    digitalWrite(LED_BUILTIN, HIGH);
    }
  /*else{
  Serial.println("no data");
  delay(1500);
  }
*/
}