Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Irrelevant WiFiClient disconnected by ESPhttpUpdate.update #8836

Closed
6 tasks done
snakeninny opened this issue Jan 29, 2023 · 3 comments
Closed
6 tasks done

Irrelevant WiFiClient disconnected by ESPhttpUpdate.update #8836

snakeninny opened this issue Jan 29, 2023 · 3 comments

Comments

@snakeninny
Copy link

snakeninny commented Jan 29, 2023

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.

@mcspr
Copy link
Collaborator

mcspr commented Jan 29, 2023

How do I keep espClient CONNECTED during ESPhttpUpdate.update? Thank you.

Should be fixed ≥3.1.0, see #8598

platform = espressif8266

iirc pio pkg update should get you the new version
(https://github.com/platformio/platform-espressif8266/releases/tag/v4.1.0)

@mcspr mcspr closed this as completed Jan 29, 2023
@snakeninny
Copy link
Author

@mcspr Thanks for the info!
But the bug persists for me:

 *  Executing task: platformio run 

Processing nodemcuv2 (platform: espressif8266; board: esp12e; framework: arduino)
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Verbose mode can be enabled via `-v, --verbose` option
CONFIGURATION: https://docs.platformio.org/page/boards/espressif8266/esp12e.html
PLATFORM: Espressif 8266 (4.1.0) > Espressif ESP8266 ESP-12E
HARDWARE: ESP8266 80MHz, 80KB RAM, 4MB Flash
PACKAGES: 
 - framework-arduinoespressif8266 @ 3.30101.0 (3.1.1) 
 - tool-esptool @ 1.413.0 (4.13) 
 - tool-esptoolpy @ 1.30000.201119 (3.0.0) 
 - toolchain-xtensa @ 2.100300.220621 (10.3.0)
LDF: Library Dependency Finder -> https://bit.ly/configure-pio-ldf
LDF Modes: Finder ~ chain, Compatibility ~ soft
Found 38 compatible libraries
Scanning dependencies...
Dependency Graph
|-- PubSubClient @ 2.8.0
|-- ESP8266WiFi @ 1.0
|-- ESP8266httpUpdate @ 1.3
|   |-- ESP8266HTTPClient @ 1.2
|   |   |-- ESP8266WiFi @ 1.0
|   |-- ESP8266WiFi @ 1.0
Building in release mode
...
.......
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.
...

Any ideas?

@mcspr
Copy link
Collaborator

mcspr commented Jan 29, 2023

Ah, it is not server.

#3359 -> #6969
ESPhttpUpdate.closeConnectionsOnUpdate(false);

void closeConnectionsOnUpdate(bool sever)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants