Showing error that not happening

Hi, i am trying to make a communication between app created in mit inventor and arduino nano with ethernet module so i set up a http web server on arduino and when i change url on the app it shows error that its unable to get a response with a specified url but arduino receives the response just fine as it should.


#include <OneWire.h>
#include <DallasTemperature.h>
#include <SPI.h>
#include <Ethernet.h>

byte mac[] = { mac adress }; //server stuff
IPAddress ip(192, 168, 1, 177);
EthernetServer server(80);

#define ONE_WIRE_BUS 5

OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensors(&oneWire);
DeviceAddress insideThermometer;

String command;

const int relay = 6;

void setup(void) {
  Serial.begin(9600);
  sensors.begin();
  sensors.getAddress(insideThermometer, 0);
  sensors.setResolution(insideThermometer, 9);
  pinMode(relay, OUTPUT);
  digitalWrite(3,LOW);
  if (Ethernet.begin(mac) == 0) {
    Serial.println("Failed to configure Ethernet using DHCP");
    while (true);
  }

  Serial.print("Server IP Address: ");
  Serial.println(Ethernet.localIP());

  server.begin();
}

float measure_temp() { // Changed return type to float
  sensors.requestTemperatures();
  float tempC = sensors.getTempC(insideThermometer);
  return tempC; // Return temperature value
}

void loop(void) {
  float temperature = measure_temp(); // Assign the return value of measure_temp() to a variable
  //Serial.print("Tempereature: ");
  Serial.println(temperature); // Print the temperature value
  //digitalWrite(relay, HIGH);
  //delay(500);
  //digitalWrite(relay, LOW);
  //delay(500);
  // Listen for incoming clients
  EthernetClient client = server.available();
  
  if (client) {
    String strtemp = String(temperature);
    client.println(strtemp);
    client.println("Ahoj");
    String request = client.readStringUntil('\r');
    int pathStart = request.indexOf(' ') + 1; // Find the position of the first space character
    int pathEnd = request.indexOf(' ', pathStart); // Find the position of the next space character after the first space
    String requestedPath = request.substring(pathStart, pathEnd); // Extract the substring between the two space characters
    requestedPath.remove(0, 1); // odstrani sa /
    if (requestedPath != "favicon.ico" && requestedPath != "alvik/2.1.0"){
      command = requestedPath;
      Serial.print("Request: ");
      Serial.println(requestedPath);
    }
    client.stop();
    Serial.println("Client disconnected");
  }
  if (command == "zap"){
    digitalWrite(relay, HIGH);
  }
  if (command == "vyp"){
    digitalWrite(relay, LOW);
  }
 
}

Is there anyone who knows what to do?

You are trying to use a delay procedure in your blocks, and have not used the required Web1.GotText event block to catch the returned text.

(Canned Response ABG - Waiting and Timing FAQ)

Please see FAQ Section: Waiting and Timing

before you decide to code a delay() procedure in AI2.

...

Also, check if you can reach that URL from your phone with its native web browser.

That URL requires the phone to be connected to the local network, which can't be done if it relies only on cell service.

Yes i can reach and also sent requests.

Thank you, but I have tried to do very similar stuff with raspberry pi where i used the same delay prodedure and url setting as here and there was no error.

I don't see where command gets its value.

I see in your code you are searching for blank ' ' in your URL?

You would need to send %20 in a URL for the URL to be legal.

I can't tell if there are blanks in your text blocks.

Lucky does not mean correct.

Its six lines above these if functions and also at the very top three lines above void setup().

1 Like

GET /zap HTTP/1.1
This is one example of how to full request looks like the "zap" is the thing i send from phone.
I sent this from my phone "http://192.168.4.141/zap" to the request.
I also disabled all delay blocks and still issue continues.

But as I have already tried to describe there are no issues about receiving commands in arduino it is turning HIGH relay pin when "zap" is sent but there is the error message in App that is shown for no reason.

If there is an option to not show errors in MIT App Inventor that will be enough for me.

You can catch the errors with ErrorOcurred block....but it would be better if you find out the reason of the error and you fix it.

1 Like

Thank you Ramon, this is working.