ESP32 - Access Point problem

Hello

I'm testing communication between an application and ESP32 through an access point. It's pretty basic, just for studying.

#include <WiFi.h> //Inclui a biblioteca
const char* ssid = "ESP32-AP"; 
const char* pass = "12345678"; 

WiFiServer sv(80); 

int LED_Pin = 2;

void setup() {
  Serial.begin(115200);
  pinMode(LED_Pin, OUTPUT);
  WiFi.softAP(ssid, pass);
  Serial.print("Se conectando a: ");
  Serial.println(ssid);
  IPAddress ip = WiFi.softAPIP();
  Serial.print("Endereço de IP: ");
  Serial.println(ip);
  sv.begin(); 
  Serial.println("Servidor online"); 
}
void loop() {
  WiFiClient client = sv.available(); 
  if (client) { 
    String line = ""; 
    while (client.connected()) {
      if (client.available()) { 
        char c = client.read();
        if (c == '\n') {
          if (line.length() == 0) {
            break;
          } else {
            line = "";
          }
        } else if (c != '\r') {
          line += c; 
        }
        if (line.indexOf("LEDON") > 0) { 
          digitalWrite(LED_Pin, HIGH);
          client.println("Ligado");
        }
        if (line.indexOf("LEDOFF") > 0) { 
          digitalWrite(LED_Pin, LOW);
          client.println("Desligado");
        }
      }
    }
    client.stop();
  }
}

I manage to send data from the app to the ESP32 and it turns an LED on and off. But I am not able to send data to the application and I would like to know if the problem is in the Arduino code. As I understand it, just the command "client.println". Got it correctly? Is there a better way to send data from ESP32 to devices that have connected to it?

Thank you!

What does "the app" do with text it receives from the server?

have a look at ESP32 Web Server using Server-Sent Events

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.