So you're a Noob? Post your questions here until you graduate! Don't be shy.

User avatar
By HobbyDev
#91439 Hi,
I am trying to connect two Wemos D1 Mini pro (Version 1). One has a DHT22 module attached the other one asks for the temperature and the heat index using the HTTPClient.Get() method from ESP8266HTTPClient.h. But all I get back is a "connection refused" error. Calling the "DHT22- server" from a web browser it works like a charm.
Both Wemos modules are of course connected to the same wifi network. I did not post the complete client code, because it is already to long. How the code works:
As soon as the wifi connection is available a ticker calls the SetBit2CallServer() method to set a flag which will be checked in the loop() to start asking the server every 15 seconds. Then the flag will be set to false until the ticker sets it back to true.

What am I doing wrong here? Thanks for any help!
Code: Select all#include <ESP8266WiFi.h>
#include <Ticker.h>

WiFiEventHandler wifiConnectHandler;

#include <ESP8266HTTPClient.h>
const char* serverNameTemperatur = "";
const char* serverNameHeatIndex = "";
Ticker CallServerTimer;
float ServerTemperature = 0;
float ServerHeatIndex = 0;
bool CallServer = false;

void SetBit2CallServer(){

  CallServer = true;

String httpGETRequest(const char* serverName) {
  WiFiClient client;
  HTTPClient http;
  // http.begin(client, "", 80, "/KorrigierterHeatIndex");
  // http.begin(client, serverName);

  http.begin(client, "", 80, "/KorrigierterHeatIndex");
  int httpResponseCode = http.GET();
  String payload = "--";
  if (httpResponseCode>0) {
    Serial.print("HTTP Response code: ");
    payload = http.getString();
  else {
    Serial.print("Error code: ");
    payload = "Error calling the temperature server. Errorcode: " + String(httpResponseCode);
  // Free resources
  return payload;

void onWifiConnect(const WiFiEventStationModeGotIP& event)
  Serial.println("Connected to Wi-Fi.");
  // Call DHT22 Server every 15 sec
void setup() {
// neu MQTT
  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;