ESP32 - OTA update via Bluetooth

Hello friends, I would appreciate your help (:
I am required to do a project where an ESP 32 WROOM microcontroller will receive a program via bluetooth and write it to itself.
I applied some but got stuck with an error.
The steps I performed:

  1. I wrote initial software on the microcontroller that defines a bluetooth object, and uses the "update" library.
  2. I made another software that I intend to send, and I extracted the binary copy for it.
  3. I sent using Python
  4. The controller received all the data sent, but there is error #6
#include <BluetoothSerial.h>
#include <Update.h>

BluetoothSerial SerialBT;

void setup() {
  Serial.begin(115200);  
  SerialBT.begin("ESP32_OTA_BLUETOOTH");
  Serial.println("Bluetooth device is ready to pair");
}

void loop() {
  if (SerialBT.available()) {
    String received = SerialBT.readStringUntil('\n');
    Serial.println("Received: " + received); 
    if (received == "START") {
      Serial.println("Starting...");
      receiveUpdate();
    }
  }
}

void receiveUpdate() {
  Serial.println("In receiveUpdate function...");
  if (!Update.begin(UPDATE_SIZE_UNKNOWN)) { 
    Serial.println("Error with OTA begin");
    return;
  }

  Serial.println("Begin OTA update...");

  size_t written = 0;
  unsigned long start = millis();
  while ((millis() - start) < 60000) { 
    if (SerialBT.available()) {
      Serial.println("Data available");
      size_t bytesWritten = Update.writeStream(SerialBT); 
      if (bytesWritten){
        written += bytesWritten;
        //Serial.print(".");
        //Serial.print("Bytes written this iteration: ");
        //Serial.println(bytesWritten);
        //Serial.print("Total bytes written so far: ");
        Serial.println(written);
      }
      else {
        Serial.println("No more bytes written, exiting loop...");
        break; 
      }
    }
  }
  Serial.println();

  Serial.println("Total bytes written : " + String(written) + " bytes");

  if (Update.end(true)) { 
    Serial.println("OTA done!");
    SerialBT.println("Update Success, Rebooting...");
    delay(1000); 
    ESP.restart();
  } else {
    Serial.println("Error #: " + String(Update.getError()));
    SerialBT.println("Update Failed");
  }
}


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