HELP - Send and receive data from web server

Hi

I'm trying to do a simple example of communication between an application and ESP32 through an Access Point.

I made a basic example of turning LEDs on and off.

The application works, I can turn the led on/off, but an error message appears on the screen:

And I'm also not able to make the app receive any data from ESP32.

Could anyone help me on this one?

AppInventor Code:
image

Arduino Code:

#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();
  }
}

Thank you!

I'm not a WiFi expert but your Sketch loop does not have any duration control, it just continuously runs at warp speed. So I think the client.stop() function could be triggering the error message.

Concerning sending data to the App, just send '1' for on and '0' for off. In Web1 Got Text, collect all the values to see what you actually get.

blocks

Try this

#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("HTTP/1.1 200 OK");
          client.println("Content-Type: text/html");
          client.println(""); //  Comillas importantes.
          client.println("Ligado"); //  Return status. 
          client.stop();
        }
        if (line.indexOf("LEDOFF") > 0) { 
          digitalWrite(LED_Pin, LOW);
          client.println("HTTP/1.1 200 OK");
          client.println("Content-Type: text/html");
          client.println(""); //  Comillas importantes.
          client.println("Desligado"); //  Return status. 
          client.stop();
        }
      }
    }
    
  }
}

Other examples: