Error 1101 in MIT App using esp32

I made an application to obtain different values from ESP32 and display them in the application. I'm getting an error saying 'ERROR 1101: Unable to get the response from the specified URL http://192.168.15.70/on' and I can't find anywhere to resolve it, I've tried many things.
My code for App Inventor:
Screenshot_1

Command sent through the browser:

Esp32 serial port:

The error presented in the application:

I wanted to write on the label Status! if the LED was ON = ligado or OFF = desligado.

The code in esp32:

#include <WiFi.h> 

#define led1 2
 
//string de mensagem enviada pelo client
String ClientRequest;
 
//IP estático, de preferencia conectar ESP32 e smartphone na mesma rede
IPAddress staticIP(192,168,15,70);
//Gateway, colocar o gateway da rede em que está conectado
IPAddress gateway(192,168,15,1);
//Máscara, colocar a máscara da rede em que está conectado
IPAddress subnet(255,255,255,0);
 
//Porta de COM server/client
WiFiServer server(80);
 
// Wi-Fi Client
WiFiClient client;
 
//variável usada para solicitar o client 
String myresultat;
String ReadIncomingRequest()
{
  //Enquanto houver dados enviados pelo client 
  while(client.available()) 
  {
    //Atribui para a variável string o comando enviado pelo client
    ClientRequest = (client.readStringUntil('\r'));
 
    //Se existir "HTTP/1.1" na string então recebe comando
    if ((ClientRequest.indexOf("HTTP/1.1")>0))
      myresultat = ClientRequest;
  }
  //Retorna variável resultado
  return myresultat;
}
 
void setup()
{
  //Inicializa varíavel sem dados
  ClientRequest = "";
  pinMode(led1,OUTPUT); 
  Serial.begin(115200);
  delay(10);

  Serial.println("PRONTO!");
  WiFi.begin("Matheus", "12345678");
 
  while (WiFi.status() != WL_CONNECTED) //Enquanto não conectar exibe "."
  {
      delay(500);
      Serial.print(".");
  }

  Serial.println("Conectado!");
  WiFi.config(staticIP, gateway, subnet); //Configura ip estático, gateway e máscara (definidos no início do código)
  Serial.println("Seu IP é");     //Exibe IP utilizado pelo ESP32
  Serial.println((WiFi.localIP()));

  server.begin();   //Inicia COM com servidor
}
 
void loop()
{
    client = server.available();
    if (!client) 
      return; 
 
    //Enquanto nao existir COM com client aguardar
    while(!client.available())
      delay(1); 
 
    //Obtem respostas utilizando a função local ReadIncomingRequest
    ClientRequest = (ReadIncomingRequest());
     
    //Retira dados da página e obtem apenas o comando enviado
    ClientRequest.remove(0, 5);
    ClientRequest.remove(ClientRequest.length()-9,9);
 
    if (ClientRequest == "on"){ 
      digitalWrite(led1,HIGH);
      Serial.println("LED ON!");
      client.print("ligado");
    }
    if (ClientRequest == "off"){
      digitalWrite(led1,LOW);
      Serial.println("LED OFF!");
      client.print("desligado");
    }
    client.flush();
    client.stop();
    delay(1);
}

Make sure your phone is working off the local router via WiFi, and not trying to connect through your cell phone carrier's Internet service, which does not see your local IP addresses.

They are all connected on the same network.

What happens if you add a WebViewer to your app, and send it to those URLs?

Could you tell me how I do it?

WebView should be in the same component pallette as Textbox, button, Label, etc.
Once you have it, its blocks are not that complex.

can it be like this?
Screenshot_1
It is showing what is written but it is still giving an error. I would like to put this value that is showing in a variable.

when I press ON this happens:


This means that I am receiving the values, but how do I put in a status variable.

I don't know why your web page is failing in the Web component, but I am hopeful on the WebView response. It shows you are getting through, but failing some Web formality.

The WebView component has a block to retrieve the Title of the page it receives, if you can figure out how to add such html to your web page.
http://ai2.appinventor.mit.edu/reference/components/userinterface.html#WebViewer
There is also a JavaScript functionality to pass data both ways, if you want to wade deeper.

Here an example with ESP32 and WiFi

I will study my case better and see if the options presented will suit my project. As soon as I get a solution, I'll post it here, thanks.

I had the same problem.

I could connect fine if I did not setup a static IP in arduino code.

To get a static IP to work I had to change it:

From: IPAddress local_IP(192, 168, 1, 115);
To: IPAddress local_IP(192, 168, 0, 115);

It would work if I used 0, 115 or 2,115 but not with 1, 115

Try playing around changing the static IP numbers.

Mike.

Thanks for the help, I managed to make it work with the same ip I was using.

I used as an example a project shown by Juan Antonio and it worked thanks!

I am currently having problems with the communication of another esp01 connected on the same network, I am working to resolve it.

I would like to thank everyone for their help, I solved my problem with changes to the esp code.

So what did you have the ESP send to satisfy the Web component?

I changed the loop this way:

void loop() {
if ((WiFi.status() != WL_CONNECTED) && (millis() > wait30)) {
Serial.println("Trying to reconnect WiFi...");
WiFi.disconnect();
WiFi.begin(ssid, password);
wait30 = millis() + 30000;
}
WiFiClient client = server.available();
if (!client) {
return;
}

Serial.print("New client: ");
Serial.println(client.remoteIP());

String req = client.readStringUntil('\r');
Serial.println(req);

   if (req.indexOf("on1") != -1) {digitalWrite(LED2, HIGH); estado = "LED RED ON";}
   if (req.indexOf("off1") != -1){digitalWrite(LED2, LOW); estado = "LED RED OFF";}
   if (req.indexOf("on2") != -1) {digitalWrite(LED4, HIGH); estado = "LED GREEN ON";}
   if (req.indexOf("off2") != -1){digitalWrite(LED4, LOW); estado = "LED GREEN OFF";}

client.println("HTTP/1.1 200 OK");
client.println("Content-Type: text/html");
client.println("");
client.println(estado);

client.flush();
client.stop();
Serial.println("Client disconnected.");
}

Comparing the two sketches, then,
I'm guessing these were the critical output header lines in the sketch that satisfied the Web component.
Right?

1 Like

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