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:
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.
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.
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";}