tzapu / WiFiManager

ESP8266 WiFi Connection manager with web captive portal
http://tzapu.com/esp8266-wifi-connection-manager-library-arduino-ide/
MIT License
6.45k stars 1.94k forks source link

OTA UPDATE ISSUE #1741

Open citygreenstech2019 opened 1 month ago

citygreenstech2019 commented 1 month ago

Basic Infos

Hardware

WiFimanager Branch/Release: WiFiClient

Esp8266/Esp32:

Hardware: ESP32-S3

Core Version: 2.4.0, staging

Description

Problem description

Settings in IDE

ARDUINO IDE version 2.3.2

Module: ESP32-S3 dev module.

Additional libraries:

Sketch

#BEGIN
#include <Arduino.h>
#include <WiFi.h>
#include "function_comm.h"
#include "Root_Certificate.h"

void setup() {
void FIRMWARE_UPDATE() {
  strip.setPixelColor(0, strip.Color(255, 255, 0));  // yellow
  strip.show();
  delay(100);
  Serial.println(F(" "));
  Serial.println(F(" ---> FUNCTION : FIRMWARE_UPDATE "));

  WiFiClientSecure client;
  client.setCACert(rootCACertificate);
  t_httpUpdate_return ret = httpUpdate.update(client, URL_fw_Bin);

  switch (ret) {
    case HTTP_UPDATE_FAILED:
      Serial.printf(" HTTP_UPDATE_FAILD Error (%d): %s\n", httpUpdate.getLastError(), httpUpdate.getLastErrorString().c_str());
      break;

    case HTTP_UPDATE_NO_UPDATES:
      Serial.println(" HTTP_UPDATE_NO_UPDATES");
      break;

    case HTTP_UPDATE_OK:
      Serial.println(" HTTP_UPDATE_OK");
      break;
  }

  strip.setPixelColor(0, strip.Color(0, 0, 0));  // off
  strip.show();
}

/*|-----------------------------------------------------------------------------|
    Firmware Version Check
  |-----------------------------------------------------------------------------|*/

int FW_VERSION_CHECK(void) {
  Serial.println(F(" "));
  Serial.println(F(" ---> FUNCTION : FW_VERSION_CHECK "));

  // Debug print to indicate the start of the function
  Serial.println("Starting version check...");

  String payload;
  int httpCode;
  String fwurl = "";
  fwurl += URL_fw_Version;
  fwurl += "?";
  fwurl += String(rand());
  Serial.println(fwurl);
  WiFiClientSecure *client = new WiFiClientSecure;

  if (client) {
    client->setCACert(rootCACertificate);

    // Add a scoping block for HTTPClient https to make sure it is destroyed before WiFiClientSecure *client is
    HTTPClient https;

    if (https.begin(*client, fwurl)) {
      // start connection and send HTTP header
      vTaskDelay(100 / portTICK_PERIOD_MS);
      httpCode = https.GET();
      vTaskDelay(100 / portTICK_PERIOD_MS);

      // Debug print to indicate the status of the HTTP request
      // Serial.print("HTTP request status: ");
      // Serial.println(httpCode);

      // // Debug print to print HTTP_CODE_OK
      // Serial.print("HTTP_CODE_OK: ");
      // Serial.println(HTTP_CODE_OK);

      if (httpCode == HTTP_CODE_OK)  // if version received
      {
        payload = https.getString();  // save received version
      } 

      else 
      {
        Serial.print(" error in downloading version file: ");
        Serial.println(httpCode);
        ERR_CODE=700;// ERROR IN DOWNLOADING VERSION FILE
        tb.sendTelemetryData("ERR_CODE", ERR_CODE);
        Serial.print("Error code: ");
        Serial.println(ERR_CODE);
        String command = "ER1.txt=\"" + String(ERR_CODE, DEC) + "\"";
        Serial0.print(command);
        Serial0.write(0xff);
        Serial0.write(0xff);
        Serial0.write(0xff);

        // Construct command to set number box ER1
        command = "ER1.val=" + String(ERR_CODE, DEC);
        Serial0.print(command);
        Serial0.write(0xff);
        Serial0.write(0xff);
        Serial0.write(0xff);
      }
      https.end();
    }
    delete client;
  }

  if (httpCode == HTTP_CODE_OK)  // if version received
  {
    payload.trim();
    if (payload.equals(FirmwareVer)) {
      Serial.print(F(" Latest Firmware Exist-> Firmware Version: "));
      Serial.println(FirmwareVer);
      return 0;
    } else {
      Serial.print("New firmware found: ");
      Serial.println(payload);
      Serial.println("Uploading new firmware");
      return 1;
    }
  }
  return 0;
}

}

void loop() {
date and time function(),and other required functions
}
#END

Debug Messages

Active Firmware Version: 1.0 17:51:53.959 -> Firmware Update In Progress.. 17:51:53.959 -> https://raw.githubusercontent.com/citygreenstech2019/BASIC_OTA/master/bin-version.txt?1270216262 17:51:54.000 -> [HTTPS] Begin... 17:51:54.000 -> [HTTPS] GET... 17:51:54.728 -> [HTTPS] GET... failed, error: connection refused 17:51:55.716 -> Active Firmware Version: 1.0


messages here
``` OTA update is unable to happen it is showing
"error in downloading version file -1 " and the connection is refused