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