Skip to content

ESP 8266 HTTP Client Connection Failure #5552

Closed
@nespotts

Description

@nespotts

Basic Infos

  • This issue complies with the issue POLICY doc.
  • I have read the documentation at readthedocs and the issue is not addressed there.
  • I have tested that the issue is present in current master branch (aka latest git).
  • I have searched the issue tracker for a similar issue.
  • If there is a stack dump, I have decoded it.
  • I have filled out all fields below.

Platform

  • Hardware: ESP-12 (ESP8266)
  • Core Version: 2.4.2 & 2.5.0-beta
  • Development Env: Arduino IDE and Platformio
  • Operating System: Ubuntu 16.04

Settings in IDE

  • Module: Wemos D1 Mini and NodeMCU 1.0
  • Flash Mode:
  • Flash Size: 4MB/1MB SPIFFS
  • lwip Variant: v2 Lower Memory
  • Reset Method: Nodemcu
  • Flash Frequency:
  • CPU Frequency: Tried both 80Mhz & 160MHz
  • Upload Using: Serial
  • Upload Speed: 115200 for testing and 921600

Problem Description

I am having issues sending HTTP GET requests to a GoPro Camera. I have gotten this to work for 3 different GoPro cameras, it is just the newer Hero 5 that is giving me problems. It is probably something simple, but the client connection works and the HTTP requests work right after the wifi connections have been reset on the camera, but if the ESP8266 is reset after a first WiFi connection, it connects to the WiFi fine, but all HTTP requests return a -1 HTTP Code and the client fails to connect.

I've tried calling client.flush(), client.stop() and just about anything else I can think of or find online. The only way to make the commands work again is to reset the WiFi connections on the camera. If I connect using my computer, I have no problem sending the commands from Google Chrome as shown in the attached picture. I've tried using the regular ESP8266WiFi library and the ESP8266HTTPClient library as shown below. Any help would be appreciated! Thanks

10 5 5 9-gp-gpcontrol-command-shutter p 1 - google chrome_006

Arduino IDE Sketch

#include <ESP8266WiFi.h>
#include <ESP8266HTTPClient.h>

// Use WiFiclient class to create TCP connections
WiFiClient client;
HTTPClient http;

const char* ssid     = "GP25000830";
const char* password = "vault9291";

String wifi_ssid = "GP25000830";
String wifi_password = "vault9291"; 

const char* host = "10.5.5.9";
const int httpPort = 80;


String StartURL = "/gp/gpControl/command/shutter?p=1";


void Trigger() {
  if (!client.connect(host, httpPort)) {
    Serial.println("connection failed");
    return;
  }

  //Command for starting recording
  client.print(String("GET ") + StartURL + " HTTP/1.1\r\n" +
               "Host: " + host + "\r\n" +
               "User-Agent: RCRemote\r\n" +
               "Connection: close\r\n\r\n");
  Serial.println("Triggering");
  delay(20);
}


void Trigger_http() {
  http.begin("http://10.5.5.9/gp/gpControl/command/shutter?p=1");
  int httpCode = http.GET();
  Serial.print("Http Code is: ");
  Serial.println(httpCode);
  http.end();
}


void setup() {
  WiFi.disconnect(true);
  WiFi.disconnect();

  Serial.begin(115200);

  // We start by connecting to a WiFi network

  Serial.print("Connecting to ");
  Serial.println(ssid);

  WiFi.mode(WIFI_STA);
  WiFi.begin(ssid, password);
 
  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(".");
  }

  Serial.println("");
  Serial.println("WiFi connected");
  Serial.print("IP address: ");
  Serial.println(WiFi.localIP());
  client.flush();

}


void loop() {

  Trigger();
  delay(5000);
  Trigger_http();
  delay(5000);
}

Debug Messages

This is just the debug messages generated via the Serial Port (Debug Level = HTTP_CLIENT). The sketch output is intermixed with the debug messages.

SDK:3.0.0-dev(c0f7b44)/Core:2.5.0-beta2=20499902/lwIP:STABLE-2_1_2_RELEASE/glue:1.0-4-gc434c6f/BearSSL:2398cc6
Connecting to GP25000830
mode : sta(38:2b:78:04:3b:81)
add if0
.....scandone
state: 0 -> 2 (b0)
.state: 2 -> 3 (0)
state: 3 -> 5 (10)
add 0
aid 1
cnt 
.
connected with GP25000830, channel 6
dhcp client start...
....ip:10.5.5.100,mask:255.255.255.0,gw:10.5.5.9
.
WiFi connected
IP address: 10.5.5.100
connection failed
pm open,type:2 0
[HTTP-Client][begin] url: http://10.5.5.9/gp/gpControl/command/shutter?p=1
[HTTP-Client][begin] host: 10.5.5.9 port: 80 url: /gp/gpControl/command/shutter?p=1
[HTTP-Client] failed connect to 10.5.5.9:80
[HTTP-Client][returnError] error(-1): connection refused
Http Code is: -1
[HTTP-Client][end] tcp is closed
connection failed
[HTTP-Client][begin] url: http://10.5.5.9/gp/gpControl/command/shutter?p=1
[HTTP-Client][begin] host: 10.5.5.9 port: 80 url: /gp/gpControl/command/shutter?p=1
[HTTP-Client] failed connect to 10.5.5.9:80
[HTTP-Client][returnError] error(-1): connection refused
Http Code is: -1
[HTTP-Client][end] tcp is closed

If you need any other details, please let me know. Thanks!

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions