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

OTA UPDATE ISSUE #1741

Open
citygreenstech2019 opened this issue May 20, 2024 · 1 comment
Open

OTA UPDATE ISSUE #1741

citygreenstech2019 opened this issue May 20, 2024 · 1 comment

Comments

@citygreenstech2019
Copy link

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
@alexhopeoconnor
Copy link

I don't think this has anything to do with WiFiManager, have you posted this issue here by mistake?

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