Skip to content

I need help with Arduino Mega OTA upload #252

Closed

Description

@yuny0404

First of all, sorry for my bad English.

I am using Arduino Mega 2560, and uploaded optiboot_atmega2560.hex as the bootloader.

I downloaded ArduinoOTA as a zip file and added the library.

I am trying to upload by selecting Arduino Mega or Mega 2560.

I'm trying to upload a basic Blink example now, but the upload fails.

I wish I could tell you what the reason is

This is an image for reference.

image
image
image

Activity

  1. JAndrassy commented on Jun 21, 2024

    @JAndrassy
    Owner

    with Optiboot you have to use my_boards or Mega Core for upload to Mega. The Arduino AVC platform uses upload settings for the standard bootloader

  2. yuny0404 commented on Jun 24, 2024

    @yuny0404
    Author

    Thanks for your help. Thanks to this, the file upload was successful.

    This time I'm running OTASketchDownload.ino.

    When I run it, a 301 error occurs in the serial.

    I'll show you the code and serial I use.

    Is there anything I need to fix?

    The bin file used in the path is here.

    Please help me😭😭
    https://github.com/dalgona-edu/OTA_test/blob/main/OTA_update_check.ino.bin

    OTASketchDownload.ino

    /*
    
     This example downloads sketch update over network.
     It doesn't start the OTA upload sever of the ArduinoOTA library,
     it only uses the InternalStorage object of the library
     to store and apply the downloaded binary file.
    
     To create the bin file for update of a SAMD board (except of M0),
     use in Arduino IDE command "Export compiled binary".
     To create a bin file for AVR boards see the instructions in README.MD.
     To try this example, you should have a web server where you put
     the binary update.
     Modify the constants below to match your configuration.
    
     Created for ArduinoOTA library in February 2020
     by Juraj Andrassy
     */
    
    #include <Ethernet.h>
    #include <ArduinoHttpClient.h>
    
    #define NO_OTA_NETWORK
    #include <ArduinoOTA.h> // only for InternalStorage
    
    const short VERSION = 1;
    
    // Mac address hidden
    byte mac[] = {};
    
    #ifdef ARDUINO_SAM_ZERO // M0
    #define Serial SerialUSB
    #endif
    
    void handleSketchDownload() {
    
      const char* SERVER = "github.com"; // must be string for HttpClient
      const unsigned short SERVER_PORT = 80;
      const char* PATH = "/dalgona-edu/OTA_test/raw/main/OTA_update_check.ino.bin";
      const unsigned long CHECK_INTERVAL = 5000;
    
      static unsigned long previousMillis;
    
      unsigned long currentMillis = millis();
    
      if (currentMillis - previousMillis < CHECK_INTERVAL)
        return;
      previousMillis = currentMillis;
    
      EthernetClient transport;
      HttpClient client(transport, SERVER, SERVER_PORT);
    
      char buff[64];
      snprintf(buff, sizeof(buff), PATH, VERSION + 1);
    
      Serial.print("Check for update file ");
      Serial.println(buff);
    
      client.get(buff);
    
      int statusCode = client.responseStatusCode();
      Serial.print("Update status code: ");
      Serial.println(statusCode);
      if (statusCode != 200) {
        client.stop();
        return;
      }
    
      long length = client.contentLength();
      if (length == HttpClient::kNoContentLengthHeader) {
        client.stop();
        Serial.println("Server didn't provide Content-length header. Can't continue with update.");
        return;
      }
      Serial.print("Server returned update file of size ");
      Serial.print(length);
      Serial.println(" bytes");
    
      if (!InternalStorage.open(length)) {
        client.stop();
        Serial.println("There is not enough space to store the update. Can't continue with update.");
        return;
      }
      byte b;
      while (length > 0) {
        if (!client.readBytes(&b, 1)) // reading a byte with timeout
          break;
        InternalStorage.write(b);
        length--;
      }
      InternalStorage.close();
      client.stop();
      if (length > 0) {
        Serial.print("Timeout downloading update file at ");
        Serial.print(length);
        Serial.println(" bytes. Can't continue with update.");
        return;
      }
    
      Serial.println("Sketch update apply and reset.");
      Serial.flush();
      InternalStorage.apply(); // this doesn't return
    }
    
    void setup() {
    
      Serial.begin(115200);
      while (!Serial);
    
      Serial.print("Sketch version ");
      Serial.println(VERSION);
    
      Serial.println("Initialize Ethernet with DHCP:");
      if (Ethernet.begin(mac) == 0) {
        Serial.println("Failed to configure Ethernet using DHCP");
        while (true);
      }
      Serial.println("Ethernet connected");
    }
    
    void loop() {
      // check for updates
      handleSketchDownload();
    
      // add your normal loop code below ...
    }
    

    Serial

    Sketch version 1
    Initialize Ethernet with DHCP:
    Ethernet connected
    Check for update file /dalgona-edu/OTA_test/raw/main/OTA_update_check.ino.bin
    Update status code: 301
    Check for update file /dalgona-edu/OTA_test/raw/main/OTA_update_check.ino.bin
    Update status code: 301
    Check for update file /dalgona-edu/OTA_test/raw/main/OTA_update_check.ino.bin
    Update status code: 301
    Check for update file /dalgona-edu/OTA_test/raw/main/OTA_update_check.ino.bin
    Update status code: 301
    Check for update file /dalgona-edu/OTA_test/raw/main/OTA_update_check.ino.bin
    Update status code: 301
    
  3. JAndrassy commented on Jun 24, 2024

    @JAndrassy
    Owner

    the Ethernet library doesn't support secure connection (https)

  4. yuny0404 commented on Jun 24, 2024

    @yuny0404
    Author

    There was such a problem!

    I will refer to it and test it.

    I am testing with OTASketchDownloadWifi.ino.

    An error occurs in the library, which version did you use?

    I am using version 1.8.14.

    image

  5. JAndrassy commented on Jun 24, 2024

    @JAndrassy
    Owner

    WiFiNINA library is not supported on Arduino Mega

  6. yuny0404 commented on Jun 24, 2024

    @yuny0404
    Author

    If so, you should use the http download link in the OTASketchDownload.ino example.

    Thanks for your help😊😊

    I'll test it and come back.

  7. yuny0404 commented on Jun 24, 2024

    @yuny0404
    Author

    hmm..

    I tried several times to insert a link in http format.

    However, when I created the link, only the https format link was created.

    How can I create a link in http format?

    I hope it isn't too difficult...

  8. JAndrassy commented on Jun 24, 2024

    @JAndrassy
    Owner

    most public sites don't allow insecure http

  9. yuny0404 commented on Jun 24, 2024

    @yuny0404
    Author

    It would be great if https format was supported.

    So would it be better to use a local server?

    If you know of any other method than this, please share😊😊

  10. JAndrassy commented on Jun 24, 2024

    @JAndrassy
    Owner

    other way in which way? I don't know what arduino libraries are still able to connect to public sites. many fail on newer versions of the secure protocol. my WiFiEspAT library with Jiri Bilek's firmware in esp8266 may be able to connect to public sites. Or with an ESP32 with AT firmware.

  11. yuny0404 commented on Jun 25, 2024

    @yuny0404
    Author

    Oh... I can't change from mega2560 to another board.

    And you can't use SD cards either.

    So how can I use the OTA function?

  12. JAndrassy commented on Jun 25, 2024

    @JAndrassy
    Owner

    WiFiEspAT is for esp8266 or esp32 as WiFi adapter.

  13. yuny0404 commented on Jun 25, 2024

    @yuny0404
    Author

    Thank you so much for letting me know, but I definitely have to complete the OTA function on the mega2560.

    It's okay if you don't use WiFiEspAT.

    Feel free to use other examples.

    Is there any way to do OTA on mega2560?

    I really want this to succeed😭😭

  14. JAndrassy commented on Jun 25, 2024

    @JAndrassy
    Owner

    so upload from IDE works. you have to code other transports in your sketch. you can do a download, but for https sites you have to use a network adapter which handles the encryption, because Mega doesn't have the computing power to do the encryption.
    I don't understand why you repeat the you have to do it on Mega. I never suggested that you should not.

  15. yuny0404 commented on Jun 25, 2024

    @yuny0404
    Author

    The reason I said that I had to use mega was because I couldn't use ESP32.

    This is how I understood it.
    Since WiFiEspAT can only be used in ESP, I understood that the WiFiEspAT example cannot be used in MEGA.

    Maybe I'm misunderstanding something?

    Anyway, I have no choice but to use mega, and I have to use OTA on mega.

    And I understand why I can't use https format in mega.

    Whatever method you use to do OTA on mega is fine.

    I would be grateful if you could tell me how to do it.

  16. JAndrassy commented on Jun 25, 2024

    @JAndrassy
    Owner

    WiFiEspAT is used in anything else than esp to communicate wit the AT firmware in esp

    sorry I thought you have upload from the IDE working. what is the problem with that?

    did you read https://github.com/JAndrassy/ArduinoOTA/blob/master/README.md ?

  17. yuny0404 commented on Jun 25, 2024

    @yuny0404
    Author

    I read Read.me.

    Let me explain my situation now.

    1. I can only use mega2560 now. ESP cannot be used

    2. I uploaded the optiboot bootloader to mega.

    3. I set the IDE to use Arduino Mega or Mega 2560 (Optiboot).

    4. I tried testing OTA with the OTASketchDownload.ino example.

    5. There was a problem that links in https format could not be used.

    What I'm curious about here is this

    Q1. Can I create a link in http format? If you can make it, how can you make it?

    Q2. Is there a way to test OTA on mega with an example other than the OTASketchDownload.ino example?

    Sorry for the many questions.
    But I really want to succeed at this.

  18. JAndrassy commented on Jun 25, 2024

    @JAndrassy
    Owner

    why did you start with an advanced example?
    with Ethernet library you should use the OTEthernet example and upload from the IDE

  19. yuny0404 commented on Jun 25, 2024

    @yuny0404
    Author

    Oh, I'm sorry. I have already tested the OTEthernet example.
    It worked well without any problems.

  20. JAndrassy commented on Jun 25, 2024

    @JAndrassy
    Owner

    ok. then my job is done. the ArduinoOTA library works

  21. Repository owner locked and limited conversation to collaborators on Jun 25, 2024
  22. converted this issue into a discussion #253 on Jun 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions