- 
                Notifications
    You must be signed in to change notification settings 
- Fork 13.3k
Closed
Description
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-12F
- Core Version: 3.0.2 I guess?
- Development Env: PlatformIO
- Operating System: macOS
Settings in platformio.ini
[env:nodemcuv2]
platform = espressif8266
board = nodemcuv2
framework = arduino
monitor_speed = 115200
lib_deps = 
	knolleary/PubSubClient@^2.8
Problem Description
In my code I have WiFiClient espClient and WiFiClientSecure updateClient, and they have irrelevant usage.
When updateClient is used by ESPhttpUpdate.update, espClient is disconnected in ESPhttpUpdate.onProgress, as you can test in the sketch:
MCVE Sketch
#include "Arduino.h"
#include <ESP8266WiFi.h>
#include <ESP8266httpUpdate.h>
#include <PubSubClient.h>
#define ssid "ssid" // Change this
#define password "password" // Change this
String upUrl = "https://bin.bemfa.com/b/3BcN2Q1NGY4NWFmNDI5NzZlZTNjMjY5M2U2OTJhNmJiNTk=light002.bin";
char serverName[] = "baidu.com";
WiFiClient espClient;
void onStart()
{
  Serial.println("onStart");
  Serial.printf("WiFiClient is %sconnected.\r\n", espClient.connected() ? "" : "NOT ");
}
void onEnd()
{
  Serial.println("onEnd");
}
void onProgress(int cur, int total)
{
  Serial.printf("onProgress at %d of %d bytes.\r\n", cur, total);
  Serial.printf("WiFiClient is %sconnected.\r\n", espClient.connected() ? "" : "NOT ");
}
void onError(int err)
{
  Serial.printf("onError, err code = %d.\r\n", err);
}
void updateBin()
{
  WiFiClientSecure updateClient;
  updateClient.setInsecure();
  ESPhttpUpdate.onStart(onStart);
  ESPhttpUpdate.onEnd(onEnd);
  ESPhttpUpdate.onProgress(onProgress);
  ESPhttpUpdate.onError(onError);
  t_httpUpdate_return ret = ESPhttpUpdate.update(updateClient, upUrl);
  switch (ret)
  {
  case HTTP_UPDATE_FAILED:
    Serial.println("HTTP_UPDATE_FAILED");
    break;
  case HTTP_UPDATE_NO_UPDATES:
    Serial.println("HTTP_UPDATE_NO_UPDATES");
    break;
  case HTTP_UPDATE_OK:
    Serial.println("HTTP_UPDATE_OK");
    break;
  }
}
void setup()
{
  Serial.begin(115200);
  WiFi.begin(ssid, password);
  while (WiFi.status() != WL_CONNECTED)
  {
    delay(500);
    Serial.print(".");
  }
  Serial.println("");
  if (espClient.connect(serverName, 443))
  {
    if (espClient.connected())
    {
      Serial.println("Connected to https://baidu.com.");
    }
    updateBin();
  }
}
void loop()
{
}
Log
...........
Connected to https://baidu.com.
onStart
WiFiClient is connected.
onProgress at 0 of 305120 bytes.
WiFiClient is NOT connected.
onProgress at 0 of 305120 bytes.
WiFiClient is NOT connected.
onProgress at 4096 of 305120 bytes.
WiFiClient is NOT connected.
...
Did I miss anything or this is normal?
How do I keep espClient CONNECTED during ESPhttpUpdate.update? Thank you.
Metadata
Metadata
Assignees
Labels
No labels