How to send data from ESP32 to Android App ?

My project must send data between ESP32 and Android App.

I create Android App by App Inventor 2.

ESP32 is Server and smartphone is Client

I set ESP32 to AP Mode and I can send data from smartphone to ESP32 but I can’t send data from ESP32

to smartphone.

how to send data from ESP32 to Android App ?

help me please!! :’( thank you

Smartphone makes http request to ESP, sends POST data with it, gets data back in the response.

// I confused process of connecting between ESP and smartphone.

// This is my code from Arduino IDE

#include<WiFi.h>

#define WIFI_AP_NAME “ESP32 Nice”
#define WIFI_AP_PASS “abcdefgh”
WiFiServer server(80,1);

//I set ESP to AP mode.

String c;
void setup() {
Serial.begin(115200);
pinMode(LED_BUILTIN, OUTPUT);
pinMode(4 , OUTPUT);
pinMode(5 , OUTPUT);
pinMode(19 , OUTPUT);
pinMode(21 , OUTPUT);
pinMode(22 , OUTPUT);
Serial.println();
Serial.println();
WiFi.mode(WIFI_AP);
WiFi.softAP(WIFI_AP_NAME, WIFI_AP_PASS);
WiFi.softAPConfig(IPAddress (89,89,89,89),IPAddress (89,89,89,89),IPAddress (255,255,255,0));
Serial.print("IP address: ");
Serial.println(WiFi.softAPIP());

server.begin();

}

void loop() {
// Check if a client has connected
WiFiClient client = server.available();
String req = client.readStringUntil(’\r’);
if (!client) {
Serial.println(“no client”);
return;
}
// Wait until the client sends some data
while(!client.available()){
delay(1);
}
// Read the first line of the request

Serial.println(req);
client.flush();

if (req.indexOf("/SBB HTTP/") != -1){
Serial.println(“Start SBB”);

RUN();
return;
}
}
// create function RUN

void RUN(){
WiFiClient client = server.available();
String req = client.readStringUntil(’\r’);
server.write(“alarm”);
if (req.indexOf("/fronton HTTP/") != -1){
server.write(“alarm”); //this is code for write data to client(ESP32)
Serial.println(“Front ON”);
}
else if (req.indexOf("/frontoff HTTP/") != -1){
server.write(“alarm”);
Serial.println(“Front OFF”);
}
else if (req.indexOf("/stop HTTP/") != -1){
server.write(“alarm”);
Serial.println(“STOP ESP32”);
END();
}
else {
server.write(“alarm”);
Serial.println(“No Data”);
RUN();
}
RUN();
}

//create function END

void END(){
WiFiClient client = server.available();
server.write(“alarm”);
Serial.println(“END”);
client.stop();
}

//this is my app inventor code.

Please use code tags when posting code (so add

[code]and [/code]

around your code, or use the </> button in the full editor).

Secondly: does the posted code work? If not, what does it do, and what should it do?

Can you please share your app inventer .aia file ?