ESP8266 httpclient connection refused

Hi, I am trying to send http get commands from one WEMOS D1 mini to an other one. Both are of course connected to the same W-Lan. Both have their one web site which is accessible.
All I get is a connection refused error. And I am running out of ideas. Hopefully you see what I don't. How the code works:
After wifi is available I start a ticker every 15 sec and call the function SetBit2CallServer() to set the flag "CallServer" which will be checked in loop(). Here I will call the server to send the temperature values back.

#include <ESP8266WiFi.h>

#include <Ticker.h>

#include <ESP8266HTTPClient.h>

WiFiEventHandler wifiConnectHandler;

const char* serverNameTemperatur = "http://192.168.178.96/KorrigierteTemperatur";

const char* serverNameHeatIndex = "http://192.168.178.96/KorrigierterHeatIndex/";

Ticker CallServerTimer;

float ServerTemperature = 0;

float ServerHeatIndex = 0;

bool CallServer = false;

void SetBit2CallServer(){

  CallServer = true;

}

String httpGETRequest(const char* serverName) {

  WiFiClient client;

  HTTPClient http;

  // I tested with this syntax as well but without success

  // http.begin(client, "192.168.178.96", 80, "/KorrigierterHeatIndex");

  

  http.begin(client, serverName);

  int httpResponseCode = http.GET();

  

  String payload = "--"; 

  

  if (httpResponseCode>0) {

    Serial.print("HTTP Response code: ");

    Serial.println(httpResponseCode);

    payload = http.getString();

  }

  else {

    Serial.print("Error code: ");

    Serial.println(httpResponseCode);

    payload = "Error calling the temperature server. Errorcode: " + String(httpResponseCode);

  }

  // Free resources

  http.end();

  client.stop();

  return payload;

}

void onWifiConnect(const WiFiEventStationModeGotIP& event) 

{

  Serial.println("Connected to Wi-Fi.");

  // Call DHT22 Server every 15 sec 

   CallServerTimer.attach(15,SetBit2CallServer);

}

void setup() {

....

  wifiConnectHandler = WiFi.onStationModeGotIP(onWifiConnect);

...

}

loop() {

...

  if (CallServer == true){

    const char* HttpResult;

    char* Position;

    HttpResult = httpGETRequest(serverNameTemperatur).c_str();

    Position = strstr(HttpResult, "Error");

    if (Position != NULL){

      ServerTemperature = atof(HttpResult);

    }

    HttpResult = httpGETRequest(serverNameHeatIndex).c_str();

    Position = strstr(HttpResult, "Error");

    if (Position != NULL){

      ServerHeatIndex = atof(HttpResult);

    }

    CallServer = false;

  }

  ...
}

If I use "http://192.168.178.96/KorrigierterHeatIndex" this url in a web browser this works like it should, but not in between the two ESP8266 Modules. Any help is appreciated!

HobbyDev

Unfortunately you didn't provide the exact output you got. You should also provide minimal code that shows the problem and actually compiles!

If you actually get a "connection refused" the connection is not allowed which usually is caused by a firewall in between that filters the connection. On WiFi networks this is often a feature of the router called device isolation, so connections between WiFi devices are not allowed but the devices are allowed to connect to the wired network (LAN or Internet).

please excuse me writing back that late. Ok! I will try to make the code compilable :slight_smile:
I checked the idea with "device isolation" on my router. This is all fine so all the WIFI devices are allowed to communicate to each other.

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