Request failed, httpCode: -11

See subject. If I copy paste this:

http://192.168.1.90:8080/67eebdd9cde42b4ea52bc9292c72db35/get/V55

from my serial output into a browser I get:

[“1”]

however running my code I get:

request failed, httpCode: -11

How on earth can this happen?

Relevant code:

String APIreadDevicePin(String token, int pin){
  String spin = String(pin);                      // convert pint number to string
  HTTPClient http;                                // create: // http://192.168.1.90:8080/382222989c2zzdbdf28bf268807c7c/get/pin
  String payload = "request failed";
  String url = "http://192.168.1.90:8080/";       // url -- http://IP:port
  url += token;                                   // blynk token
  url += "/get/V";
  url += spin;                                    // pin to read
  http.begin(url);
  Serial.println(url);
  int httpCode = http.GET();
  delay(50);
  if (httpCode > 0) {
    payload = http.getString();                   // get response payload as String
    payload.remove(0, 2);
    payload.remove(payload.length() - 2);         // strip [""]
  }
  else payload = payload + ", httpCode: " + httpCode;

  http.end();
  delay(10);
  return payload;
}

the line: Serial.println(url);
is the line that produces the above url that I tested in a browser. The line that calls the API in my code is:

  String relayState = APIreadDevicePin(auth_RLY, relayOn_PIN[ROOM-1]);      // additional vpin state set by relay pins go from 0-6 rooms from 1-7

no one? really?

have you tried digging out the meaning of this code?

yeah, if I google it, guess what comes up on top?

This topic! I can’t find anything concerning that and don’t know where to look to do find anything.

That’s probably because this http code is “unexpected”, I’d say. EDIT: Actually IT is expected. See the next post
This is what is written in HTTP client library:
(send request is called by http.GET();

/**
 * sendRequest
 * @param type const char *     "GET", "POST", ....
 * @param stream Stream *       data stream for the message body
 * @param size size_t           size for the message body if 0 not Content-Length is send
 * @return -1 if no info or > 0 when Content-Length is set by server
 */

and those are programmed error code responses:

/// HTTP codes see RFC7231
typedef enum {
    HTTP_CODE_CONTINUE = 100,
    HTTP_CODE_SWITCHING_PROTOCOLS = 101,
    HTTP_CODE_PROCESSING = 102,
    HTTP_CODE_OK = 200,
    HTTP_CODE_CREATED = 201,
    HTTP_CODE_ACCEPTED = 202,
    HTTP_CODE_NON_AUTHORITATIVE_INFORMATION = 203,
    HTTP_CODE_NO_CONTENT = 204,
    HTTP_CODE_RESET_CONTENT = 205,
    HTTP_CODE_PARTIAL_CONTENT = 206,
    HTTP_CODE_MULTI_STATUS = 207,
    HTTP_CODE_ALREADY_REPORTED = 208,
    HTTP_CODE_IM_USED = 226,
    HTTP_CODE_MULTIPLE_CHOICES = 300,
    HTTP_CODE_MOVED_PERMANENTLY = 301,
    HTTP_CODE_FOUND = 302,
    HTTP_CODE_SEE_OTHER = 303,
    HTTP_CODE_NOT_MODIFIED = 304,
    HTTP_CODE_USE_PROXY = 305,
    HTTP_CODE_TEMPORARY_REDIRECT = 307,
    HTTP_CODE_PERMANENT_REDIRECT = 308,
    HTTP_CODE_BAD_REQUEST = 400,
    HTTP_CODE_UNAUTHORIZED = 401,
    HTTP_CODE_PAYMENT_REQUIRED = 402,
    HTTP_CODE_FORBIDDEN = 403,
    HTTP_CODE_NOT_FOUND = 404,
    HTTP_CODE_METHOD_NOT_ALLOWED = 405,
    HTTP_CODE_NOT_ACCEPTABLE = 406,
    HTTP_CODE_PROXY_AUTHENTICATION_REQUIRED = 407,
    HTTP_CODE_REQUEST_TIMEOUT = 408,
    HTTP_CODE_CONFLICT = 409,
    HTTP_CODE_GONE = 410,
    HTTP_CODE_LENGTH_REQUIRED = 411,
    HTTP_CODE_PRECONDITION_FAILED = 412,
    HTTP_CODE_PAYLOAD_TOO_LARGE = 413,
    HTTP_CODE_URI_TOO_LONG = 414,
    HTTP_CODE_UNSUPPORTED_MEDIA_TYPE = 415,
    HTTP_CODE_RANGE_NOT_SATISFIABLE = 416,
    HTTP_CODE_EXPECTATION_FAILED = 417,
    HTTP_CODE_MISDIRECTED_REQUEST = 421,
    HTTP_CODE_UNPROCESSABLE_ENTITY = 422,
    HTTP_CODE_LOCKED = 423,
    HTTP_CODE_FAILED_DEPENDENCY = 424,
    HTTP_CODE_UPGRADE_REQUIRED = 426,
    HTTP_CODE_PRECONDITION_REQUIRED = 428,
    HTTP_CODE_TOO_MANY_REQUESTS = 429,
    HTTP_CODE_REQUEST_HEADER_FIELDS_TOO_LARGE = 431,
    HTTP_CODE_INTERNAL_SERVER_ERROR = 500,
    HTTP_CODE_NOT_IMPLEMENTED = 501,
    HTTP_CODE_BAD_GATEWAY = 502,
    HTTP_CODE_SERVICE_UNAVAILABLE = 503,
    HTTP_CODE_GATEWAY_TIMEOUT = 504,
    HTTP_CODE_HTTP_VERSION_NOT_SUPPORTED = 505,
    HTTP_CODE_VARIANT_ALSO_NEGOTIATES = 506,
    HTTP_CODE_INSUFFICIENT_STORAGE = 507,
    HTTP_CODE_LOOP_DETECTED = 508,
    HTTP_CODE_NOT_EXTENDED = 510,
    HTTP_CODE_NETWORK_AUTHENTICATION_REQUIRED = 511
} t_http_codes;

well, I’ve found. I was bit wrong. Here it is:

#define HTTPC_ERROR_READ_TIMEOUT (-11)

so it means, it times-out without response… I guess.

ok, thanks, but that does not make any sense. if I use that url in a browser I get an immediate response and using exactly the sme in the code it fails??

edit: note that its a local IP address, accessed by connected ESP devices on the same local network and the browser test is done again on the same local network. AND for another device (running different code for a different function) which has the SAME routine is does work. I’m really baffled.

there is this basic HTTP client test example:

/**
 * BasicHTTPClient.ino
 *
 *  Created on: 24.05.2015
 *
 */

#include <Arduino.h>

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

#include <ESP8266HTTPClient.h>

#define USE_SERIAL Serial

ESP8266WiFiMulti WiFiMulti;

void setup() {

    USE_SERIAL.begin(115200);
   // USE_SERIAL.setDebugOutput(true);

    USE_SERIAL.println();
    USE_SERIAL.println();
    USE_SERIAL.println();

    for(uint8_t t = 4; t > 0; t--) {
        USE_SERIAL.printf("[SETUP] WAIT %d...\n", t);
        USE_SERIAL.flush();
        delay(1000);
    }

    WiFi.mode(WIFI_STA);
    WiFiMulti.addAP("SSID", "PASSWORD");

}

void loop() {
    // wait for WiFi connection
    if((WiFiMulti.run() == WL_CONNECTED)) {

        HTTPClient http;

        USE_SERIAL.print("[HTTP] begin...\n");
        // configure traged server and url
        //http.begin("https://192.168.1.12/test.html", "7a 9c f4 db 40 d3 62 5a 6e 21 bc 5c cc 66 c8 3e a1 45 59 38"); //HTTPS
        http.begin("http://192.168.1.12/test.html"); //HTTP

        USE_SERIAL.print("[HTTP] GET...\n");
        // start connection and send HTTP header
        int httpCode = http.GET();

        // httpCode will be negative on error
        if(httpCode > 0) {
            // HTTP header has been send and Server response header has been handled
            USE_SERIAL.printf("[HTTP] GET... code: %d\n", httpCode);

            // file found at server
            if(httpCode == HTTP_CODE_OK) {
                String payload = http.getString();
                USE_SERIAL.println(payload);
            }
        } else {
            USE_SERIAL.printf("[HTTP] GET... failed, error: %s\n", http.errorToString(httpCode).c_str());
        }

        http.end();
    }

    delay(10000);
}

Have you tried it with ESP device?

yes I’m only working with wemos D1 (esp8266) devices. I’ll give your test a shot as well.

This is me jumping in the deep end without looking… :crazy_face:

Isn’t this similar to using webhook?? Will having the Webhook widget in your App make any difference?

erm… I don’t know what a webhook is. Ill check it out.

Don’t think so… It is directly tight to HTTP API, so…

I don’t think so - again.

I wasn’t sure… I just see HTTP and figure they are related

image

But further reading of the Docs seems to imply that is is just a easier way of sending the http request code… so probaly the widget is NOT required if using lots of code…?

1 Like

@wolph42, some idea came into my mind:
And IF (just for testing purposes) you will hardcode the url into http.begin() with WORKING string (from browser url line)??
What will be the response?
Naturally the WiFI is connected all the time function quits with code -11? (WL_CONNECTED)

ill give it a shot an d let you know. And yes so far its been connected