Can´t connect to webserver in local network using ESP8266

Hello,

I know similar prolems have been addressed before but changing the domain to the IP doesn´t fix it, there actually is no firewall that could block this. The address can easily be connected with a browser in the same network. The page just spits out a small string, so nothing which should be a problem to the ESP.

#include <ESP8266WiFi.h>
#include <ESP8266HTTPClient.h>
#include <WiFiClient.h>

const char* ssid = "myWifi";
const char* password = "myWifipass";
String serverName = "http://192.168.178.71";

unsigned long lastTime = 0;
unsigned long timerDelay = 5000;

void setup() {
  Serial.begin(115200); 

  WiFi.begin(ssid, password);
  Serial.println("Connecting");
  while(WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(".");
  }  
  Serial.println(WiFi.localIP());  
}

void loop() {
  if ((millis() - lastTime) > timerDelay) {
    if(WiFi.status()== WL_CONNECTED){
      WiFiClient client;
      HTTPClient http;

      String serverPath = serverName + "/pool.php";       
      http.begin(client, serverPath.c_str());
      int httpResponseCode = http.GET();
      
      if (httpResponseCode>0) {
        Serial.print("HTTP Response code: ");
        Serial.println(httpResponseCode);
        String payload = http.getString();
        Serial.println(payload);
      }
      else {
        Serial.print("Error code: ");
        Serial.println(httpResponseCode);
      }
      // Free resources
      http.end();
    }
    else {
      Serial.println("WiFi Disconnected");
    }
    lastTime = millis();
  }
}

this script returns an ERROR -1,

Any webserver OUTSIDE the local network does work.
The local webserver runs on Apache2.

Anybody with an idea what the issue could be?

Please only reply when you read this post not just the subject! This is just making it more difficult for other people running into the same problem.

Mmmmm... I don't think it's legitimate to concatenate an unresolved IP address with part of a URL. I admit I haven't tried though...

Try pointing a browser at

http://192.168.178.71/pool.php
and see what you get

@anon57585045 actually no difference if I put it in one string

EDIT: As I wrote in OP, direct call to the url with a browser is no problem.

Not in the program, I mean testing with another client, like a browser...

no problem, works as expected, even with the DNS version

But, you were not specific. You just said, "the address".

What DNS version?

grafik

same with domain/pool.php

I guess you already know, the domain name is safer to use, you should at least continue troubleshooting with that, not the hardcoded IP.

Have you tried hard coding it like:

      http.begin(client, "http://domain/pool.php");

Yes I tried it as a complete string already, same result. Doesn´t matter if I use the ip, it is bound to the device anyway. So the only chance this is changing is when switching the router. But yes of course I´d use the domain once it works, for now this is at least avoiding any issues with the dns.

Well, there can be issues with hard coded IP addresses, too, but I see what you mean.

firewall on computer with the server?

@Juraj didnt change since my original post :wink:

[...]there actually is no firewall that could block this[...]

Is your webserver properly configurated to accept connection other than localhost?

Try with another PC or with a smartphone for example and check if you can reach the webserver.

I thought I wrote my initial post clear enough but obviously I was wrong.

[...] The address can easily be connected with a browser in the same network. [...]

Yes this is clear!
What I did not understand is if you tried with a browser from a PC DIFFERENT from the one in which the webserver is running, you stated only "with a browser in the same network".

IMHO wouldn´t even making a difference when using the ip, just when using localhost
but no of course I used a browser on a different machine.

has the esp8266 network connection at all?

Please post a network diagram. Which devices are connected via Wifi? Which are connected via ethernet? Which device has the webserver? Who can access it and who cannot? Does connecting to the internet work?