send header failed random errors, and loopback issue ?

pimoosse
Posts: 1
Joined: Thu Jan 07, 2016 7:58 am

send header failed random errors, and loopback issue ?

Postby pimoosse » Thu Jan 07, 2016 8:24 am

Hello !

I recently received my first ESP8266 board :)

My ESP8266 successfully connects to my local private network (DHCP internet box serving 192.168.0.x IPs)

My goal is to make my ESP8266 call a home made REST API on my RASPBERRY (the two devices are in my local private network) using the ESP8266HTTPClient library and HTTPClient class.

I'm developping with Arduino IDE, and I'm able to compile then upload bin to my ESP8266 and finally see what happen with the COM monitor.

All should be fine, but I have two problems.

1)

My ESP8266 cannot request my local network's devices , I got a -1 / connection refused error when using my Raspberry hostname or IP (192.168.0.103)

But my ESP8266 can successfully make HTTP GET requests to my Raspberry through my external hostname synology address (with correct NAT/PATH rule) !

The odd thing is that I have the inverse situation with my Windows 7 laptop : I cannot request the external URL (loopback issue ?!), but I can request my Raspberry locally !

2)

Even if I successfully manage to HTTP GET my Raspberry with my external hostname, I got a lot of random -2 / "send header failed" errors :(

Here is a COM monitor output sample where you can see a good responde (http 200) and a lot of random -2 returns :

Code: Select all

[HTTP] begin for floriandrevet.synology.me...
[HTTP] GET... code: 200 (try=0)
{"Description":"nHome Domotic Rest Api","Version":"1.0.0.0"}{"Description":"nHome Domotic Rest Api","Version":"1.0.0.0"}
[HTTP] begin for floriandrevet.synology.me...
[HTTP] GET... failed, error: -2
[HTTP] GET... failed, error: -2
[HTTP] GET... failed, error: -2
[HTTP] begin for floriandrevet.synology.me...
[HTTP] GET... failed, error: -2
[HTTP] GET... code: 200 (try=1)
{"Description":"nHome Domotic Rest Api","Version":"1.0.0.0"}{"Description":"nHome Domotic Rest Api","Version":"1.0.0.0"}
[HTTP] begin for floriandrevet.synology.me...
[HTTP] GET... code: 200 (try=0)





Here is the code :

Code: Select all

#include <Arduino.h>

#include <ESP8266WiFi.h>
#include <ESP8266WiFiMulti.h>

#include <ESP8266HTTPClient.h>

#define USE_SERIAL Serial

ESP8266WiFiMulti WiFiMulti;

HTTPClient http;
 
void setup() {

    USE_SERIAL.begin(115200);

    delay(10);

    WiFiMulti.addAP("*****", "*****");

void loop() {
    // wait for WiFi connection
    if((WiFiMulti.run() == WL_CONNECTED))
    {
      doRequest("myserver", 80, "/api/get/description");
    }

    delay(5000);
}

void doRequest(String server, const int port, String url)
{
  USE_SERIAL.print("[HTTP] begin for " + server + "...\n");

  bool resultOk = false;
  int maxTries = 3;
  int currentTries = 0;

  // configure traged server and url
  http.begin(server, port, url); //HTTP

  while(!resultOk && currentTries < maxTries)
  {
    // start connection and send HTTP header
 
    int httpCode = http.GET();
   
    if(httpCode > 0)
    {
        // HTTP header has been send and Server response header has been handled
        USE_SERIAL.printf("[HTTP] GET... code: %d (try=%d)\n", httpCode, currentTries);
 
        // file found at server
        if(httpCode == 200)
        {
            String payload = http.getString();
            USE_SERIAL.println(payload);

            resultOk = true;
        }
    }
    else
    {
      USE_SERIAL.printf("[HTTP] GET... failed, error: %d\n", httpCode);
    }

    if (!resultOk)
    {
      delay(500);
      currentTries++;
    }
  }
 
  http.end();
}



The situation is very frustrating, any help wil lbe appreciated !!

Best regards;

Florian

ESP_Faye
Posts: 1646
Joined: Mon Oct 27, 2014 11:08 am

Re: send header failed random errors, and loopback issue ?

Postby ESP_Faye » Mon Jan 11, 2016 3:41 pm

Hi,

Sorry that we only have the demo based on our original ESP8266_NONOS_SDK http://bbs.espressif.com/viewtopic.php?f=31&t=232.

Could it help ?

Who is online

Users browsing this forum: No registered users and 1 guest