When reset, should OPTA execute setup() again?

I have followed Over-The-Air (OTA) Updates with the Arduino Portenta H7 tutorial and successfully uploaded an example sketch in the tutorial that blinks red green and blue LED's. I then changed something and again followed the whole procedure, compiled it as binary, hosted the file as .ota (With the same address and file name), and I expected that when I reboot the device, the setup() part of the QSPI sketch will execute again(And therefore download the new, changed .ota file ), however, my board just continues to blink LED's, and on the Serial nothing changes. Like the setup is not executed at all. Here is the QSPI sketch that should enable OTA:

#include <Arduino_Portenta_OTA.h>
#include <WiFi.h>
#include "arduino_secrets.h" 

static char const SSID[] = SSID_NAME;  /* your network SSID (name) */
static char const PASS[] = SSID_PASS;  /* your network password (use for WPA, or use as key for WEP) */

static char const OTA_FILE_LOCATION[] = "http://downloads.arduino.cc/ota/OTA_Usage_Portenta.ino.PORTENTA_H7_M7.ota";

void setup()
{
  Serial.begin(115200);
  while (!Serial) {}

  if (WiFi.status() == WL_NO_SHIELD)
  {
    Serial.println("Communication with WiFi module failed!");
    return;
  }

  int status = WL_IDLE_STATUS;
  while (status != WL_CONNECTED)
  {
    Serial.print  ("Attempting to connect to '");
    Serial.print  (SSID);
    Serial.println("'");
    status = WiFi.begin(SSID, PASS);
    delay(10000);
  }
  Serial.print  ("You're connected to '");
  Serial.print  (WiFi.SSID());
  Serial.println("'");

  Arduino_Portenta_OTA_QSPI ota(QSPI_FLASH_FATFS_MBR, 2);
  Arduino_Portenta_OTA::Error ota_err = Arduino_Portenta_OTA::Error::None;

  if (!ota.isOtaCapable())
  {
    Serial.println("Higher version bootloader required to perform OTA.");
    Serial.println("Please update the bootloader.");
    Serial.println("File -> Examples -> STM32H747_System -> STM32H747_updateBootloader");
    return;
  }

  Serial.println("Initializing OTA storage");
  if ((ota_err = ota.begin()) != Arduino_Portenta_OTA::Error::None)
  {
    Serial.print  ("Arduino_Portenta_OTA::begin() failed with error code ");
    Serial.println((int)ota_err);
    return;
  }

  Serial.println("Starting download to QSPI ...");
  int const ota_download = ota.download(OTA_FILE_LOCATION, false /* is_https */);
  if (ota_download <= 0)
  {
    Serial.print  ("Arduino_Portenta_OTA_QSPI::download failed with error code ");
    Serial.println(ota_download);
    return;
  }
  Serial.print  (ota_download);
  Serial.println(" bytes stored.");


  Serial.println("Decompressing LZSS compressed file ...");
  int const ota_decompress = ota.decompress();
  if (ota_decompress < 0)
  {
    Serial.print("Arduino_Portenta_OTA_QSPI::decompress() failed with error code");
    Serial.println(ota_decompress);
    return;
  }
  Serial.print(ota_decompress);
  Serial.println(" bytes decompressed.");


  Serial.println("Storing parameters for firmware update in bootloader accessible non-volatile memory ...");
  if ((ota_err = ota.update()) != Arduino_Portenta_OTA::Error::None)
  {
    Serial.print  ("ota.update() failed with error code ");
    Serial.println((int)ota_err);
    return;
  }

  Serial.println("Performing a reset after which the bootloader will update the firmware.");
  Serial.println("Hint: Portenta H7 LED will blink Red-Blue-Green.");
  delay(1000); /* Make sure the serial message gets out before the reset. */
  ota.reset();
}

void loop()
{
}

Am I doing something wrong with the way I post topics, or is it just rare to get a reply?

This forum isn't an official Arduino product support channel and the high price of the Portenta H7 means that few people can afford to buy it and therefore few people are able to answer questions about it.

If you were to ask about OTA for a cheaper product such as the ESP32 you would probably get many people offering to help.

Where can I expect then to get help solving the problem? Thank you for the heads up!

You could try the section specifically for the H7.

As far as official support is concerned, that seems to be a bit of a mystery. A Google search didn't find an obvious link to a paid support option. Maybe it exists, perhaps I just didn't see it.

Much appreciated @mikb55 , I saw that the tools directory used to encode and compress from one file format to another support a wide range of boards, so i thought that this could be a universal problem.

Yes.

1 Like

I have deleted your other cross-post @lipfilicmi.

Cross-posting is against the Arduino forum rules. The reason is that duplicate posts can waste the time of the people trying to help. Someone might spend a lot of time investigating and writing a detailed answer on one topic, without knowing that someone else already did the same in the other topic.

Repeated cross-posting can result in a suspension from the forum.

In the future, please only create one topic for each distinct subject matter. This is basic forum etiquette, as explained in the "How to get the best out of this forum" guide. It contains a lot of other useful information. Please read it.

Thanks in advance for your cooperation.

2 Likes

In order to get OTA to work you need to make this code an integral part of any code that you want to make ota-capable. You can place the setup() part (Of the code in the post) in some function and for example, program the user button on OPTA to start the OTA process once the button is pressed (Rising edge). The link remains fixed and you need someone to press the button but it works. I will investigate possibilities of remotely starting the OTA process, without the need for someone to press reset or user button. (One idea is through MQTT when the device receives some string for example "Start_OTA" you simply start the process, the other idea is to make it dependent on some digital input that you can control remotely e.g. wait for Rising Edge on that pin.) It is also possible to configure the link that is hosting .ota file with MQTT.

I suppose I should change the topic title :slightly_smiling_face:

This might be the problem, after OTA upload, you might need to restart the Serial Port.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.