ESP32 w/ HCSR04 WiFi

Hello, I have an arduino code that sends data through a Wi-Fi access point according to each case that is met for the sensors, however I cannot get it to perform any action within my APP, probably because I am doing it incorrectly. If someone could guide me on how to do it, I leave my code and the block of the app.

#include <WiFi.h>
#include <Ultrasonic.h>

Ultrasonic ultrasonic(12, 13);
Ultrasonic ultrasonic2(14, 15);

//constantes
const float lejos = 70.0;
const float medio = 50.0;
const float cerca = 30.0;

// SSID y contraseña del punto de acceso WiFi
const char* ssid = "red wifi";
const char* password = "12345678";

WiFiServer server(80);

void setup() {
  Serial.begin(115200);
  
  // Inicia el punto de acceso WiFi
  WiFi.softAP(ssid, password);
  Serial.print("Punto de acceso WiFi iniciado, SSID: ");
  Serial.println(ssid);

  // Inicia el servidor
  server.begin();
  Serial.println("Servidor iniciado");
}

void loop() {
  // Verifica si hay una solicitud de cliente
  WiFiClient client = server.available();
  if (!client) {
    return;
  }

  // Lee los valores del sensor ultrasónico
  long distancia = ultrasonic.read();
  long distancia2 = ultrasonic2.read();

  // Envía respuesta basada en las condiciones originales
  if (distancia < lejos) {
    alertas(client, distancia);
  } else if (distancia > lejos) {
    client.println("d");
    delay(400);
  }

  if (distancia2 < lejos) {
    cuidado(client, distancia2);
  } else if (distancia2 > lejos) {
    delay(400);
    client.println("h");
  }
  
  // Espera un tiempo para evitar sobrecargar la conexión
  delay(100);
}

void alertas(WiFiClient client, float distancia) {
  if (distancia < lejos && distancia >= medio) {
    client.println("a");
    delay(400);
  } else if (distancia < medio && distancia > cerca) {
    client.println("b");
    delay(400);
  } else if (distancia <= cerca) {
    client.println("c");
    delay(400);
  }
}

void cuidado(WiFiClient client, float distancia2) {
  if (distancia2 < lejos && distancia2 >= medio) {
    client.println("e");
    delay(400);
  } else if (distancia2 < medio && distancia2 > cerca) {
    client.println("f");
    delay(400);
  } else if (distancia2 <= cerca) {
    client.println("g");
    delay(400);
  }
}

What do you get in responseContent?.
Create a small app with a single ultrasound module that sends data to the app, to learn how to use it.
Here you have tutorials on the ESP32

Hi, the app says "error 1101, unable to get a response" :confused:
I tried to use exactly the same code of the led on/of and i got the same error, also when i tried to access to the url i couldnt

It would really help if you provided a screenshot of your relevant blocks, so we can see what you are trying to do, and where the problem may be.

To get an image of your blocks, right click in the Blocks Editor and select "Download Blocks as Image". You might want to use an image editor to crop etc. if required. Then post it here in the community.

Taifun


Trying to push the limits! Snippets, Tutorials and Extensions from Pura Vida Apps by icon24 Taifun.