Coder Social home page Coder Social logo

fbiego / esp32_ble_ota_arduino Goto Github PK

View Code? Open in Web Editor NEW
181.0 7.0 37.0 21.25 MB

OTA update on ESP32 via BLE

License: MIT License

C++ 82.08% Python 17.92%
ble ota ota-update esp32 arduino spiffs firmware android bluetooth-low-energy bluetooth-le

esp32_ble_ota_arduino's Introduction

esp32_ble_ota_arduino's People

Contributors

ericlangel avatar fbiego avatar vincent-stragier avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

esp32_ble_ota_arduino's Issues

ble_hci_rx_acl failed to allocate ACL buffers;

I am getting the following error after adding the nimble ota to my code, any idea how to fix it?

TX AA 00
E (32453) NimBLE: ble_hci_rx_acl failed to allocate ACL buffers; increase ACL_BUF_COUNT
E (32456) NimBLE: ble_hci_rx_acl failed to allocate ACL buffers; increase ACL_BUF_COUNT
E (32458) NimBLE: ble_hci_rx_acl failed to allocate ACL buffers; increase ACL_BUF_COUNT
E (32466) NimBLE: ble_hci_rx_acl failed to allocate ACL buffers; increase ACL_BUF_COUNT
E (32474) NimBLE: ble_hci_rx_acl failed to allocate ACL buffers; increase ACL_BUF_COUNT
E (32481) NimBLE: ble_hci_rx_acl failed to allocate ACL buffers; increase ACL_BUF_COUNT
E (32489) NimBLE: ble_hci_rx_acl failed to allocate ACL buffers; increase ACL_BUF_COUNT
E (32497) NimBLE: ble_hci_rx_acl failed to allocate ACL buffers; increase ACL_BUF_COUNT
E (32505) NimBLE: ble_hci_rx_acl failed to allocate ACL buffers; increase ACL_BUF_COUNT
E (32512) NimBLE: ble_hci_rx_acl failed to allocate ACL buffers; increase ACL_BUF_COUNT
E (32520) NimBLE: ble_hci_rx_acl failed to allocate ACL buffers; increase ACL_BUF_COUNT
E (32528) NimBLE: ble_hci_rx_acl failed to allocate ACL buffers; increase ACL_BUF_COUNT
E (32536) NimBLE: ble_hci_rx_acl failed to allocate ACL buffers; increase ACL_BUF_COUNT
E (32543) NimBLE: ble_hci_rx_acl failed to allocate ACL buffers; increase ACL_BUF_COUNT
E (32551) NimBLE: ble_hci_rx_acl failed to allocate ACL buffers; increase ACL_BUF_COUNT
E (32559) NimBLE: ble_hci_rx_acl failed to allocate ACL buffers; increase ACL_BUF_COUNT
E (32566) NimBLE: ble_hci_rx_acl failed to allocate ACL buffers; increase ACL_BUF_COUNT
E (32574) NimBLE: ble_hci_rx_acl failed to allocate ACL buffers; increase ACL_BUF_COUNT
E (32582) NimBLE: ble_hci_rx_acl failed to allocate ACL buffers; increase ACL_BUF_COUNT
E (32590) NimBLE: ble_hci_rx_acl failed to allocate ACL buffers; increase ACL_BUF_COUNT
E (32597) NimBLE: ble_hci_rx_acl failed to allocate ACL buffers; increase ACL_BUF_COUNT
E (32605) NimBLE: ble_hci_rx_acl failed to allocate ACL buffers; increase ACL_BUF_COUNT
E (32613) NimBLE: ble_hci_rx_acl failed to allocate ACL buffers; increase ACL_BUF_COUNT
E (32620) NimBLE: ble_hci_rx_acl failed to allocate ACL buffers; increase ACL_BUF_COUNT
E (32628) NimBLE: ble_hci_rx_acl failed to allocate ACL buffers; increase ACL_BUF_COUNT
E (32636) NimBLE: ble_hci_rx_acl failed to allocate ACL buffers; increase ACL_BUF_COUNT
E (32644) NimBLE: ble_hci_rx_acl failed to allocate ACL buffers; increase ACL_BUF_COUNT
E (32651) NimBLE: ble_hci_rx_acl failed to allocate ACL buffers; increase ACL_BUF_COUNT
E (32659) NimBLE: ble_hci_rx_acl failed to allocate ACL buffers; increase ACL_BUF_COUNT
E (32667) NimBLE: ble_hci_rx_acl failed to allocate ACL buffers; increase ACL_BUF_COUNT
E (32675) NimBLE: ble_hci_rx_acl failed to allocate ACL buffers; increase ACL_BUF_COUNT
E (32682) NimBLE: ble_hci_rx_acl failed to allocate ACL buffers; increase ACL_BUF_COUNT
E (32690) NimBLE: ble_hci_rx_acl failed to allocate ACL buffers; increase ACL_BUF_COUNT
E (32698) NimBLE: ble_hci_rx_acl failed to allocate ACL buffers; increase ACL_BUF_COUNT
E (32705) NimBLE: ble_hci_rx_acl failed to allocate ACL buffers; increase ACL_BUF_COUNT
E (32713) NimBLE: ble_hci_rx_acl failed to allocate ACL buffers; increase ACL_BUF_COUNT
E (32721) NimBLE: ble_hci_rx_acl failed to allocate ACL buffers; increase ACL_BUF_COUNT
E (32729) NimBLE: ble_hci_rx_acl failed to allocate ACL buffers; increase ACL_BUF_COUNT
E (32736) NimBLE: ble_hci_rx_acl failed to allocate ACL buffers; increase ACL_BUF_COUNT
E (32744) NimBLE: ble_hci_rx_acl failed to allocate ACL buffers; increase ACL_BUF_COUNT
E (32752) NimBLE: ble_hci_rx_acl failed to allocate ACL buffers; increase ACL_BUF_COUNT
E (32760) NimBLE: ble_hci_rx_acl failed to allocate ACL buffers; increase ACL_BUF_COUNT
E (32767) NimBLE: ble_hci_rx_acl failed to allocate ACL buffers; increase ACL_BUF_COUNT
E (32775) NimBLE: ble_hci_rx_acl failed to allocate ACL buffers; increase ACL_BUF_COUNT
E (32783) NimBLE: ble_hci_rx_acl failed to allocate ACL buffers; increase ACL_BUF_COUNT
E (32790) NimBLE: ble_hci_rx_acl failed to allocate ACL buffers; increase ACL_BUF_COUNT
E (32798) NimBLE: ble_hci_rx_acl failed to allocate ACL buffers; increase ACL_BUF_COUNT
E (32806) NimBLE: ble_hci_rx_acl failed to allocate ACL buffers; increase ACL_BUF_COUNT
E (32814) NimBLE: ble_hci_rx_acl failed to allocate ACL buffers; increase ACL_BUF_COUNT
E (32821) NimBLE: ble_hci_rx_acl failed to allocate ACL buffers; increase ACL_BUF_COUNT
E (32829) NimBLE: ble_hci_rx_acl failed to allocate ACL buffers; increase ACL_BUF_COUNT
E (32837) NimBLE: ble_hci_rx_acl failed to allocate ACL buffers; increase ACL_BUF_COUNT
E (32845) NimBLE: ble_hci_rx_acl failed to allocate ACL buffers; increase ACL_BUF_COUNT
E (32852) NimBLE: ble_hci_rx_acl failed to allocate ACL buffers; increase ACL_BUF_COUNT
E (32860) NimBLE: ble_hci_rx_acl failed to allocate ACL buffers; increase ACL_BUF_COUNT
E (32868) NimBLE: ble_hci_rx_acl failed to allocate ACL buffers; increase ACL_BUF_COUNT
E (32875) NimBLE: ble_hci_rx_acl failed to allocate ACL buffers; increase ACL_BUF_COUNT
E (32883) NimBLE: ble_hci_rx_acl failed to allocate ACL buffers; increase ACL_BUF_COUNT
E (32891) NimBLE: ble_hci_rx_acl failed to allocate ACL buffers; increase ACL_BUF_COUNT
E (32899) NimBLE: ble_hci_rx_acl failed to allocate ACL buffers; increase ACL_BUF_COUNT
E (32906) NimBLE: ble_hci_rx_acl failed to allocate ACL buffers; increase ACL_BUF_COUNT
E (32914) NimBLE: ble_hci_rx_acl failed to allocate ACL buffers; increase ACL_BUF_COUNT
E (32922) NimBLE: ble_hci_rx_acl failed to allocate ACL buffers; increase ACL_BUF_COUNT
E (32929) NimBLE: ble_hci_rx_acl failed to allocate ACL buffers; increase ACL_BUF_COUNT
E (32937) NimBLE: ble_hci_rx_acl failed to allocate ACL buffers; increase ACL_BUF_COUNT
E (32945) NimBLE: ble_hci_rx_acl failed to allocate ACL buffers; increase ACL_BUF_COUNT
E (32953) NimBLE: ble_hci_rx_acl failed to allocate ACL buffers; increase ACL_BUF_COUNT
E (32960) NimBLE: ble_hci_rx_acl failed to allocate ACL buffers; increase ACL_BUF_COUNT
E (32968) NimBLE: ble_hci_rx_acl failed to allocate ACL buffers; increase ACL_BUF_COUNT
E (32976) NimBLE: ble_hci_rx_acl failed to allocate ACL buffers; increase ACL_BUF_COUNT
E (32984) NimBLE: ble_hci_rx_acl failed to allocate ACL buffers; increase ACL_BUF_COUNT
E (32991) NimBLE: ble_hci_rx_acl failed to allocate ACL buffers; increase ACL_BUF_COUNT
E (32999) NimBLE: ble_hci_rx_acl failed to allocate ACL buffers; increase ACL_BUF_COUNT
E (33007) NimBLE: ble_hci_rx_acl failed to allocate ACL buffers; increase ACL_BUF_COUNT
E (33015) NimBLE: ble_hci_rx_acl failed to allocate ACL buffers; increase ACL_BUF_COUNT
E (33022) NimBLE: ble_hci_rx_acl failed to allocate ACL buffers; increase ACL_BUF_COUNT
E (33030) NimBLE: ble_hci_rx_acl failed to allocate ACL buffers; increase ACL_BUF_COUNT
E (33038) NimBLE: ble_hci_rx_acl failed to allocate ACL buffers; increase ACL_BUF_COUNT
E (33045) NimBLE: ble_hci_rx_acl failed to allocate ACL buffers; increase ACL_BUF_COUNT
E (33053) NimBLE: ble_hci_rx_acl failed to allocate ACL buffers; increase ACL_BUF_COUNT
E (33061) NimBLE: ble_hci_rx_acl failed to allocate ACL buffers; increase ACL_BUF_COUNT
E (33069) NimBLE: ble_hci_rx_acl failed to allocate ACL buffers; increase ACL_BUF_COUNT
E (33076) NimBLE: ble_hci_rx_acl failed to allocate ACL buffers; increase ACL_BUF_COUNT
E (33084) NimBLE: ble_hci_rx_acl failed to allocate ACL buffers; increase ACL_BUF_COUNT
E (33092) NimBLE: ble_hci_rx_acl failed to allocate ACL buffers; increase ACL_BUF_COUNT
E (33099) NimBLE: ble_hci_rx_acl failed to allocate ACL buffers; increase ACL_BUF_COUNT
E (33107) NimBLE: ble_hci_rx_acl failed to allocate ACL buffers; increase ACL_BUF_COUNT
E (33115) NimBLE: ble_hci_rx_acl failed to allocate ACL buffers; increase ACL_BUF_COUNT
E (33123) NimBLE: ble_hci_rx_acl failed to allocate ACL buffers; increase ACL_BUF_COUNT
E (33130) NimBLE: ble_hci_rx_acl failed to allocate ACL buffers; increase ACL_BUF_COUNT
E (33138) NimBLE: ble_hci_rx_acl failed to allocate ACL buffers; increase ACL_BUF_COUNT
E (33146) NimBLE: ble_hci_rx_acl failed to allocate ACL buffers; increase ACL_BUF_COUNT
E (33154) NimBLE: ble_hci_rx_acl failed to allocate ACL buffers; increase ACL_BUF_COUNT
E (33161) NimBLE: ble_hci_rx_acl failed to allocate ACL buffers; increase ACL_BUF_COUNT
E (33169) NimBLE: ble_hci_rx_acl failed to allocate ACL buffers; increase ACL_BUF_COUNT
E (33177) NimBLE: ble_hci_rx_acl failed to allocate ACL buffers; increase ACL_BUF_COUNT
E (33184) NimBLE: ble_hci_rx_acl failed to allocate ACL buffers; increase ACL_BUF_COUNT
E (33192) NimBLE: ble_hci_rx_acl failed to allocate ACL buffers; increase ACL_BUF_COUNT
E (33200) NimBLE: ble_hci_rx_acl failed to allocate ACL buffers; increase ACL_BUF_COUNT
E (33208) NimBLE: ble_hci_rx_acl failed to allocate ACL buffers; increase ACL_BUF_COUNT
E (33215) NimBLE: ble_hci_rx_acl failed to allocate ACL buffers; increase ACL_BUF_COUNT
E (33223) NimBLE: ble_hci_rx_acl failed to allocate ACL buffers; increase ACL_BUF_COUNT
E (33231) NimBLE: ble_hci_rx_acl failed to allocate ACL buffers; increase ACL_BUF_COUNT
E (33239) NimBLE: ble_hci_rx_acl failed to allocate ACL buffers; increase ACL_BUF_COUNT
E (33246) NimBLE: ble_hci_rx_acl failed to allocate ACL buffers; increase ACL_BUF_COUNT
E (33254) NimBLE: ble_hci_rx_acl failed to allocate ACL buffers; increase ACL_BUF_COUNT
E (33262) NimBLE: ble_hci_rx_acl failed to allocate ACL buffers; increase ACL_BUF_COUNT
E (33269) NimBLE: ble_hci_rx_acl failed to allocate ACL buffers; increase ACL_BUF_COUNT
E (33277) NimBLE: ble_hci_rx_acl failed to allocate ACL buffers; increase ACL_BUF_COUNT
E (33285) NimBLE: ble_hci_rx_acl failed to allocate ACL buffers; increase ACL_BUF_COUNT
E (33293) NimBLE: ble_hci_rx_acl failed to allocate ACL buffers; increase ACL_BUF_COUNT
E (33300) NimBLE: ble_hci_rx_acl failed to allocate ACL buffers; increase ACL_BUF_COUNT
E (33308) NimBLE: ble_hci_rx_acl failed to allocate ACL buffers; increase ACL_BUF_COUNT
E (33316) NimBLE: ble_hci_rx_acl failed to allocate ACL buffers; increase ACL_BUF_COUNT
E (33324) NimBLE: ble_hci_rx_acl failed to allocate ACL buffers; increase ACL_BUF_COUNT
E (33331) NimBLE: ble_hci_rx_acl failed to allocate ACL buffers; increase ACL_BUF_COUNT
E (33339) NimBLE: ble_hci_rx_acl failed to allocate ACL buffers; increase ACL_BUF_COUNT
E (33347) NimBLE: ble_hci_rx_acl failed to allocate ACL buffers; increase ACL_BUF_COUNT
E (33354) NimBLE: ble_hci_rx_acl failed to allocate ACL buffers; increase ACL_BUF_COUNT
E (33362) NimBLE: ble_hci_rx_acl failed to allocate ACL buffers; increase ACL_BUF_COUNT
E (33370) NimBLE: ble_hci_rx_acl failed to allocate ACL buffers; increase ACL_BUF_COUNT
E (33378) NimBLE: ble_hci_rx_acl failed to allocate ACL buffers; increase ACL_BUF_COUNT
E (33385) NimBLE: ble_hci_rx_acl failed to allocate ACL buffers; increase ACL_BUF_COUNT
E (33393) NimBLE: ble_hci_rx_acl failed to allocate ACL buffers; increase ACL_BUF_COUNT
E (33401) NimBLE: ble_hci_rx_acl failed to allocate ACL buffers; increase ACL_BUF_COUNT
E (33408) NimBLE: ble_hci_rx_acl failed to allocate ACL buffers; increase ACL_BUF_COUNT
E (33416) NimBLE: ble_hci_rx_acl failed to allocate ACL buffers; increase ACL_BUF_COUNT
E (33424) NimBLE: ble_hci_rx_acl failed to allocate ACL buffers; increase ACL_BUF_COUNT
E (33432) NimBLE: ble_hci_rx_acl failed to allocate ACL buffers; increase ACL_BUF_COUNT
E (33439) NimBLE: ble_hci_rx_acl failed to allocate ACL buffers; increase ACL_BUF_COUNT
E (33447) NimBLE: ble_hci_rx_acl failed to allocate ACL buffers; increase ACL_BUF_COUNT
E (33455) NimBLE: ble_hci_rx_acl failed to allocate ACL buffers; increase ACL_BUF_COUNT
E (33463) NimBLE: ble_hci_rx_acl failed to allocate ACL buffers; increase ACL_BUF_COUNT
E (33470) NimBLE: ble_hci_rx_acl failed to allocate ACL buffers; increase ACL_BUF_COUNT
E (33478) NimBLE: ble_hci_rx_acl failed to allocate ACL buffers; increase ACL_BUF_COUNT
E (33486) NimBLE: ble_hci_rx_acl failed to allocate ACL buffers; increase ACL_BUF_COUNT
E (33493) NimBLE: ble_hci_rx_acl failed to allocate ACL buffers; increase ACL_BUF_COUNT
E (33501) NimBLE: ble_hci_rx_acl failed to allocate ACL buffers; increase ACL_BUF_COUNT
E (33509) NimBLE: ble_hci_rx_acl failed to allocate ACL buffers; increase ACL_BUF_COUNT
E (33517) NimBLE: ble_hci_rx_acl failed to allocate ACL buffers; increase ACL_BUF_COUNT
E (33524) NimBLE: ble_hci_rx_acl failed to allocate ACL buffers; increase ACL_BUF_COUNT
E (33532) NimBLE: ble_hci_rx_acl failed to allocate ACL buffers; increase ACL_BUF_COUNT
E (33540) NimBLE: ble_hci_rx_acl failed to allocate ACL buffers; increase ACL_BUF_COUNT
E (33548) NimBLE: ble_hci_rx_acl failed to allocate ACL buffers; increase ACL_BUF_COUNT
E (33555) NimBLE: ble_hci_rx_acl failed to allocate ACL buffers; increase ACL_BUF_COUNT
E (33563) NimBLE: ble_hci_rx_acl failed to allocate ACL buffers; increase ACL_BUF_COUNT
E (33571) NimBLE: ble_hci_rx_acl failed to allocate ACL buffers; increase ACL_BUF_COUNT
E (33578) NimBLE: ble_hci_rx_acl failed to allocate ACL buffers; increase ACL_BUF_COUNT
E (33586) NimBLE: ble_hci_rx_acl failed to allocate ACL buffers; increase ACL_BUF_COUNT
E (33594) NimBLE: ble_hci_rx_acl failed to allocate ACL buffers; increase ACL_BUF_COUNT
E (33602) NimBLE: ble_hci_rx_acl failed to allocate ACL buffers; increase ACL_BUF_COUNT

Core panic'ed

Hi Fbiego and Team,
I am getting an issue where the core panics or in some cases the ESP32 just freezes not sure which end is the issue the client or server. I only have the logs for the Server i.e. ESP32 side.
Below are the logs as much as I can get Ive added a little bit more in the code so that you can see more in the logs like:
code extract:
else if (pData[0] == 0xFF) //BLE_FOTA_CMD_OTA_INFO (PART_DETAILS) <0xFF> <parts[2]> <MTU[2]>
{
parts = (pData[1] * 256) + pData[2];
MTU = (pData[3] * 256) + pData[4];
MODE = UPDATE_MODE;
Serial.printf("Rcved-OTA_INFO :Parts=%i, MTU=%i, MODE=%i\n", parts, MTU, MODE);
}
Outputs: Rcved-OTA_INFO :Parts=60, MTU=500, MODE=1

I have also opend up your Serial.sprintf(...) in onWrite call backs.

Attached are the logs please see if you've had this issue before... Ive tried both the Android app and python script with similar issue...

Any help would be much appreciated...

Raj

Failedupload log.txt
Failedupload log2.txt
Failedupload log3.txt
Failedupload log4.txt
Failedupload log5.txt
Failedupload log6.txt

App crash after file select

Hello,

i try to test your BLE OTA example.

But the App Crash(close) after selecting the File. I Also get a info that the App is crashed.

Android 10
Xiaomi Note 10 Lite

Re-flashing the firmware does not work!

I flash the firmware with Arduino IDE, after that I can use Android App or Python to successfully flash my ESP32-C3 DevKit over BLE. but after that I can't flash the ESP32 anymore.
I tried both esp32_ble_ota and esp32_nim_ble_ota but it got stuck. do I need to change any setting in Arduino IDE or change the code?
Here is my terminal output, it stuck after this:

Connected
Available space: 1318001
File Size: 573936
@fbiego Can you help me Please!!

FFat seems to be slower than SPIFFS

Hi Felix,

I try to run the FFat version of the code, but it looks like it is slower to run... also I have modified your code.

I have heavily modified your code to reduce de complexity (of the firmware and of the Python OTA script). Note that I removed all the code stored in the loop. Nearly all is managed in the onWrite callback and a new task is created to perform the update in the end. On the other side I changed the update sequence, I first send the file size, then MTU/Part size and finally I initiate the update by getting the mode.
It is not perfect but by removing most of the global variable, the code gets simpler:

/*
   MIT License

   Copyright (c) 2021 Felix Biego

   Permission is hereby granted, free of charge, to any person obtaining a copy
   of this software and associated documentation files (the "Software"), to deal
   in the Software without restriction, including without limitation the rights
   to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
   copies of the Software, and to permit persons to whom the Software is
   furnished to do so, subject to the following conditions:

   The above copyright notice and this permission notice shall be included in
   all copies or substantial portions of the Software.

   THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
   IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
   FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
   AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
   LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
   OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
   SOFTWARE.
*/
#include "FS.h"
#include <Arduino.h>
#include <BLE2902.h>
#include <BLEDevice.h>
#include <BLEServer.h>
#include <BLEUtils.h>
#include <Update.h>

// #define DEBUG_BLE_OTA_DFU_TX
// #define DEBUG_BLE_OTA_DFU_RX
const uint8_t BUILTIN_LED = 2;

const bool FORMAT_FLASH_IF_MOUNT_FAILED = true;

#define USE_SPIFFS // comment to use FFat

#ifdef USE_SPIFFS
// SPIFFS write is slower
#include "SPIFFS.h"
#define FLASH SPIFFS
const bool FASTMODE = false;
#else
// FFat is faster
#include "FFat.h"
#define FLASH FFat
const bool FASTMODE = true;
#endif

// enum mode { OTA_IDLE = 0, OTA_UPLOAD, OTA_INSTALL };

const char SERVICE_UUID[] = "fe590001-54ae-4a28-9f74-dfccb248601d";
const char CHARACTERISTIC_UUID_RX[] = "fe590002-54ae-4a28-9f74-dfccb248601d";
const char CHARACTERISTIC_UUID_TX[] = "fe590003-54ae-4a28-9f74-dfccb248601d";

BLECharacteristic *pCharacteristicTX;
BLECharacteristic *pCharacteristicRX;

bool device_connected = false;

void reboot_ESP_with_reason(String reason) {
  ESP_LOGI(TAG, "Rebooting ESP32 with reason: %s", reason.c_str());
  delay(5000);
  ESP.restart();
}

uint16_t write_binary(fs::FS &file_system, const char *path, uint8_t *data,
                      uint16_t length) {
  // Append data to the file
  ESP_LOGI(TAG, "Write binary file %s\r\n", path);
  File file = file_system.open(path, FILE_APPEND);

  if (!file) {
    ESP_LOGE(TAG, "Failed to open the file to write");
    return 0;
  }

  file.write(data, length);
  file.close();
  return length;
}

void perform_update(Stream &update_stream, size_t update_size) {
  String result = (String)(char)0x0F;
  // Init update
  if (Update.begin(update_size)) {
    // Perform the update
    size_t written = Update.writeStream(update_stream);
    if (written == update_size) {
      ESP_LOGI(TAG, "Written: %d successfully", written);
    } else {
      ESP_LOGI(TAG, "Written: %d/%d. Retry?", written, update_size);
    }
    result += "Written : " + String(written) + "/" + String(update_size) +
              " [" + String((written / update_size) * 100) + " %] \n";

    // Check update
    if (Update.end()) {
      ESP_LOGI(TAG, "OTA done!");
      result += "OTA Done: ";
      if (Update.isFinished()) {
        ESP_LOGI(TAG, "Update successfully completed. Rebooting...");
        result += "Success!\n";
      } else {
        ESP_LOGE(TAG, "Update not finished? Something went wrong!");
        result += "Failed!\n";
      }
    } else {
      Serial.println("Error Occurred. Error #: " + String(Update.getError()));
      result += "Error #: " + String(Update.getError());
    }
  } else {
    ESP_LOGE(TAG, "Not enough space to begin BLE OTA DFU");
    result += "Not enough space to begin BLE OTA DFU";
  }

  if (device_connected) {
    // Return the result to the client (tells the client if the update was a
    // success or not)
    pCharacteristicTX->setValue(result.c_str());
    pCharacteristicTX->notify();
    delay(10);
    delay(5000);
  }
}

void update_from_FS(fs::FS &file_system) {
  // Update the board from the flash.

  // Open update.bin file.
  File update_binary = file_system.open("/update.bin");

  // If the file can be loaded
  if (update_binary) {
    // Verify that the file is not a directory
    if (update_binary.isDirectory()) {
      ESP_LOGE(TAG, "Error, update.bin is not a file");
      update_binary.close();
      return;
    }

    // Get binary file size
    size_t update_size = update_binary.size();

    // Proceed to the update if the file is not empty
    if (update_size > 0) {
      ESP_LOGI(TAG, "Trying to start update");
      perform_update(update_binary, update_size);
    } else {
      ESP_LOGE(TAG, "Error, update file is empty");
    }

    update_binary.close();

    // When finished remove the binary from spiffs
    // to indicate the end of the process
    ESP_LOGI(TAG, "Removing update file");
    file_system.remove("/update.bin");

    reboot_ESP_with_reason("complete OTA update");
  } else {
    ESP_LOGE(TAG, "Could not load update.bin from spiffs root");
  }
}

void task_install_update(void *parameters) {
  delay(5000);
  update_from_FS(FLASH);
  ESP_LOGI(TAG, "Installation is complete");
}

class MyServerCallbacks : public BLEServerCallbacks {
  // Somehow generic
  void onConnect(BLEServer *pServer) { device_connected = true; }
  void onDisconnect(BLEServer *pServer) { device_connected = false; }
};

class BLEOverTheAirDeviceFirmwareUpdate : public BLECharacteristicCallbacks {
private:
  bool selected_updater = true;
  uint8_t updater[2][16384];
  uint16_t write_len[2] = {0, 0};
  uint16_t parts = 0, MTU = 0;
  uint16_t current_progression = 0;
  uint32_t received_file_size, expected_file_size;
  //    void onStatus(BLECharacteristic* pCharacteristic, Status s, uint32_t
  //    code) {
  //      Serial.print("Status ");
  //      Serial.print(s);
  //      Serial.print(" on characteristic ");
  //      Serial.print(pCharacteristic->getUUID().toString().c_str());
  //      Serial.print(" with code ");
  //      Serial.println(code);
  //    }
public:
  void onNotify(BLECharacteristic *pCharacteristic) {
#ifdef DEBUG_BLE_OTA_DFU_TX
    uint8_t *pData;
    std::string value = pCharacteristic->getValue();
    uint16_t len = value.length();
    pData = pCharacteristic->getData();
    if (pData != NULL) {
      ESP_LOGD(TAG, "Notify callback for characteristic %s  of data length %d",
               pCharacteristic->getUUID().toString().c_str(), len);

      // Print transferred packets
      Serial.print("TX  ");
      for (uint16_t i = 0; i < len; i++) {
        Serial.printf("%02X ", pData[i]);
      }
      Serial.println();
    }
#endif
  }

  void onWrite(BLECharacteristic *pCharacteristic) {
    uint8_t *pData;
    std::string value = pCharacteristic->getValue();
    uint16_t len = value.length();
    pData = pCharacteristic->getData();

    if (pData != NULL) { // Check that data have been received
#ifdef DEBUG_BLE_OTA_DFU_RX
      ESP_LOGD(TAG, "Write callback for characteristic %s  of data length %d",
               pCharacteristic->getUUID().toString().c_str(), len);
      Serial.print("RX  ");
      for (int i = 0; i < len; i++) {
        Serial.printf("%02X ", pData[i]);
      }
      Serial.println();
#endif
      switch (pData[0]) {
      case 0xEF: { // Format the flash and send total and used sizes
        FLASH.format();

        // Send flash size
        uint16_t total_size = FLASH.totalBytes();
        uint16_t used_size = FLASH.usedBytes();
        uint8_t flash_size[] = {0xEF,
                                (uint8_t)(total_size >> 16),
                                (uint8_t)(total_size >> 8),
                                (uint8_t)total_size,
                                (uint8_t)(used_size >> 16),
                                (uint8_t)(used_size >> 8),
                                (uint8_t)used_size};
        pCharacteristicTX->setValue(flash_size, 7);
        pCharacteristicTX->notify();
        delay(10);
      } break;

      case 0xFB: // Write parts to RAM
        // pData[1] is the position of the next part
        for (uint16_t index = 0; index < len - 2; index++) {
          updater[!selected_updater][(pData[1] * MTU) + index] =
              pData[index + 2];
        }
        break;

      case 0xFC: { // Write updater content to the flash
        selected_updater = !selected_updater;
        write_len[selected_updater] = (pData[1] * 256) + pData[2];
        current_progression = (pData[3] * 256) + pData[4];

        received_file_size +=
            write_binary(FLASH, "/update.bin", updater[selected_updater],
                         write_len[selected_updater]);

        if ((current_progression < parts - 1) && !FASTMODE) {
          uint8_t progression[] = {0xF1,
                                   (uint8_t)((current_progression + 1) / 256),
                                   (uint8_t)((current_progression + 1) % 256)};
          pCharacteristicTX->setValue(progression, 3);
          pCharacteristicTX->notify();
          delay(10);
        }

        ESP_LOGI(TAG, "Upload progress: %d/%d", current_progression + 1, parts);
        if (current_progression + 1 == parts) {
          // If all the file has been received, send the progression
          uint8_t progression[] = {0xF2,
                                   (uint8_t)((current_progression + 1) / 256),
                                   (uint8_t)((current_progression + 1) % 256)};
          pCharacteristicTX->setValue(progression, 3);
          pCharacteristicTX->notify();
          delay(10);

          if (received_file_size != expected_file_size) {
            received_file_size +=
                write_binary(FLASH, "/update.bin", updater[selected_updater],
                             write_len[selected_updater]);

            if (received_file_size > expected_file_size) {
              ESP_LOGW(TAG, "Unexpected size:\n Expected: %d\nReceived: %d",
                       expected_file_size, received_file_size);
            }

          } else {
            ESP_LOGI(TAG, "Installing update");
            xTaskCreate(task_install_update, "task_install_update", 8192, NULL,
                        5, NULL);
          }
        }
      } break;

      case 0xFD: // Remove previous file and send transfer mode
      {
        // Remove previous (failed?) update
        if (FLASH.exists("/update.bin")) {
          ESP_LOGI(TAG, "Removing previous update");
          FLASH.remove("/update.bin");
        }

        // Send mode ("fast" or "slow")
        uint8_t mode[] = {0xAA, FASTMODE};
        pCharacteristicTX->setValue(mode, 2);
        pCharacteristicTX->notify();
        delay(10);
      } break;

      case 0xFE: // Keep track of the received file and of the expected file
                 // sizes
        received_file_size = 0;
        expected_file_size = (pData[1] * 16777216) + (pData[2] * 65536) +
                             (pData[3] * 256) + pData[4];

        ESP_LOGI(TAG, "Available space: %d\nFile Size: %d\n",
                 FLASH.totalBytes() - FLASH.usedBytes(), expected_file_size);
        break;

      case 0xFF: // Switch to update mode
        parts = (pData[1] * 256) + pData[2];
        MTU = (pData[3] * 256) + pData[4];
        break;

      default:
        ESP_LOGW(TAG, "Unknown command: %02X", pData[0]);
        break;
      }
    }
    delay(1);
  }
};

void initBLE() {
  BLEDevice::init("ESP32 OTA");
  BLEServer *pServer = BLEDevice::createServer();
  pServer->setCallbacks(new MyServerCallbacks());

  BLEService *pService = pServer->createService(SERVICE_UUID);
  pCharacteristicTX = pService->createCharacteristic(
      CHARACTERISTIC_UUID_TX, BLECharacteristic::PROPERTY_NOTIFY);
  pCharacteristicRX = pService->createCharacteristic(
      CHARACTERISTIC_UUID_RX,
      BLECharacteristic::PROPERTY_WRITE | BLECharacteristic::PROPERTY_WRITE_NR);
  pCharacteristicRX->setCallbacks(new BLEOverTheAirDeviceFirmwareUpdate());
  pCharacteristicTX->setCallbacks(new BLEOverTheAirDeviceFirmwareUpdate());
  pCharacteristicTX->addDescriptor(new BLE2902());
  pCharacteristicTX->setNotifyProperty(true);
  pService->start();

  // BLEAdvertising *pAdvertising = pServer->getAdvertising();
  // The above is still working for backward compatibility
  BLEAdvertising *pAdvertising = BLEDevice::getAdvertising();
  pAdvertising->addServiceUUID(SERVICE_UUID);
  pAdvertising->setScanResponse(true);
  // functions that help with iPhone connections issue
  pAdvertising->setMinPreferred(0x06);
  pAdvertising->setMinPreferred(0x12);
  BLEDevice::startAdvertising();
  Serial.println("Characteristic defined! Now you can read it in your phone!");
}

void setup() {
  Serial.begin(115200);
  Serial.println("Starting BLE OTA sketch");

  pinMode(BUILTIN_LED, OUTPUT);

#ifdef USE_SPIFFS
  if (!SPIFFS.begin(FORMAT_FLASH_IF_MOUNT_FAILED)) {
    Serial.println("SPIFFS Mount Failed");
    return;
  }
#else
  if (!FFat.begin()) {
    Serial.println("FFat Mount Failed");
    if (FORMAT_FLASH_IF_MOUNT_FAILED)
      FFat.format();
    return;
  }
#endif

  initBLE();
}

void loop() {
  // switch (mode) {
  // case OTA_IDLE:
  //   if (device_connected) {
  //     digitalWrite(BUILTIN_LED, HIGH);
  //     delay(100);
  //     // your loop code here (if a client is needed)
  //   } else {
  //     digitalWrite(BUILTIN_LED, LOW);
  //     delay(500);
  //   }
  //   // or here (if no client is needed)
  //   break;

  // case OTA_UPLOAD:
  //   break;

  // case OTA_INSTALL:
  //   break;
  // }
  delay(100); // Try to increase stability
}
"""
  
MIT License

Copyright (c) 2021 Felix Biego

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
"""

from __future__ import print_function
import os
import asyncio
import math
import sys
import re

from bleak import BleakClient, BleakScanner
# from bleak.exc import BleakError

header = """#####################################################################
    ------------------------BLE OTA update---------------------
    Arduino code @ https://github.com/fbiego/ESP32_BLE_OTA_Arduino
#####################################################################"""

UART_SERVICE_UUID = "fe590001-54ae-4a28-9f74-dfccb248601d"
UART_RX_CHAR_UUID = "fe590002-54ae-4a28-9f74-dfccb248601d"
UART_TX_CHAR_UUID = "fe590003-54ae-4a28-9f74-dfccb248601d"

PART = 16000
MTU = 500

ble_ota_dfu_end = False
global_client = None
file_bytes = None
total = 0


async def start_ota(ble_address: str, filename: str):
    device = await BleakScanner.find_device_by_address(ble_address, timeout=20.0)
    disconnected_event = asyncio.Event()

    def handle_disconnect(_: BleakClient):
        print("Device disconnected !")
        disconnected_event.set()

    async def handle_rx(_: int, data: bytearray):
        # print(f'\nReceived: {data = }\n')
        match data[0]:
            case 0xAA:
                print("Starting transfer, mode:", data[1])
                print_progress_bar(0, total, prefix='Upload progress:',
                                   suffix='Complete', length=50)

                match data[1]:
                    case 0:  # Slow mode
                        # Send first part
                        await send_part(0, file_bytes, global_client)
                    case 1:  # Fast mode
                        for index in range(file_parts):
                            await send_part(index, file_bytes, global_client)
                            print_progress_bar(index + 1, total,
                                               prefix='Upload progress:',
                                               suffix='Complete', length=50)

            case 0xF1:  # Send next part and update progress bar
                next_part_to_send = int.from_bytes(
                    data[2:3], byteorder='little')
                # print("Next part:", next_part_to_send, "\n")
                await send_part(next_part_to_send, file_bytes, global_client)
                print_progress_bar(next_part_to_send + 1, total,
                                   prefix='Upload progress:',
                                   suffix='Complete', length=50)

            case 0xF2:  # Install firmware
                # ins = 'Installing firmware'
                # print("Installing firmware")
                pass

            case 0x0F:
                print("OTA result: ", str(data[1:], 'utf-8'))
                global ble_ota_dfu_end
                ble_ota_dfu_end = True

    def print_progress_bar(iteration: int, total: int, prefix: str = '', suffix: str = '', decimals: int = 1, length: int = 100, filler: str = 'โ–ˆ', print_end: str = "\r"):
        """
        Call in a loop to create terminal progress bar
        @params:
            iteration   - Required  : current iteration (Int)
            total       - Required  : total iterations (Int)
            prefix      - Optional  : prefix string (Str)
            suffix      - Optional  : suffix string (Str)
            decimals    - Optional  : positive number of decimals in percent complete (Int)
            length      - Optional  : character length of bar (Int)
            filler      - Optional  : bar fill character (Str)
            print_end   - Optional  : end character (e.g. "\r", "\r\n") (Str)
        """
        percent = ("{0:." + str(decimals) + "f}").format(100 *
                                                         (iteration / float(total)))
        filled_length = (length * iteration) // total
        bar = filler * filled_length + '-' * (length - filled_length)
        print(f'\r{prefix} |{bar}| {percent}ย % {suffix}', end=print_end)
        # Print new line upon complete
        if iteration == total:
            print()

    async def send_part(position: int, data: bytearray, client: BleakClient):
        start = position * PART
        end = (position + 1) * PART

        if len(data) < end:
            end = len(data)

        data_length = end - start
        parts = data_length // MTU
        for part_index in range(parts):
            to_be_sent = bytearray([0xFB, part_index])
            for mtu_index in range(MTU):
                to_be_sent.append(
                    data[(position*PART)+(MTU * part_index) + mtu_index])
            await send_data(client, to_be_sent)

        if data_length % MTU:
            remaining = data_length % MTU
            to_be_sent = bytearray([0xFB, parts])
            for index in range(remaining):
                to_be_sent.append(
                    data[(position*PART)+(MTU * parts) + index])
            await send_data(client, to_be_sent)

        await send_data(client, bytearray([0xFC, data_length//256, data_length %
                                           256, position//256, position % 256]), True)

    async def send_data(client: BleakClient, data: bytearray, response: bool = False):
        await client.write_gatt_char(UART_RX_CHAR_UUID, data, response)

    if not device:
        print("-----------Failed--------------")
        print(f"Device with address {ble_address} could not be found.")
        return
        #raise BleakError(f"A device with address {ble_address} could not be found.")

    async with BleakClient(device, disconnected_callback=handle_disconnect) as client:
        # Set the UUID of the service you want to connect to and the callback
        await client.start_notify(UART_TX_CHAR_UUID, handle_rx)
        await asyncio.sleep(1.0)

        # Set global client to be the current client
        global global_client
        global_client = client

        # Send file size
        print("Reading from: ", filename)
        global file_bytes
        file_bytes = open(filename, "rb").read()
        file_parts = math.ceil(len(file_bytes) / PART)
        file_length = len(file_bytes)

        print(f'File size: {len(file_bytes)}')
        # Send file length
        await send_data(client, bytearray([0xFE,
                                           file_length >> 24 & 0xFF,
                                           file_length >> 16 & 0xFF,
                                           file_length >> 8 & 0xFF,
                                           file_length & 0xFF]))

        # Send number of part and MTU value
        global total
        total = file_parts

        await send_data(client, bytearray([0xFF,
                                           file_parts//256,
                                           file_parts % 256,
                                           MTU // 256,
                                           MTU % 256]))

        # Remove previous update and receive transfer mode (start the update)
        await send_data(client, bytearray([0xFD]))

        # Wait til upload is complete
        while not ble_ota_dfu_end:
            await asyncio.sleep(1.0)

        print("Waiting for disconnect... ", end="")

        await disconnected_event.wait()
        print("-----------Complete--------------")


def is_valid_address(value: str = None) -> bool:
    # Regex to check valid MAC address
    regex_0 = (r"^([0-9A-Fa-f]{2}[:-])"
               r"{5}([0-9A-Fa-f]{2})|"
               r"([0-9a-fA-F]{4}\\."
               r"[0-9a-fA-F]{4}\\."
               r"[0-9a-fA-F]{4}){17}$")
    regex_1 = (r"^[{]?[0-9a-fA-F]{8}"
               r"-([0-9a-fA-F]{4}-)"
               r"{3}[0-9a-fA-F]{12}[}]?$")

    # Compile the ReGex
    regex_0 = re.compile(regex_0)
    regex_1 = re.compile(regex_1)

    # If the string is empty return false
    if value is None:
        return False

    # Return if the string matched the ReGex
    if re.search(regex_0, value) and len(value) == 17:
        return True

    return re.search(regex_1, value) and len(value) == 36


if __name__ == "__main__":
    print(header)
    # Check if the user has entered enough arguments
    # sys.argv.append("C8:C9:A3:D2:60:8E")
    # sys.argv.append("firmware.bin")

    if len(sys.argv) < 3:
        print("Specify the device address and firmware file")
        import sys
        import os
        filename = os.path.join(os.path.dirname(
            __file__), 'PIO', 'ESP32_BLE_OTA_DFU', '.pio', 'build', 'esp32dev', 'firmware.bin')
        filename = filename if os.path.exists(filename) else "firmware.bin"
        print(f"$ {sys.executable} {__file__} \"C8:C9:A3:D2:60:8E\" \"{filename}\"")
        exit(1)

    print("Trying to start OTA update")
    ble_address = sys.argv[1]
    filename = sys.argv[2]

    # Check if the address is valid
    if not is_valid_address(ble_address):
        print(f"Invalid Address: {ble_address}")
        exit(2)

    # Check if the file exists
    if not os.path.exists(filename):
        print(f"File not found: {filename}")
        exit(3)

    asyncio.run(start_ota(ble_address, filename))

Best,
Vincent

Hexadecimal meaning

I found decition with "if()" that compare with Hexadecimal numbers. I know that number are recived by the Android. But what it these mean?
0xAA, 0xEF, 0xF1, 0xF2, 0xFB, 0xFC, 0xFD, 0xFE, 0xFF, 0xEF, 0x0F

Problem with initial flashing

Hello,
I am able to connect to my device using the Mobile App
I'm getting BT_SMP errors.

When connected the device terminal responds with:

Advertising BLE...
BLE APP connected...
Stopped advertising BLE...
Advertising BLE...
E (225670) BT_SMP: smp_calculate_link_key_from_long_term_key failed to update link_key. Sec Mode = 2, sm4 = 0x00
E (225670) BT_SMP: smp_derive_link_key_from_long_term_key failed

E (225677) BT_BTM: btm_proc_smp_cback received for unknown device
E (228839) BT_BTM: Device not found

BLE APP disconnected...
====================================== [SUCCESS] Took 568.16 seconds ======================================

The settings on the device are

#define USE_SPIFFS  //comment to use FFat

  #ifdef USE_SPIFFS
  #define FLASH SPIFFS
  #define FASTMODE false    //SPIFFS write is slow
  #else
  #define FLASH FFat
  #define FASTMODE true    //FFat is faster

Im not sure if USE_SPIFFS is correct ?

esp32_ble_ota getting Incomplete while ota

Hi,
I am running the esp32_ble_ota code on my esp32 cam board, I have flashed the esp32_ble_ota arduino sketch on my esp32 cam board and then uploaded the bin file using the anrdoid app. In android its is showing file transfered 100%, but in serial monitor it is showing "Incomplete Available space: 603153 File Size: 16596862"
In arduino ide I have selected the following from tools tab Partition Scheme as Default 4MB with spiffs(1.2MBAPP/1.5MB SPIFFS), Board as ESP32 Dev Module.
even I have tried with esp32_nim_ble_ota code too ,but is connecting and immediately getting disconnecting.
I have attached serial monitor log for esp32_ble_ota, I am not able to find the problem

serial monitor log:

ets Jun 8 2016 00:22:57

rst:0x1 (POWERON_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
configsip: 0, SPIWP:0xee
clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
mode:DIO, clock div:1
load:0x3fff0018,len:4
load:0x3fff001c,len:1216
ho 0 tail 12 room 4
load:0x40078000,len:10944
load:0x40080400,len:6388
entry 0x400806b4
Starting BLE OTA sketch
Characteristic defined! Now you can read it in your phone!
TX AA 00
TX F1 00 01
TX F1 00 02
TX F1 00 03
TX F1 00 04
TX F1 00 05
TX F1 00 06
TX F1 00 07
TX F1 00 08
TX F1 00 09
TX F1 00 0A
TX F1 00 0B
TX F1 00 0C
TX F1 00 0D
TX F1 00 0E
TX F1 00 0F
TX F1 00 10
TX F1 00 11
TX F1 00 12
TX F1 00 13
TX F1 00 14
TX F1 00 15
TX F1 00 16
TX F1 00 17
TX F1 00 18
TX F1 00 19
TX F1 00 1A
TX F1 00 1B
TX F1 00 1C
TX F1 00 1D
TX F1 00 1E
TX F1 00 1F
TX F1 00 20
TX F1 00 21
TX F1 00 22
TX F1 00 23
TX F1 00 24
TX F1 00 25
TX F1 00 26
TX F1 00 27
TX F1 00 28
TX F1 00 29
TX F1 00 2A
TX F1 00 2B
TX F1 00 2C
TX F1 00 2D
TX F1 00 2E
TX F2 00 2F
Incomplete
Available space: 603153
File Size: 16596862
Incomplete
Incomplete
Incomplete

Getting error while using the python script

I am getting Error #
without more details.

It does not flash it.

#####################################################################
------------------------BLE OTA update---------------------
Arduino code @ https://github.com/fbiego/ESP32_BLE_OTA_Arduino
#####################################################################
Trying to start OTA update
Reading from: firmware.bin
Transfer mode: 0
Progress: |โ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆ| 100.0% Complete
Installing firmware
OTA result: Written : 160000/160000 [100%]
Error #:
Waiting for disconnect... : Device disconnected

ESP32 not detecting in Android, Poco M2 Pro

I am newbie and trying to test this code, but in the phone, after app start it searches for device then nothing shows except Search again button and the button press shows the same result again, thanks

How to add ota function

I am trying to update my code via OTA and i was confused about how to go about that
firstly
when i try the serial upload i have 4 bin files (bootloader, partitions, main code etc)
when i am trying to do ota which bin file should i be uploading( i am guessing only the main code bin)
in the code provided, once the data packet is recieved, addresses have been defined like (pData[0] == 0xFB)
what does 0xFB stand for(like corrposponding to which address)
other addresses given are
0xFC
0xFD
0xFE
if i could get some clarity on that i would be really greatful as i am new to iot and ble implementaitons

NimBLE

This is not a real issue...more a Feature Request

i ported your ESP32 Code to the ESP32 NimBLE Stack: https://github.com/h2zero/NimBLE-Arduino

first i had an issue with the CRC of the update File, so the Update failed.

Because of this issue i changed the FS to SD Card (SPI Mode) and compared both files.
They are exactly the same and the Update with SD Card is successful.

Now the more Interesting Part:
The Transfer of around 1,2MB Update File was done in 29 Seconds (SD Card) and 43Seconds to FFAT.
And the NimBLE Stack takes less flash Space
605978 Bytes (46%) with NimBLE Stack
1031430 Bytes (78%) with ESP32 BLE Stack

Maybe someone knows the reson for failed Checksum when using FFAT?
Trying to start update
Written : 1188512 successfully
E (73242) esp_image: Checksum failed. Calculated 0xd1 read 0x0
Error Occurred. Error #: 9

Here is the changed code:

#include <Update.h>
#include "FS.h"
#include "FFat.h"
#include "SPIFFS.h"
//#include <SD.h>
//#include <BLEDevice.h>
//#include <BLEUtils.h>
//#include <BLEServer.h>
//#include <BLE2902.h>

#include <NimBLEDevice.h>

#define BUILTINLED 2
#define FORMAT_SPIFFS_IF_FAILED true
#define FORMAT_FFAT_IF_FAILED true

//#define USE_SPIFFS  //comment to use FFat

#ifdef USE_SPIFFS
#define FLASH SPIFFS
#define FASTMODE false    //SPIFFS write is slow
#else
#define FLASH FFat
#define FASTMODE true    //FFat is faster
#endif

#define NORMAL_MODE   0   // normal
#define UPDATE_MODE   1   // receiving firmware
#define OTA_MODE      2   // installing firmware

uint8_t updater[16384];
uint8_t updater2[16384];

#define SERVICE_UUID              "fb1e4001-54ae-4a28-9f74-dfccb248601d"
#define CHARACTERISTIC_UUID_RX    "fb1e4002-54ae-4a28-9f74-dfccb248601d"
#define CHARACTERISTIC_UUID_TX    "fb1e4003-54ae-4a28-9f74-dfccb248601d"

static BLECharacteristic* pCharacteristicTX;
static BLECharacteristic* pCharacteristicRX;

static bool deviceConnected = false, sendMode = false;
static bool writeFile = false, request = false;
static int writeLen = 0, writeLen2 = 0;
static bool current = true;
static int parts = 0, next = 0, cur = 0, MTU = 0;
static int MODE = NORMAL_MODE;

static void rebootEspWithReason(String reason) {
  Serial.println(reason);
  delay(1000);
  ESP.restart();
}

class MyServerCallbacks: public BLEServerCallbacks {
    void onConnect(BLEServer* pServer) {
      Serial.println("Connected");
      deviceConnected = true;

    }
    void onDisconnect(BLEServer* pServer) {
      Serial.println("disconnected");
      deviceConnected = false;
    }
};

class MyCallbacks: public BLECharacteristicCallbacks {

    //    void onStatus(BLECharacteristic* pCharacteristic, Status s, uint32_t code) {
    //      Serial.print("Status ");
    //      Serial.print(s);
    //      Serial.print(" on characteristic ");
    //      Serial.print(pCharacteristic->getUUID().toString().c_str());
    //      Serial.print(" with code ");
    //      Serial.println(code);
    //    }

    void onRead(BLECharacteristic* pCharacteristic){
        Serial.print(pCharacteristic->getUUID().toString().c_str());
        Serial.print(": onRead(), value: ");
        Serial.println(pCharacteristic->getValue().c_str());
    };

    void onNotify(BLECharacteristic *pCharacteristic) {
      //uint8_t* pData;
      std::string pData = pCharacteristic->getValue();
      int len = pData.length();
      //pData = pCharacteristic->getData();
      //if (pData != NULL) {
        //        Serial.print("Notify callback for characteristic ");
        //        Serial.print(pCharacteristic->getUUID().toString().c_str());
        //        Serial.print(" of data length ");
        //        Serial.println(len);
        Serial.print("TX  ");
        for (int i = 0; i < len; i++) {
          Serial.printf("%02X ", pData[i]);
        }
        Serial.println();
     // }
    }

    void onWrite(BLECharacteristic *pCharacteristic) {
      //uint8_t* pData;
      std::string pData = pCharacteristic->getValue();
      int len = pData.length();
      //pData = pCharacteristic->getData();
      //if (pData != NULL) {
               // Serial.print("Write callback for characteristic ");
               // Serial.print(pCharacteristic->getUUID().toString().c_str());
               // Serial.print(" of data length ");
               // Serial.println(len);
               // Serial.print("RX  ");
               // for (int i = 0; i < len; i++) {         // leave this commented
               //   Serial.printf("%02X ", pData[i]);
               // }
               // Serial.println();

        if (pData[0] == 0xFB) {
          int pos = pData[1];
          for (int x = 0; x < len - 2; x++) {
            if (current) {
              updater[(pos * MTU) + x] = pData[x + 2];
            } else {
              updater2[(pos * MTU) + x] = pData[x + 2];
            }
          }

        } else if  (pData[0] == 0xFC) {
          if (current) {
            writeLen = (pData[1] * 256) + pData[2];
          } else {
            writeLen2 = (pData[1] * 256) + pData[2];
          }
          current = !current;
          cur = (pData[3] * 256) + pData[4];
          writeFile = true;
          if (cur < parts - 1) {
            request = !FASTMODE;
          }
        } else if (pData[0] == 0xFD) {
          sendMode = true;
          if (FLASH.exists("/update.bin")) {
            FLASH.remove("/update.bin");
          }
        } else if  (pData[0] == 0xFF) {
          parts = (pData[1] * 256) + pData[2];
          MTU = (pData[3] * 256) + pData[4];
          MODE = UPDATE_MODE;

        }


      //}

    }


};

static void writeBinary(fs::FS &fs, const char * path, uint8_t *dat, int len) {

  //Serial.printf("Write binary file %s\r\n", path);

  File file = fs.open(path, FILE_APPEND);

  if (!file) {
    Serial.println("- failed to open file for writing");
    return;
  }
  file.write(dat, len);
  file.close();
}

void initBLE() {
  BLEDevice::init("SBBUA");
  BLEDevice::setMTU(517);
  BLEDevice::setPower(ESP_PWR_LVL_P9);
  BLEServer *pServer = BLEDevice::createServer();
  pServer->setCallbacks(new MyServerCallbacks());

  BLEService *pService = pServer->createService(SERVICE_UUID);
  pCharacteristicTX = pService->createCharacteristic(CHARACTERISTIC_UUID_TX, NIMBLE_PROPERTY::NOTIFY | NIMBLE_PROPERTY::READ );
  pCharacteristicRX = pService->createCharacteristic(CHARACTERISTIC_UUID_RX, NIMBLE_PROPERTY::WRITE | NIMBLE_PROPERTY::READ| NIMBLE_PROPERTY::WRITE_NR);
  pCharacteristicRX->setCallbacks(new MyCallbacks());
  pCharacteristicTX->setCallbacks(new MyCallbacks());
  //pCharacteristicTX->addDescriptor(new BLE2902());
  //pCharacteristicTX->setNotifyProperty(true);
  pService->start();
  pServer->start();

  // BLEAdvertising *pAdvertising = pServer->getAdvertising();  // this still is working for backward compatibility
  NimBLEAdvertising *pAdvertising = BLEDevice::getAdvertising();
  pAdvertising->addServiceUUID(SERVICE_UUID);
  pAdvertising->setScanResponse(true);
  pAdvertising->setMinPreferred(0x06);  // functions that help with iPhone connections issue
  pAdvertising->setMinPreferred(0x12);
  pAdvertising->start();
  //BLEDevice::startAdvertising();
  Serial.println("Characteristic defined! Now you can read it in your phone!");
}

void setup() {
  Serial.begin(115200);
  Serial.println("Starting BLE OTA sketch");
  //pinMode(BUILTINLED, OUTPUT);

  //SPI.begin(18, 22, 23, 5);
  //SD.begin(5);

#ifdef USE_SPIFFS
  if (!SPIFFS.begin(FORMAT_SPIFFS_IF_FAILED)) {
    Serial.println("SPIFFS Mount Failed");
    return;
  }
#else
  if (!FFat.begin()) {
    Serial.println("FFat Mount Failed");
    if (FORMAT_FFAT_IF_FAILED) FFat.format();
    return;
  }
#endif


  initBLE();

}

void loop() {

  switch (MODE) {

    case NORMAL_MODE:
      if (deviceConnected) {
        //digitalWrite(BUILTINLED, HIGH);
        if (sendMode) {
          uint8_t fMode[] = {0xAA, FASTMODE};
          pCharacteristicTX->setValue(fMode, 2);
          pCharacteristicTX->notify();
          delay(50);
          sendMode = false;
        }

        // your loop code here 
      } else {
        //digitalWrite(BUILTINLED, LOW);
      }

      // or here

      break;

    case UPDATE_MODE:

      if (request) {
        uint8_t rq[] = {0xF1, (cur + 1) / 256, (cur + 1) % 256};
        pCharacteristicTX->setValue(rq, 3);
        pCharacteristicTX->notify();
        delay(50);
        request = false;
      }

      if (cur + 1 == parts) { // received complete file
        uint8_t com[] = {0xF2, (cur + 1) / 256, (cur + 1) % 256};
        pCharacteristicTX->setValue(com, 3);
        pCharacteristicTX->notify();
        delay(50);
        MODE = OTA_MODE;
      }

      if (writeFile) {
        if (!current) {
          writeBinary(FLASH, "/update.bin", updater, writeLen);
        } else {
          writeBinary(FLASH, "/update.bin", updater2, writeLen2);
        }
        writeFile = false;
      }

      break;

    case OTA_MODE:
        updateFromFS(FLASH);
      break;

  }

}

void sendOtaResult(String result) {
  pCharacteristicTX->setValue(result.c_str());
  pCharacteristicTX->notify();
  delay(200);
}


void performUpdate(Stream &updateSource, size_t updateSize) {
  char s1 = 0x0F;
  String result = String(s1);
  if (Update.begin(updateSize)) {
    size_t written = Update.writeStream(updateSource);
    if (written == updateSize) {
      Serial.println("Written : " + String(written) + " successfully");
    }
    else {
      Serial.println("Written only : " + String(written) + "/" + String(updateSize) + ". Retry?");
    }
    result += "Written : " + String(written) + "/" + String(updateSize) + " [" + String((written / updateSize) * 100) + "%] \n";
    if (Update.end()) {
      Serial.println("OTA done!");
      result += "OTA Done: ";
      if (Update.isFinished()) {
        Serial.println("Update successfully completed. Rebooting...");
        result += "Success!\n";
      }
      else {
        Serial.println("Update not finished? Something went wrong!");
        result += "Failed!\n";
      }

    }
    else {
      Serial.println("Error Occurred. Error #: " + String(Update.getError()));
      result += "Error #: " + String(Update.getError());
    }
  }
  else
  {
    Serial.println("Not enough space to begin OTA");
    result += "Not enough space for OTA";
  }
  if (deviceConnected) {
    sendOtaResult(result);
    delay(5000);
  }
}

void updateFromFS(fs::FS &fs) {
  File updateBin = fs.open("/update.bin");
  if (updateBin) {
    if (updateBin.isDirectory()) {
      Serial.println("Error, update.bin is not a file");
      updateBin.close();
      return;
    }

    size_t updateSize = updateBin.size();

    if (updateSize > 0) {
      Serial.println("Trying to start update");
      performUpdate(updateBin, updateSize);
    }
    else {
      Serial.println("Error, file is empty");
    }

    updateBin.close();

    // when finished remove the binary from spiffs to indicate end of the process
    //Serial.println("Removing update file");
    //fs.remove("/update.bin");

    rebootEspWithReason("Rebooting to complete OTA update");
  }
  else {
    Serial.println("Could not load update.bin from spiffs root");
  }
}

Problem f1 reply

hello, i'm try to user part of your code to do the ota update from an ionic app and an esp32
i'm writing the android part as new in angular and ionic, but the arduino esp32 part i'll try to use the most to test if it works, and now i'm avaing some issue,
i've managed to send the version of the esp32 at setup, on the app i'll check it and if it's different i'll start the update process,
i'll send an 0xFD to format the SPIFFS,
after that i'll send an 0xFF with the size and total number of packets
after that i'll send 0xFB with the number of the packet and the part of the firmware file itself
then i'll send 0xFC with the size of the packet and the number of that packet
at this point the esp32 should send 0xF1 to android, but here it's my issue the loop, when it enter the updating if and the request if, i will receive 0 0 on andorid
(i've tried sent again the version instead of 0xF1 but still i receive 0 0, because i was thinkig about some issue on the data structure on the rq variable)

any idea why that is happening ?

thanks

Error#9

I trying to update the firmware ,but i recive the Error#9. and the esp32 start again. How can i fix it?

Can't connect to the ESP32

I try to use the code ,and the app. I can select the Firmware file, but i can select de device.

  1. I select the "Chose" button
  2. Show me the name ESP32 OTA, and i select it.
  3. I wait but nothing happen
  4. After 5 seconds, the app closes.

So i can't update the ESP32 for that. Could you help me?

Is there a way to use classic BT instead of BLE to receive the file?

I'm worrying about the file transfer speed of BLE, so I'd like to use classic BT to receive the file. But I've seen no reference about OBEX or OPP or FTP on classic BT. Right now I can only send files in stupid SPP way.

It is better for me to use the OS native way to send the file (e.g. Android blutooth sharing & Windows bluetooth transfer)
Could you please tell me what I can refer to, or this is totally impossible for now?

App V1-2 no connection

i tried your actual Example with APK V1.2

i could get it working -> Very Nice Job!

BUT: i had to use V1.1 to set the mac adress/Pairing and then install V1.2

If you use a fresh installed V1.2 you cant connect to ESP32.
Just saying "Setup Mac Adress first"

Question: Why there need to be a pairing?
Feature Request: BLE can connect without pairing. This would be much easier.

E (106953) esp_image: invalid segment length 0x76727000

After upload process, it is showing something related to time. and on serial, I am getting error: E (106953) esp_image: invalid segment length 0x76727000

Full serial output is here,

18:48:55.641 -> Starting BLE OTA sketch
18:48:55.969 -> Characteristic defined! Now you can read it in your phone!
18:49:00.437 -> Connected
18:49:29.869 -> disconnected
18:50:09.226 -> Connected
18:50:22.192 -> TX AA 00
18:50:22.192 -> Available space: 113201
18:50:22.192 -> File Size: 625024
18:50:22.511 -> TX F1 00 01
18:50:23.059 -> TX F1 00 02
18:50:23.725 -> TX F1 00 03
18:50:24.331 -> TX F1 00 04
18:50:24.842 -> TX F1 00 05
18:50:25.449 -> TX F1 00 06
18:50:26.010 -> TX F1 00 07
18:50:26.333 -> TX F1 00 08
18:50:26.659 -> TX F1 00 09
18:50:26.984 -> TX F1 00 0A
18:50:27.299 -> TX F1 00 0B
18:50:27.671 -> TX F1 00 0C
18:50:27.988 -> TX F1 00 0D
18:50:28.310 -> TX F1 00 0E
18:50:28.637 -> TX F1 00 0F
18:50:28.960 -> TX F1 00 10
18:50:29.330 -> TX F1 00 11
18:50:29.611 -> TX F1 00 12
18:50:29.939 -> TX F1 00 13
18:50:30.265 -> TX F1 00 14
18:50:30.592 -> TX F1 00 15
18:50:30.873 -> TX F1 00 16
18:50:31.196 -> TX F1 00 17
18:50:31.522 -> TX F1 00 18
18:50:31.849 -> TX F1 00 19
18:50:32.174 -> TX F1 00 1A
18:50:32.483 -> TX F1 00 1B
18:50:32.856 -> TX F1 00 1C
18:50:33.181 -> TX F1 00 1D
18:50:33.510 -> TX F1 00 1E
18:50:33.824 -> TX F1 00 1F
18:50:34.198 -> TX F1 00 20
18:50:34.524 -> TX F1 00 21
18:50:34.795 -> TX F1 00 22
18:50:35.124 -> TX F1 00 23
18:50:35.499 -> TX F1 00 24
18:50:35.826 -> TX F1 00 25
18:50:36.141 -> TX F1 00 26
18:50:36.316 -> TX F2 00 27
18:50:36.399 -> Complete
18:50:41.381 -> Trying to start update
18:50:42.535 -> Written : 100736 successfully
18:50:42.535 -> E (106953) esp_image: invalid segment length 0x76727000
18:50:42.535 -> Error Occurred. Error #: 9
18:50:42.585 -> TX 0F 57 72 69 74 74 65 6E 20 3A 20 31 30 30 37 33 36 2F 31 30 30 37 33 36 20 5B 31 30 30 25 5D 20 0A 45 72 72 6F 72 20 23 3A 20 00
18:50:47.777 -> Removing update file
18:50:48.010 -> Rebooting to complete OTA update

OTA Speed 3kb/s vs 12kb/s

dear fbiego,

I transformed your OTA code with minor changes into my esp32 project and into my android app. It works like a charm, thank you for that!

Now I am just curious how you could achieve ~12kb/s transfer speed (stated in the readme). I am getting only 3kb/s transfer speed like your "old code". I already looked into your ESP32 Clock OTA source code you posted into an older github issue, but could not see anything what could spice the transfer speed up to 12kb/s.

I would be very glad if you could give me a hint. Maybe it is the use of FFAT? Would be very interesting to know, because on my project it feels like the bluetooth data transfer rate is the bottleneck.

Device with address is not found

Hello. There seems to be something missing in your example code. In order to perform firmware update using python script, you must know the device address, but in your program, you havent written a code to print out the device address to the serial monitor which is very inconvenient. I would suggest adding something like :

void printDeviceAddress() {
 
  const uint8_t* point = esp_bt_dev_get_address();
 
  for (int i = 0; i < 6; i++) {
 
    char str[3];
 
    sprintf(str, "%02X", (int)point[i]);
    Serial.print(str);
 
    if (i < 5){
      Serial.print(":");
    }
 
  }
}

To your code. Additionally, I have managed to get the firmware update using this method only once, I have tried to do it again afterwards and getting this issue:

C:\Users\petrikas.lu\Downloads\BLE_OTA_Python-main\BLE_OTA_Python-main>python ota.py "30:AE:A4:BE:38:32" "firmware.bin"
#####################################################################
    ------------------------BLE OTA update---------------------
    Arduino code @ https://github.com/fbiego/ESP32_BLE_OTA_Arduino
#####################################################################
Trying to start OTA update
-----------Failed--------------
Device with address 30:AE:A4:BE:38:32 could not be found.

It seems that it no longer can find the device with such address but my function return this address when I call the function that I have suggested:

13:50:57.398 -> Starting BLE OTA sketch
13:50:58.240 -> Characteristic defined! Now you can read it in your phone!
13:50:58.240 -> 30:AE:A4:BE:38:32

E (66829) esp_image: invalid segment length 0xffffffff

Dear fbiego
thanks for this great ota example

When I try the "esp32_ble_ota" example I get the error below.
I made sure to have fully erased the flash on my esp32 dev kit c board before uploading the binaries from the Arduino IDE.

Sequence is this:

  1. erase flash on esp32 target
  2. open "esp32_ble_ota" in Arduino IDE, verify and upload it.
  3. open "BLE_OTA_Python-main" in Visual Studio code
  4. python .\ota.py "3C:61:05:3E:C6:2A" "firmware.bin"

Please see the traces below.
Any help to resolve this issue is much appreciated.
thanks
Marko


trace on terminal:
(penv) PS C:\Users\me\Documents\ISE\sensor-devices\esp32\BLE_OTA_Python-main> python .\ota.py "3C:61:05:3E:C6:2A" "firmware.bin"
------------------------BLE OTA update---------------------
Arduino code @ https://github.com/fbiego/ESP32_BLE_OTA_Arduino
#####################################################################
Trying to start OTA update
Reading from: firmware.bin
Transfer mode: 0
Installing firmwareโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆ----| 92.3% Complete
Progress: |โ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆ| 100.0% Complete
OTA result: Written : 160000/160000 [100%]
Error #: 9
Waiting for disconnect... : Device disconnected
-----------Complete--------------

trace on COM from esp32
ets Jun 8 2016 00:22:57

rst:0x1 (POWERON_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
configsip: 0, SPIWP:0xee
clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
mode:DIO, clock div:1
load:0x3fff0018,len:4
load:0x3fff001c,len:1216
ho 0 tail 12 room 4
load:0x40078000,len:10944
load:0x40080400,len:6388
entry 0x400806b4
Starting BLE OTA sketch
Characteristic defined! Now you can read it in your phone!
TX AA 00
TX F1 00 01
TX F1 00 02
TX F1 00 03
TX F1 00 04
TX F1 00 05
TX F1 00 06
TX F1 00 07
TX F1 00 08
TX F1 00 09
TX F1 00 0A
TX F1 00 0B
TX F1 00 0C
TX F2 00 0D
Trying to start update
Written : 160000 successfully
E (66829) esp_image: invalid segment length 0xffffffff
Error Occurred. Error #: 9
TX 0F 57 72 69 74 74 65 6E 20 3A 20 31 36 30 30 30 30 2F 31 36 30 30 30 30 20 5B 31 30 30 25 5D 20 0A 45 72 72 6F 72 20 23 3A 20 39
Removing update file
Rebooting to complete OTA update
ets Jun 8 2016 00:22:57

rst:0xc (SW_CPU_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
configsip: 0, SPIWP:0xee
clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
mode:DIO, clock div:1
load:0x3fff0018,len:4
load:0x3fff001c,len:1216
ho 0 tail 12 room 4
load:0x40078000,len:10944
load:0x40080400,len:6388
entry 0x400806b4
Starting BLE OTA sketch
Characteristic defined! Now you can read it in your phone!

ESP32 with additional BLE-characteristics

Hello

Thanks for this great implementation.
Your test example works great, so I was trying to integrate your code into mine to have OTA_BLE functionality.
I might be doing something I'm not fully understanding, so apologies in advance:

My goal is to post some values in a few BLE-characteristics. After integrating the BLE-OTA, I seem to fail at this. I might have butchered something in your initBLE() function (or didn't understand it).

It seems like the additional characteristics are just not available at all anymore (when scanning through my phone).
And every time I called pAdvertising->start(); in the loop() the ESP32 reboots.

In case you have any suggestions, they are very welcome.

thanks!

BLEServer *pServer;
BLEService *pService;
BLEAdvertising *pAdvertising;

// BluetoothSerial ESP_BT; //Object for Bluetooth
BLECharacteristic *pCharacteristic1;
BLECharacteristic *pCharacteristic2;
BLECharacteristic *pCharacteristic3;
BLECharacteristic *pCharacteristic4;

static BLECharacteristic *pCharacteristicTX;
static BLECharacteristic *pCharacteristicRX;

#define SERVICE_UUID "4fafc201-1fb5-459e-8fcc-c5c9c331914b"
#define CHARACTERISTIC_UUID "beb5483e-36e1-4688-b7f5-ea07361b26a8"  //power
#define CHARACTERISTIC2_UUID "688091db-1736-4179-b7ce-e42a724a6a68" //battery voltage
#define CHARACTERISTIC3_UUID "d240dbed-7d22-45bb-b810-add58a6c856b" // rpm
#define CHARACTERISTIC4_UUID "41e5e3f7-47e2-4885-945c-9dda1fc1dc7c" // operating state

// #define SERVICE_UUID2 "fb1e4002-54ae-4a28-9f74-dfccb248601d"
#define CHARACTERISTIC_UUID_RX "fb1e4002-54ae-4a28-9f74-dfccb248601d"
#define CHARACTERISTIC_UUID_TX "fb1e4003-54ae-4a28-9f74-dfccb248601d"
void initBLE()
{
  BLEDevice::init("ESP32 Hover");
  // BLEServer *pServer = BLEDevice::createServer();
  pServer = BLEDevice::createServer();
  pServer->setCallbacks(new MyServerCallbacks());

  // BLEService *pService2 = pServer->createService(SERVICE_UUID2);
  pService = pServer->createService(SERVICE_UUID);
  pCharacteristicTX = pService->createCharacteristic(CHARACTERISTIC_UUID_TX, BLECharacteristic::PROPERTY_NOTIFY);
  pCharacteristicRX = pService->createCharacteristic(CHARACTERISTIC_UUID_RX, BLECharacteristic::PROPERTY_WRITE | BLECharacteristic::PROPERTY_WRITE_NR);
  pCharacteristicRX->setCallbacks(new MyCallbacks());
  pCharacteristicTX->setCallbacks(new MyCallbacks());
  pCharacteristicTX->addDescriptor(new BLE2902());
  pCharacteristicTX->setNotifyProperty(true);

  // pService = pServer->createService(SERVICE_UUID);
  pCharacteristic1 = pService->createCharacteristic(
      CHARACTERISTIC_UUID,
      BLECharacteristic::PROPERTY_READ |
          BLECharacteristic::PROPERTY_WRITE);
  pCharacteristic1->setValue("Start1");

  pCharacteristic2 = pService->createCharacteristic(
      CHARACTERISTIC2_UUID,
      BLECharacteristic::PROPERTY_READ |
          BLECharacteristic::PROPERTY_WRITE);
  pCharacteristic2->setValue("start2");

  pCharacteristic3 = pService->createCharacteristic(
      CHARACTERISTIC3_UUID,
      BLECharacteristic::PROPERTY_READ |
          BLECharacteristic::PROPERTY_WRITE);
  pCharacteristic3->setValue("start3");

  pCharacteristic4 = pService->createCharacteristic(
      CHARACTERISTIC4_UUID,
      BLECharacteristic::PROPERTY_READ |
          BLECharacteristic::PROPERTY_WRITE);
  pCharacteristic3->setValue("start4");

  pService->start();

  // BLEAdvertising *pAdvertising = pServer->getAdvertising();  // this still is working for backward compatibility
  pAdvertising = BLEDevice::getAdvertising();
  pAdvertising->addServiceUUID(SERVICE_UUID);
  pAdvertising->setScanResponse(true);
  pAdvertising->setMinPreferred(0x06); // functions that help with iPhone connections issue
  pAdvertising->setMinPreferred(0x12);
  BLEDevice::startAdvertising();
  Serial.println("Characteristic defined! Now you can read it in your phone!");

  // pAdvertising->start();
}

void send_BLE(int16_t value, BLECharacteristic *pCharacteristic)
{
  char buffer[80];
  dtostrf(value, 1, 2, buffer);
  pCharacteristic->setValue(buffer);
  pCharacteristic->notify(); // send notification of change
}

I used to call in the loop repetitively ... but this has no effect anymore.

    pAdvertising->start();
    send_BLE((int16_t)(power1), pCharacteristic1);
    send_BLE((int16_t)(batVoltage_buf[buffer_index]), pCharacteristic2);
    send_BLE((int16_t)(speed_left[buffer_index]), pCharacteristic3);
    send_BLE((int16_t)(charging_state), pCharacteristic4);

TAG missing in esp32_ble_ota_compact

Hello,

I'm trying to compile the esp32_ble_ota_compact example, but I get an error due to a missing definition of TAG, and indeed there is nothing like this in the ble_ota_dfu.cpp nor ble_ota_dfu.hpp file.

How is it possible to define it?

Regards,
ABC

Processing esp32doit-devkit-v1 (platform: espressif32; board: esp32doit-devkit-v1; framework: arduino)
---------------------------------------------------------------------------------------------------------------------------------------Verbose mode can be enabled via -v, --verbose option
CONFIGURATION: https://docs.platformio.org/page/boards/espressif32/esp32doit-devkit-v1.html
PLATFORM: Espressif 32 (5.2.0) > DOIT ESP32 DEVKIT V1
HARDWARE: ESP32 240MHz, 320KB RAM, 4MB Flash
DEBUG: Current (cmsis-dap) External (cmsis-dap, esp-bridge, esp-prog, iot-bus-jtag, jlink, minimodule, olimex-arm-usb-ocd, olimex-arm-usb-ocd-h, olimex-arm-usb-tiny-h, olimex-jtag-tiny, tumpa)
PACKAGES:

  • framework-arduinoespressif32 @ 3.20005.220925 (2.0.5)
  • tool-esptoolpy @ 1.40201.0 (4.2.1)
  • toolchain-xtensa-esp32 @ 8.4.0+2021r2-patch3
    LDF: Library Dependency Finder -> https://bit.ly/configure-pio-ldf
    LDF Modes: Finder ~ chain, Compatibility ~ soft
    Found 34 compatible libraries
    Scanning dependencies...
    Dependency Graph
    |-- NimBLE-Arduino @ 1.4.1+sha.e46123a
    |-- ble_ota_dfuU @ 1.0.0
    Building in release mode
    Compiling .pio\build\esp32doit-devkit-v1\src\main.cpp.o
    Compiling .pio\build\esp32doit-devkit-v1\lib066\NimBLE-Arduino\nimble\esp_port\esp-hci\src\esp_nimble_hci.c.o
    Compiling .pio\build\esp32doit-devkit-v1\lib066\NimBLE-Arduino\nimble\esp_port\port\src\esp_nimble_mem.c.o
    Compiling .pio\build\esp32doit-devkit-v1\lib066\NimBLE-Arduino\nimble\ext\tinycrypt\src\aes_decrypt.c.o
    Compiling .pio\build\esp32doit-devkit-v1\lib066\NimBLE-Arduino\nimble\ext\tinycrypt\src\aes_encrypt.c.o
    Compiling .pio\build\esp32doit-devkit-v1\lib066\NimBLE-Arduino\nimble\ext\tinycrypt\src\cbc_mode.c.o
    Compiling .pio\build\esp32doit-devkit-v1\lib066\NimBLE-Arduino\nimble\ext\tinycrypt\src\ccm_mode.c.o
    Compiling .pio\build\esp32doit-devkit-v1\lib066\NimBLE-Arduino\nimble\ext\tinycrypt\src\cmac_mode.c.o
    Compiling .pio\build\esp32doit-devkit-v1\lib066\NimBLE-Arduino\nimble\ext\tinycrypt\src\ctr_mode.c.o
    Compiling .pio\build\esp32doit-devkit-v1\lib066\NimBLE-Arduino\nimble\ext\tinycrypt\src\ctr_prng.c.o
    Compiling .pio\build\esp32doit-devkit-v1\lib066\NimBLE-Arduino\nimble\ext\tinycrypt\src\ecc.c.o
    In file included from C:/Users/ABC/.platformio/packages/framework-arduinoespressif32/cores/esp32/esp32-hal.h:76,
    from C:/Users/ABC/.platformio/packages/framework-arduinoespressif32/cores/esp32/Arduino.h:36,
    from src/main.hpp:9,
    from src/main.cpp:2:
    lib/ble_ota_dfu/src/./freertos_utils.hpp: In function 'void _initialize_queue(QueueDefinition**, const char*, size_t, T*)':
    lib/ble_ota_dfu/src/./freertos_utils.hpp:22:14: error: 'TAG' was not declared in this scope
    ESP_LOGE(TAG, "Error creating the queue "%s"", queue_name);
    ^~~
    C:/Users/ABC/.platformio/packages/framework-arduinoespressif32/cores/esp32/esp32-hal-log.h:159:72: note: in definition of macro 'log_e'
    #define log_e(format, ...) log_printf(ARDUHAL_LOG_FORMAT(E, format), ##VA_ARGS)
    ^~~~~~~~~~~
    lib/ble_ota_dfu/src/./freertos_utils.hpp:22:5: note: in expansion of macro 'ESP_LOGE'
    ESP_LOGE(TAG, "Error creating the queue "%s"", queue_name);
    ^~~~~~~~
    lib/ble_ota_dfu/src/./freertos_utils.hpp:30:14: error: 'TAG' was not declared in this scope
    ESP_LOGE(TAG, "Error initializing the queue "%s"", queue_name);
    ^~~
    C:/Users/ABC/.platformio/packages/framework-arduinoespressif32/cores/esp32/esp32-hal-log.h:159:72: note: in definition of macro 'log_e'
    #define log_e(format, ...) log_printf(ARDUHAL_LOG_FORMAT(E, format), ##VA_ARGS)
    ^~~~~~~~~~~
    lib/ble_ota_dfu/src/./freertos_utils.hpp:30:5: note: in expansion of macro 'ESP_LOGE'
    ESP_LOGE(TAG, "Error initializing the queue "%s"", queue_name);
    ^~~~~~~~
    Compiling .pio\build\esp32doit-devkit-v1\lib066\NimBLE-Arduino\nimble\ext\tinycrypt\src\ecc_dh.c.o
    Compiling .pio\build\esp32doit-devkit-v1\lib066\NimBLE-Arduino\nimble\ext\tinycrypt\src\ecc_dsa.c.o
    *** [.pio\build\esp32doit-devkit-v1\src\main.cpp.o] Error 1'

React native

Hi how can i add react native support for this project?

Create simple ArduinoBleOTA library

Thanks for Your fullstack solution (from esp32 to android app)! I have forked this repository in order to create PlatformIO Arduino library:
https://github.com/vovagorodok/ArduinoBleOTA

At the and will be nice to move it to: https://github.com/arduino-libraries

I'm trying to make it as simple as possible with reusing of NimBLE-Arduino and ArduinoOTA(support only WIFI) libraries. Proposed interface will be similar to ArduinoOTA:

#include <ArduinoBleOTA.h>
void setup() {
  ArduinoBleOTA.begin("ArduinoBleOTA", InternalStorage);  // or SDStorage or SerialFlashStorage
}

Or if bluetooth is used not only for OTA:

#include <ArduinoBleOTA.h>
void setup() {
    BLEDevice::init("MyBleDevice");
    auto* server = BLEDevice::createServer();
    ArduinoBleOTA.begin(server, InternalStorage);
    // add your BLE services here
    server->startAdvertising();
}

Additionally I have plan to add support of Atmel based boards using ArduinoBLE library.

I see that @Vincent-Stragier begin with that. Lets connect our forces and create easy library with simple/lightweight protocol.

Draft protocol proposal will have small number of commands (names and numbers can be another like 0x01 or 0xFE):

SIZE 1
PACKAGE 2
INSTALL 3
OK 4
NOK 5

Designations for examples:
-> - recived from phone
<- - send to phone

Sunny day scenario:

-> SIZE <size>
<- OK % open ota storage
-> PACKAGE <data>
<- OK
...
-> PACKAGE <data>
<- OK
-> INSTALL % full <data> size == <size>, apply binary
<- OK

Size to big:

-> SIZE <size>
<- NOK % do nothing

Connection terminated:

-> SIZE <size>
<- OK
-> PACKAGE <data>
<- OK
...
% termination
-> SIZE <size>
<- OK % reopen ota storage and write from scratch
...

Unexpected package:

...
-> PACKAGE <data> % full <data> size > <size>, close ota storage
<- NOK

Instalation error:

...
-> INSTALL % full <data> size < <size>
<- NOK

I thing that most/all corner cases are covered or something is missed?
@fbiego can you describe scenarios(corner cases) that are currently covered with command names (because from code I see some magic numbers 0xFB, 0xFC, 0xFD, FE ..)?
What do you think generally about this idea?

Thanks!

E (58138) esp_image: Invalid segment length

Hi fbiego and thank you for this OTA example.

I'm using your example ESP32 code together with you Android app and are trying to implement this in my own code. It worked well with your example applications but when i changed it to use Ffat I can only upload and install one BIN (the first one i tried, that uses your SPIFFS code and only modified some pins to activate). Any other BIN I try larger or smaller then the original gets an error after upload. The segment length varies between the different files.

File compleate...
Trying to start update
Written : 4096 successfully
E (58138) esp_image: invalid segment length 0x7369
Error Occurred. Error #: 9
TX 0F 57 72 69 74 74 65 6E 20 3A 20 34 30 39 36 2F 34 30 39 36 20 5B 31 30 30 25 5D 20 0A 45 72 72 6F 72 20 23 3A 20 39
Removing update file
Rebooting to complete OTA update

I should say I only tried the the SPIFFS version with the original BIN and now I can't seam to format the ESP32 flash back to SPIFFS, at least the mounting fails.

I assume you do not experience this error, but do you have any tips for where to start looking?
Thanks

NimBLE OTA and Android app connect and instantly disconnect

Hi, I'm trying to get "esp32_nim_ble_ota.ino" and the Android app "ESP32 OTA BLE" working,
unfortunately, immediately after connecting to the ESP32,
"Connected (and one second after) disconnected" appears in the console,
and as a result, the new firmware cannot be uploaded.. the code is not modified in any way .. it's pure code from here and the app comes from the google store

Please help =( Tom

Gradle fail

Hi,

On opening the code it sais
Build file 'C:\Users\fimartin\Documents\Repo_GIT\Prueba_BLE_APP\ESP32_BLE_OTA_Android\app\build.gradle' line: 34

A problem occurred evaluating project ':app'.

Could not get unknown property 'STORE_FILE' for SigningConfig$AgpDecorated_Decorated{name=debug, storeFile=C:\Users\fimartin.android\debug.keystore, storePassword=android, keyAlias=AndroidDebugKey, keyPassword=android, storeType=pkcs12, v1SigningEnabled=true, v2SigningEnabled=true, enableV1Signing=null, enableV2Signing=null, enableV3Signing=null, enableV4Signing=null} of type com.android.build.gradle.internal.dsl.SigningConfig$AgpDecorated.

  • Try:

Run with --info or --debug option to get more log output.
Run with --scan to get full insights.

  • Exception is:
    Log info
    org.gradle.api.GradleScriptException: A problem occurred evaluating project ':app'.
    at org.gradle.groovy.scripts.internal.DefaultScriptRunnerFactory$ScriptRunnerImpl.run(DefaultScriptRunnerFactory.java:93)
    at org.gradle.configuration.DefaultScriptPluginFactory$ScriptPluginImpl.lambda$apply$0(DefaultScriptPluginFactory.java:133)
    at org.gradle.configuration.ProjectScriptTarget.addConfiguration(ProjectScriptTarget.java:79)
    at org.gradle.configuration.DefaultScriptPluginFactory$ScriptPluginImpl.apply(DefaultScriptPluginFactory.java:136)
    at org.gradle.configuration.BuildOperationScriptPlugin$1.run(BuildOperationScriptPlugin.java:65)
    at org.gradle.internal.operations.DefaultBuildOperationRunner$1.execute(DefaultBuildOperationRunner.java:29)
    at org.gradle.internal.operations.DefaultBuildOperationRunner$1.execute(DefaultBuildOperationRunner.java:26)
    at org.gradle.internal.operations.DefaultBuildOperationRunner$2.execute(DefaultBuildOperationRunner.java:66)
    at org.gradle.internal.operations.DefaultBuildOperationRunner$2.execute(DefaultBuildOperationRunner.java:59)
    at org.gradle.internal.operations.DefaultBuildOperationRunner.execute(DefaultBuildOperationRunner.java:157)
    at org.gradle.internal.operations.DefaultBuildOperationRunner.execute(DefaultBuildOperationRunner.java:59)
    at org.gradle.internal.operations.DefaultBuildOperationRunner.run(DefaultBuildOperationRunner.java:47)
    at org.gradle.internal.operations.DefaultBuildOperationExecutor.run(DefaultBuildOperationExecutor.java:68)
    at org.gradle.configuration.BuildOperationScriptPlugin.lambda$apply$0(BuildOperationScriptPlugin.java:62)
    at org.gradle.configuration.internal.DefaultUserCodeApplicationContext.apply(DefaultUserCodeApplicationContext.java:44)
    at org.gradle.configuration.BuildOperationScriptPlugin.apply(BuildOperationScriptPlugin.java:62)
    at org.gradle.api.internal.project.DefaultProjectStateRegistry$ProjectStateImpl.lambda$applyToMutableState$0(DefaultProjectStateRegistry.java:366)
    at org.gradle.api.internal.project.DefaultProjectStateRegistry$ProjectStateImpl.fromMutableState(DefaultProjectStateRegistry.java:393)
    at org.gradle.api.internal.project.DefaultProjectStateRegistry$ProjectStateImpl.applyToMutableState(DefaultProjectStateRegistry.java:365)
    at org.gradle.configuration.project.BuildScriptProcessor.execute(BuildScriptProcessor.java:42)
    at org.gradle.configuration.project.BuildScriptProcessor.execute(BuildScriptProcessor.java:26)
    at org.gradle.configuration.project.ConfigureActionsProjectEvaluator.evaluate(ConfigureActionsProjectEvaluator.java:35)
    at org.gradle.configuration.project.LifecycleProjectEvaluator$EvaluateProject.lambda$run$0(LifecycleProjectEvaluator.java:100)
    at org.gradle.api.internal.project.DefaultProjectStateRegistry$ProjectStateImpl.lambda$applyToMutableState$0(DefaultProjectStateRegistry.java:366)
    at org.gradle.api.internal.project.DefaultProjectStateRegistry$ProjectStateImpl.lambda$withProjectLock$3(DefaultProjectStateRegistry.java:426)
    at org.gradle.internal.work.DefaultWorkerLeaseService.withLocks(DefaultWorkerLeaseService.java:211)
    at org.gradle.api.internal.project.DefaultProjectStateRegistry$ProjectStateImpl.withProjectLock(DefaultProjectStateRegistry.java:426)
    at org.gradle.api.internal.project.DefaultProjectStateRegistry$ProjectStateImpl.fromMutableState(DefaultProjectStateRegistry.java:407)
    at org.gradle.api.internal.project.DefaultProjectStateRegistry$ProjectStateImpl.applyToMutableState(DefaultProjectStateRegistry.java:365)
    at org.gradle.configuration.project.LifecycleProjectEvaluator$EvaluateProject.run(LifecycleProjectEvaluator.java:91)
    at org.gradle.internal.operations.DefaultBuildOperationRunner$1.execute(DefaultBuildOperationRunner.java:29)
    at org.gradle.internal.operations.DefaultBuildOperationRunner$1.execute(DefaultBuildOperationRunner.java:26)
    at org.gradle.internal.operations.DefaultBuildOperationRunner$2.execute(DefaultBuildOperationRunner.java:66)
    at org.gradle.internal.operations.DefaultBuildOperationRunner$2.execute(DefaultBuildOperationRunner.java:59)
    at org.gradle.internal.operations.DefaultBuildOperationRunner.execute(DefaultBuildOperationRunner.java:157)
    at org.gradle.internal.operations.DefaultBuildOperationRunner.execute(DefaultBuildOperationRunner.java:59)
    at org.gradle.internal.operations.DefaultBuildOperationRunner.run(DefaultBuildOperationRunner.java:47)
    at org.gradle.internal.operations.DefaultBuildOperationExecutor.run(DefaultBuildOperationExecutor.java:68)
    at org.gradle.configuration.project.LifecycleProjectEvaluator.evaluate(LifecycleProjectEvaluator.java:63)
    at org.gradle.api.internal.project.DefaultProject.evaluate(DefaultProject.java:751)
    at org.gradle.api.internal.project.DefaultProject.evaluate(DefaultProject.java:151)
    at org.gradle.api.internal.project.DefaultProjectStateRegistry$ProjectStateImpl.ensureConfigured(DefaultProjectStateRegistry.java:339)
    at org.gradle.execution.TaskPathProjectEvaluator.configure(TaskPathProjectEvaluator.java:41)
    at org.gradle.execution.TaskPathProjectEvaluator.configureHierarchy(TaskPathProjectEvaluator.java:57)
    at org.gradle.configuration.DefaultProjectsPreparer.prepareProjects(DefaultProjectsPreparer.java:48)
    at org.gradle.configuration.BuildTreePreparingProjectsPreparer.prepareProjects(BuildTreePreparingProjectsPreparer.java:64)
    at org.gradle.configuration.BuildOperationFiringProjectsPreparer$ConfigureBuild.run(BuildOperationFiringProjectsPreparer.java:52)
    at org.gradle.internal.operations.DefaultBuildOperationRunner$1.execute(DefaultBuildOperationRunner.java:29)
    at org.gradle.internal.operations.DefaultBuildOperationRunner$1.execute(DefaultBuildOperationRunner.java:26)
    at org.gradle.internal.operations.DefaultBuildOperationRunner$2.execute(DefaultBuildOperationRunner.java:66)
    at org.gradle.internal.operations.DefaultBuildOperationRunner$2.execute(DefaultBuildOperationRunner.java:59)
    at org.gradle.internal.operations.DefaultBuildOperationRunner.execute(DefaultBuildOperationRunner.java:157)
    at org.gradle.internal.operations.DefaultBuildOperationRunner.execute(DefaultBuildOperationRunner.java:59)
    at org.gradle.internal.operations.DefaultBuildOperationRunner.run(DefaultBuildOperationRunner.java:47)
    at org.gradle.internal.operations.DefaultBuildOperationExecutor.run(DefaultBuildOperationExecutor.java:68)
    at org.gradle.configuration.BuildOperationFiringProjectsPreparer.prepareProjects(BuildOperationFiringProjectsPreparer.java:40)
    at org.gradle.initialization.VintageBuildModelController.lambda$prepareProjects$1(VintageBuildModelController.java:93)
    at org.gradle.internal.build.StateTransitionController.lambda$doTransition$1(StateTransitionController.java:222)
    at org.gradle.internal.build.StateTransitionController.doTransition(StateTransitionController.java:243)
    at org.gradle.internal.build.StateTransitionController.doTransition(StateTransitionController.java:221)
    at org.gradle.internal.build.StateTransitionController.transitionIfNotPreviously(StateTransitionController.java:190)
    at org.gradle.initialization.VintageBuildModelController.prepareProjects(VintageBuildModelController.java:93)
    at org.gradle.initialization.VintageBuildModelController.doBuildStages(VintageBuildModelController.java:77)
    at org.gradle.initialization.VintageBuildModelController.getConfiguredModel(VintageBuildModelController.java:58)
    at org.gradle.internal.build.StateTransitionController.notInStateIgnoreOtherThreads(StateTransitionController.java:89)
    at org.gradle.internal.build.DefaultBuildLifecycleController.getConfiguredBuild(DefaultBuildLifecycleController.java:98)
    at org.gradle.internal.build.AbstractBuildState.ensureProjectsConfigured(AbstractBuildState.java:65)
    at org.gradle.internal.buildtree.DefaultBuildTreeModelCreator$DefaultBuildToolingModelController.locateBuilderForTarget(DefaultBuildTreeModelCreator.java:90)
    at org.gradle.internal.buildtree.DefaultBuildTreeModelCreator$DefaultBuildToolingModelController.locateBuilderForDefaultTarget(DefaultBuildTreeModelCreator.java:82)
    at org.gradle.tooling.internal.provider.runner.DefaultBuildController$DefaultTargetModel.locate(DefaultBuildController.java:239)
    at org.gradle.tooling.internal.provider.runner.DefaultBuildController.getToolingModelBuilder(DefaultBuildController.java:184)
    at org.gradle.tooling.internal.provider.runner.DefaultBuildController.getModel(DefaultBuildController.java:98)
    at org.gradle.tooling.internal.consumer.connection.ParameterAwareBuildControllerAdapter.getModel(ParameterAwareBuildControllerAdapter.java:39)
    at org.gradle.tooling.internal.consumer.connection.UnparameterizedBuildController.getModel(UnparameterizedBuildController.java:113)
    at org.gradle.tooling.internal.consumer.connection.NestedActionAwareBuildControllerAdapter.getModel(NestedActionAwareBuildControllerAdapter.java:31)
    at org.gradle.tooling.internal.consumer.connection.UnparameterizedBuildController.findModel(UnparameterizedBuildController.java:97)
    at org.gradle.tooling.internal.consumer.connection.NestedActionAwareBuildControllerAdapter.findModel(NestedActionAwareBuildControllerAdapter.java:31)
    at org.gradle.tooling.internal.consumer.connection.UnparameterizedBuildController.findModel(UnparameterizedBuildController.java:81)
    at org.gradle.tooling.internal.consumer.connection.NestedActionAwareBuildControllerAdapter.findModel(NestedActionAwareBuildControllerAdapter.java:31)
    at org.gradle.tooling.internal.consumer.connection.UnparameterizedBuildController.findModel(UnparameterizedBuildController.java:66)
    at org.gradle.tooling.internal.consumer.connection.NestedActionAwareBuildControllerAdapter.findModel(NestedActionAwareBuildControllerAdapter.java:31)
    at org.jetbrains.plugins.gradle.model.ProjectImportAction.execute(ProjectImportAction.java:116)
    at org.jetbrains.plugins.gradle.model.ProjectImportAction.execute(ProjectImportAction.java:42)
    at org.gradle.tooling.internal.consumer.connection.InternalBuildActionAdapter.execute(InternalBuildActionAdapter.java:64)
    at org.gradle.tooling.internal.provider.runner.AbstractClientProvidedBuildActionRunner$ActionAdapter.runAction(AbstractClientProvidedBuildActionRunner.java:131)
    at org.gradle.tooling.internal.provider.runner.AbstractClientProvidedBuildActionRunner$ActionAdapter.beforeTasks(AbstractClientProvidedBuildActionRunner.java:99)
    at org.gradle.internal.buildtree.DefaultBuildTreeModelCreator.beforeTasks(DefaultBuildTreeModelCreator.java:57)
    at org.gradle.internal.buildtree.DefaultBuildTreeLifecycleController.lambda$fromBuildModel$1(DefaultBuildTreeLifecycleController.java:72)
    at org.gradle.internal.buildtree.DefaultBuildTreeLifecycleController.lambda$runBuild$4(DefaultBuildTreeLifecycleController.java:103)
    at org.gradle.internal.build.StateTransitionController.lambda$transition$0(StateTransitionController.java:145)
    at org.gradle.internal.build.StateTransitionController.doTransition(StateTransitionController.java:243)
    at org.gradle.internal.build.StateTransitionController.transition(StateTransitionController.java:145)
    at org.gradle.internal.buildtree.DefaultBuildTreeLifecycleController.runBuild(DefaultBuildTreeLifecycleController.java:100)
    at org.gradle.internal.buildtree.DefaultBuildTreeLifecycleController.fromBuildModel(DefaultBuildTreeLifecycleController.java:71)
    at org.gradle.tooling.internal.provider.runner.AbstractClientProvidedBuildActionRunner.runClientAction(AbstractClientProvidedBuildActionRunner.java:43)
    at org.gradle.tooling.internal.provider.runner.ClientProvidedPhasedActionRunner.run(ClientProvidedPhasedActionRunner.java:53)
    at org.gradle.launcher.exec.ChainingBuildActionRunner.run(ChainingBuildActionRunner.java:35)
    at org.gradle.internal.buildtree.ProblemReportingBuildActionRunner.run(ProblemReportingBuildActionRunner.java:49)
    at org.gradle.launcher.exec.BuildOutcomeReportingBuildActionRunner.run(BuildOutcomeReportingBuildActionRunner.java:69)
    at org.gradle.tooling.internal.provider.FileSystemWatchingBuildActionRunner.run(FileSystemWatchingBuildActionRunner.java:114)
    at org.gradle.launcher.exec.BuildCompletionNotifyingBuildActionRunner.run(BuildCompletionNotifyingBuildActionRunner.java:41)
    at org.gradle.launcher.exec.RootBuildLifecycleBuildActionExecutor.lambda$execute$0(RootBuildLifecycleBuildActionExecutor.java:40)
    at org.gradle.composite.internal.DefaultRootBuildState.run(DefaultRootBuildState.java:155)
    at org.gradle.launcher.exec.RootBuildLifecycleBuildActionExecutor.execute(RootBuildLifecycleBuildActionExecutor.java:40)
    at org.gradle.internal.buildtree.DefaultBuildTreeContext.execute(DefaultBuildTreeContext.java:40)
    at org.gradle.launcher.exec.BuildTreeLifecycleBuildActionExecutor.lambda$execute$0(BuildTreeLifecycleBuildActionExecutor.java:65)
    at org.gradle.internal.buildtree.BuildTreeState.run(BuildTreeState.java:53)
    at org.gradle.launcher.exec.BuildTreeLifecycleBuildActionExecutor.execute(BuildTreeLifecycleBuildActionExecutor.java:65)
    at org.gradle.launcher.exec.RunAsBuildOperationBuildActionExecutor$3.call(RunAsBuildOperationBuildActionExecutor.java:61)
    at org.gradle.launcher.exec.RunAsBuildOperationBuildActionExecutor$3.call(RunAsBuildOperationBuildActionExecutor.java:57)
    at org.gradle.internal.operations.DefaultBuildOperationRunner$CallableBuildOperationWorker.execute(DefaultBuildOperationRunner.java:204)
    at org.gradle.internal.operations.DefaultBuildOperationRunner$CallableBuildOperationWorker.execute(DefaultBuildOperationRunner.java:199)
    at org.gradle.internal.operations.DefaultBuildOperationRunner$2.execute(DefaultBuildOperationRunner.java:66)
    at org.gradle.internal.operations.DefaultBuildOperationRunner$2.execute(DefaultBuildOperationRunner.java:59)
    at org.gradle.internal.operations.DefaultBuildOperationRunner.execute(DefaultBuildOperationRunner.java:157)
    at org.gradle.internal.operations.DefaultBuildOperationRunner.execute(DefaultBuildOperationRunner.java:59)
    at org.gradle.internal.operations.DefaultBuildOperationRunner.call(DefaultBuildOperationRunner.java:53)
    at org.gradle.internal.operations.DefaultBuildOperationExecutor.call(DefaultBuildOperationExecutor.java:73)
    at org.gradle.launcher.exec.RunAsBuildOperationBuildActionExecutor.execute(RunAsBuildOperationBuildActionExecutor.java:57)
    at org.gradle.launcher.exec.RunAsWorkerThreadBuildActionExecutor.lambda$execute$0(RunAsWorkerThreadBuildActionExecutor.java:38)
    at org.gradle.internal.work.DefaultWorkerLeaseService.withLocks(DefaultWorkerLeaseService.java:211)
    at org.gradle.launcher.exec.RunAsWorkerThreadBuildActionExecutor.execute(RunAsWorkerThreadBuildActionExecutor.java:38)
    at org.gradle.tooling.internal.provider.ContinuousBuildActionExecutor.execute(ContinuousBuildActionExecutor.java:103)
    at org.gradle.tooling.internal.provider.SubscribableBuildActionExecutor.execute(SubscribableBuildActionExecutor.java:64)
    at org.gradle.internal.session.DefaultBuildSessionContext.execute(DefaultBuildSessionContext.java:46)
    at org.gradle.tooling.internal.provider.BuildSessionLifecycleBuildActionExecuter$ActionImpl.apply(BuildSessionLifecycleBuildActionExecuter.java:100)
    at org.gradle.tooling.internal.provider.BuildSessionLifecycleBuildActionExecuter$ActionImpl.apply(BuildSessionLifecycleBuildActionExecuter.java:88)
    at org.gradle.internal.session.BuildSessionState.run(BuildSessionState.java:69)
    at org.gradle.tooling.internal.provider.BuildSessionLifecycleBuildActionExecuter.execute(BuildSessionLifecycleBuildActionExecuter.java:62)
    at org.gradle.tooling.internal.provider.BuildSessionLifecycleBuildActionExecuter.execute(BuildSessionLifecycleBuildActionExecuter.java:41)
    at org.gradle.tooling.internal.provider.GradleThreadBuildActionExecuter.execute(GradleThreadBuildActionExecuter.java:36)
    at org.gradle.tooling.internal.provider.GradleThreadBuildActionExecuter.execute(GradleThreadBuildActionExecuter.java:25)
    at org.gradle.tooling.internal.provider.StartParamsValidatingActionExecuter.execute(StartParamsValidatingActionExecuter.java:63)
    at org.gradle.tooling.internal.provider.StartParamsValidatingActionExecuter.execute(StartParamsValidatingActionExecuter.java:31)
    at org.gradle.tooling.internal.provider.SessionFailureReportingActionExecuter.execute(SessionFailureReportingActionExecuter.java:58)
    at org.gradle.tooling.internal.provider.SessionFailureReportingActionExecuter.execute(SessionFailureReportingActionExecuter.java:42)
    at org.gradle.tooling.internal.provider.SetupLoggingActionExecuter.execute(SetupLoggingActionExecuter.java:47)
    at org.gradle.tooling.internal.provider.SetupLoggingActionExecuter.execute(SetupLoggingActionExecuter.java:31)
    at org.gradle.launcher.daemon.server.exec.ExecuteBuild.doBuild(ExecuteBuild.java:65)
    at org.gradle.launcher.daemon.server.exec.BuildCommandOnly.execute(BuildCommandOnly.java:37)
    at org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:104)
    at org.gradle.launcher.daemon.server.exec.WatchForDisconnection.execute(WatchForDisconnection.java:39)
    at org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:104)
    at org.gradle.launcher.daemon.server.exec.ResetDeprecationLogger.execute(ResetDeprecationLogger.java:29)
    at org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:104)
    at org.gradle.launcher.daemon.server.exec.RequestStopIfSingleUsedDaemon.execute(RequestStopIfSingleUsedDaemon.java:35)
    at org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:104)
    at org.gradle.launcher.daemon.server.exec.ForwardClientInput$2.create(ForwardClientInput.java:78)
    at org.gradle.launcher.daemon.server.exec.ForwardClientInput$2.create(ForwardClientInput.java:75)
    at org.gradle.util.internal.Swapper.swap(Swapper.java:38)
    at org.gradle.launcher.daemon.server.exec.ForwardClientInput.execute(ForwardClientInput.java:75)
    at org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:104)
    at org.gradle.launcher.daemon.server.exec.LogAndCheckHealth.execute(LogAndCheckHealth.java:55)
    at org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:104)
    at org.gradle.launcher.daemon.server.exec.LogToClient.doBuild(LogToClient.java:63)
    at org.gradle.launcher.daemon.server.exec.BuildCommandOnly.execute(BuildCommandOnly.java:37)
    at org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:104)
    at org.gradle.launcher.daemon.server.exec.EstablishBuildEnvironment.doBuild(EstablishBuildEnvironment.java:84)
    at org.gradle.launcher.daemon.server.exec.BuildCommandOnly.execute(BuildCommandOnly.java:37)
    at org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:104)
    at org.gradle.launcher.daemon.server.exec.StartBuildOrRespondWithBusy$1.run(StartBuildOrRespondWithBusy.java:52)
    at org.gradle.launcher.daemon.server.DaemonStateCoordinator$1.run(DaemonStateCoordinator.java:297)
    at org.gradle.internal.concurrent.ExecutorPolicy$CatchAndRecordFailures.onExecute(ExecutorPolicy.java:64)
    at org.gradle.internal.concurrent.ManagedExecutorImpl$1.run(ManagedExecutorImpl.java:48)
    at org.gradle.internal.concurrent.ThreadFactoryImpl$ManagedThreadRunnable.run(ThreadFactoryImpl.java:61)
    Caused by: groovy.lang.MissingPropertyException: Could not get unknown property 'STORE_FILE' for SigningConfig$AgpDecorated_Decorated{name=debug, storeFile=C:\Users\fimartin.android\debug.keystore, storePassword=android, keyAlias=AndroidDebugKey, keyPassword=android, storeType=pkcs12, v1SigningEnabled=true, v2SigningEnabled=true, enableV1Signing=null, enableV2Signing=null, enableV3Signing=null, enableV4Signing=null} of type com.android.build.gradle.internal.dsl.SigningConfig$AgpDecorated.
    at org.gradle.internal.metaobject.AbstractDynamicObject.getMissingProperty(AbstractDynamicObject.java:85)
    at org.gradle.internal.metaobject.ConfigureDelegate.getProperty(ConfigureDelegate.java:130)
    at build_1lgz6zr90cqrpx870aaikniva$_run_closure1$_closure3$_closure9.doCall(C:\Users\fimartin\Documents\Repo_GIT\Prueba_BLE_APP\ESP32_BLE_OTA_Android\app\build.gradle:34)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at org.gradle.util.internal.ClosureBackedAction.execute(ClosureBackedAction.java:72)
    at org.gradle.util.internal.ConfigureUtil.configureTarget(ConfigureUtil.java:155)
    at org.gradle.util.internal.ConfigureUtil.configure(ConfigureUtil.java:106)
    at org.gradle.api.internal.DefaultNamedDomainObjectCollection$ContainerElementsDynamicObject.tryInvokeMethod(DefaultNamedDomainObjectCollection.java:542)
    at org.gradle.internal.metaobject.BeanDynamicObject$MetaClassAdapter.invokeMethod(BeanDynamicObject.java:504)
    at org.gradle.internal.metaobject.BeanDynamicObject.tryInvokeMethod(BeanDynamicObject.java:196)
    at org.gradle.internal.metaobject.CompositeDynamicObject.tryInvokeMethod(CompositeDynamicObject.java:98)
    at org.gradle.internal.extensibility.MixInClosurePropertiesAsMethodsDynamicObject.tryInvokeMethod(MixInClosurePropertiesAsMethodsDynamicObject.java:34)
    at org.gradle.internal.metaobject.ConfigureDelegate.invokeMethod(ConfigureDelegate.java:56)
    at build_1lgz6zr90cqrpx870aaikniva$_run_closure1$_closure3.doCall(C:\Users\fimartin\Documents\Repo_GIT\Prueba_BLE_APP\ESP32_BLE_OTA_Android\app\build.gradle:33)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at org.gradle.util.internal.ClosureBackedAction.execute(ClosureBackedAction.java:72)
    at org.gradle.util.internal.ConfigureUtil.configureTarget(ConfigureUtil.java:155)
    at org.gradle.util.internal.ConfigureUtil.configureSelf(ConfigureUtil.java:143)
    at org.gradle.api.internal.AbstractNamedDomainObjectContainer.configure(AbstractNamedDomainObjectContainer.java:91)
    at org.gradle.api.internal.AbstractNamedDomainObjectContainer.configure(AbstractNamedDomainObjectContainer.java:38)
    at org.gradle.util.internal.ConfigureUtil.configure(ConfigureUtil.java:104)
    at org.gradle.util.internal.ConfigureUtil$WrappedConfigureAction.execute(ConfigureUtil.java:167)
    at com.android.build.gradle.internal.dsl.CommonExtensionImpl.signingConfigs(CommonExtensionImpl.kt:354)
    at com.android.build.gradle.internal.dsl.BaseAppModuleExtension.signingConfigs(BaseAppModuleExtension.kt)
    at com.android.build.gradle.internal.dsl.BaseAppModuleExtension_Decorated.signingConfigs(Unknown Source)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at org.gradle.internal.metaobject.BeanDynamicObject$MetaClassAdapter.invokeMethod(BeanDynamicObject.java:484)
    at org.gradle.internal.metaobject.BeanDynamicObject.tryInvokeMethod(BeanDynamicObject.java:196)
    at org.gradle.internal.metaobject.CompositeDynamicObject.tryInvokeMethod(CompositeDynamicObject.java:98)
    at org.gradle.internal.extensibility.MixInClosurePropertiesAsMethodsDynamicObject.tryInvokeMethod(MixInClosurePropertiesAsMethodsDynamicObject.java:34)
    at org.gradle.internal.metaobject.ConfigureDelegate.invokeMethod(ConfigureDelegate.java:56)
    at build_1lgz6zr90cqrpx870aaikniva$_run_closure1.doCall(C:\Users\fimartin\Documents\Repo_GIT\Prueba_BLE_APP\ESP32_BLE_OTA_Android\app\build.gradle:32)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at org.gradle.util.internal.ClosureBackedAction.execute(ClosureBackedAction.java:72)
    at org.gradle.util.internal.ConfigureUtil.configureTarget(ConfigureUtil.java:155)
    at org.gradle.util.internal.ConfigureUtil.configure(ConfigureUtil.java:106)
    at org.gradle.util.internal.ConfigureUtil$WrappedConfigureAction.execute(ConfigureUtil.java:167)
    at org.gradle.internal.extensibility.ExtensionsStorage$ExtensionHolder.configure(ExtensionsStorage.java:173)
    at org.gradle.internal.extensibility.ExtensionsStorage.configureExtension(ExtensionsStorage.java:64)
    at org.gradle.internal.extensibility.DefaultConvention.configureExtension(DefaultConvention.java:364)
    at org.gradle.internal.extensibility.DefaultConvention.access$500(DefaultConvention.java:45)
    at org.gradle.internal.extensibility.DefaultConvention$ExtensionsDynamicObject.tryInvokeMethod(DefaultConvention.java:301)
    at org.gradle.internal.metaobject.CompositeDynamicObject.tryInvokeMethod(CompositeDynamicObject.java:98)
    at org.gradle.internal.extensibility.MixInClosurePropertiesAsMethodsDynamicObject.tryInvokeMethod(MixInClosurePropertiesAsMethodsDynamicObject.java:34)
    at org.gradle.groovy.scripts.BasicScript$ScriptDynamicObject.tryInvokeMethod(BasicScript.java:135)
    at org.gradle.internal.metaobject.AbstractDynamicObject.invokeMethod(AbstractDynamicObject.java:163)
    at org.gradle.groovy.scripts.BasicScript.invokeMethod(BasicScript.java:84)
    at build_1lgz6zr90cqrpx870aaikniva.run(C:\Users\fimartin\Documents\Repo_GIT\Prueba_BLE_APP\ESP32_BLE_OTA_Android\app\build.gradle:31)
    at org.gradle.groovy.scripts.internal.DefaultScriptRunnerFactory$ScriptRunnerImpl.run(DefaultScriptRunnerFactory.java:91)
    ... 164 more
It can't start to compile because there is something wrong with Gradle.

Do you know what is happening?

Thanks.

esp32_ble_ota getting Incomplete while ota

I tried to do an update of the fw by using the ble android app.
From the app side it is saying that the transfer was completed but at the end from the esp32 side it is saying it is incompleted and it is not restarting.

What could be the issue?

Thanks a lot

Firmware uploaded but performUpdate fails while partitionEraseRange...

Hello all,
I have following problem on WeMoS D1 MINI ESP32 platform: firmware update is uploaded, but while executing

size_t written = Update.writeStream(updateSource);

image

it fails:

00:57:35.339 -> Notify callback for characteristic fb1e4003-54ae-4a28-9f74-dfccb248601d of data length 3
00:57:35.339 -> TX  F2 00 0F 
00:57:35.339 -> Status 1 on characteristic fb1e4003-54ae-4a28-9f74-dfccb248601d with code 0
00:57:35.373 -> Write binary file /update.bin
00:57:35.514 -> Complete
00:57:40.541 -> Trying to start update
00:57:40.541 -> 
00:57:40.541 -> abort() was called at PC 0x40081ece on core 1
00:57:40.541 -> 
00:57:40.541 -> 
00:57:40.541 -> Backtrace: 0x400836a5:0x3ffd1150 0x40093601:0x3ffd1170 0x40098855:0x3ffd1190 0x40081ece:0x3ffd1210 0x400e1973:0x3ffd1260 0x400db57d:0x3ffd1280 0x400d32ff:0x3ffd12a0 0x400d355f:0x3ffd12c0 0x400d2582:0x3ffd12e0 0x400d2b4b:0x3ffd1360 0x400d2e4b:0x3ffd13b0 0x400dc63d:0x3ffd13e0
00:57:40.541 -> 
00:57:40.541 -> 
00:57:40.541 -> 
00:57:40.541 -> 
00:57:40.541 -> ELF file SHA256: 0f188e5b9d82dfd5
00:57:40.574 -> 
00:57:40.681 -> Rebooting...
00:57:40.681 -> ets Jun  8 2016 00:22:57

Backtrace decoded shows:

Decoding stack results
0x400836a5: panic_abort at /Users/ficeto/Desktop/ESP32/ESP32S2/esp-idf-public/components/esp_system/panic.c line 408
0x40093601: esp_system_abort at /Users/ficeto/Desktop/ESP32/ESP32S2/esp-idf-public/components/esp_system/esp_system.c line 137
0x40098855: abort at /Users/ficeto/Desktop/ESP32/ESP32S2/esp-idf-public/components/newlib/abort.c line 46
0x40081ece: esp_flash_erase_region at /Users/ficeto/Desktop/ESP32/ESP32S2/esp-idf-public/components/spi_flash/esp_flash_api.c line 561
0x400e1973: esp_partition_erase_range at /Users/ficeto/Desktop/ESP32/ESP32S2/esp-idf-public/components/spi_flash/partition.c line 540
0x400db57d: EspClass::partitionEraseRange(esp_partition_t const*, unsigned int, unsigned int) at /Users/pavol/Library/Arduino15/packages/esp32/hardware/esp32/2.0.14/cores/esp32/Esp.cpp line 432
0x400d32ff: UpdateClass::_writeBuffer() at /Users/pavol/Library/Arduino15/packages/esp32/hardware/esp32/2.0.14/libraries/Update/src/Updater.cpp line 211
0x400d355f: UpdateClass::writeStream(Stream&) at /Users/pavol/Library/Arduino15/packages/esp32/hardware/esp32/2.0.14/libraries/Update/src/Updater.cpp line 386
0x400d2582: performUpdate(Stream&, unsigned int) at /Users/pavol/Documents/esp32_ble_ota/esp32_ble_ota.ino line 215
0x400d2b4b: updateFromFS(fs::FS&) at /Users/pavol/Documents/esp32_ble_ota/esp32_ble_ota.ino line 265
0x400d2e4b: loop() at /Users/pavol/Documents/esp32_ble_ota/esp32_ble_ota.ino line 410
0x400dc63d: loopTask(void*) at /Users/pavol/Library/Arduino15/packages/esp32/hardware/esp32/2.0.14/cores/esp32/main.cpp line 50

Another error:

02:20:25.530 -> Incomplete
02:20:25.530 -> Expected: 305472Received: 304000
02:20:27.531 -> Write binary file /update.bin
02:20:27.598 -> Complete
02:20:32.618 -> Trying to start update
02:20:32.618 -> Written only : 0/305472. Retry?
02:20:32.618 -> Error Occurred. Error #: 8
02:20:32.618 -> Notify callback for characteristic fb1e4003-54ae-4a28-9f74-dfccb248601d of data length 36
02:20:32.618 -> TX  0F 57 72 69 74 74 65 6E 20 3A 20 30 2F 33 30 35 34 37 32 20 5B 30 25 5D 20 0A 45 72 72 6F 72 20 23 3A 20 38 
02:20:32.652 -> Status 1 on characteristic fb1e4003-54ae-4a28-9f74-dfccb248601d with code 0
02:20:37.827 -> Removing update file

What I try to do

  1. I flash esp32_ble_ota firmware to WeMoS D1 MINI ESP32

  2. I upload an empty SPIFFS to ESP32:

        Leaving...
        Hard resetting via RTS pin...
        [SPIFFS] data   : /Users/pavol/Documents/esp32_ble_ota/data
        [SPIFFS] start  : 1966080
        [SPIFFS] size   : 1856
        [SPIFFS] page   : 256
        [SPIFFS] block  : 4096
        [SPIFFS] upload : /var/folders/0d/70vb7f0j1t114w9nkrmypn4r0000gn/T/arduino_build_904895/esp32_ble_ota.spiffs.bin
        [SPIFFS] address: 1966080
        [SPIFFS] port   : /dev/cu.usbserial-02T9S8H5
        [SPIFFS] speed  : 921600
        [SPIFFS] mode   : dio
        [SPIFFS] freq   : 40m
    
        esptool.py v4.5.1
        Serial port /dev/cu.usbserial-02T9S8H5
        Connecting....
        Chip is ESP32-D0WDQ6 (revision v1.0)
        Features: WiFi, BT, Dual Core, 240MHz, VRef calibration in efuse, Coding Scheme None
        Crystal is 40MHz
        MAC: 84:cc:a8:5f:57:ac
        Uploading stub...
        Running stub...
        Stub running...
        Changing baud rate to 921600
        Changed.
        Configuring flash size...
        Auto-detected Flash size: 4MB
        Flash will be erased from 0x001e0000 to 0x003affff...
        Compressed 1900544 bytes to 3420...
        Writing at 0x001e0000... (100 %)
        Wrote 1900544 bytes (3420 compressed) at 0x001e0000 in 8.1 seconds (effective 1888.1 kbit/s)...
        Hash of data verified.
    
  3. I compile Blink firmware and upload final bin image to Android application (blink_firmware.bin). Both firmwares were compiled with partition app_spiffs (check below)

  4. I try to upload blink firmware via Android updater application EPS32 BLE OTA to ESP32. The transfer is successfull, but problem occurres as described above.

What am I doing wrong???

My Partitions layout

Here is my partition layout:

app_sppifs.cvs:

# Name,   Type, SubType, Offset,  Size, Flags
nvs,      data, nvs,     0x9000,  0x5000,
otadata,  data, ota,     0xe000,  0x2000,
app0,     app,  ota_0,   0x10000, 0x1D0000,
spiffs,     data,  spiffs, 0x1E0000,0x1D0000,
coredump, data, coredump,0x3E0000,0x10000,

I supposed that app0 and spiffs needs to have the same size, but the update fails anyway...

Board partition scheme

...
d1_mini32.menu.PartitionScheme.min_spiffs_nocoredump=APP_SPIFFS
d1_mini32.menu.PartitionScheme.min_spiffs_nocoredump.build.partitions=app_spiffs
d1_mini32.menu.PartitionScheme.min_spiffs_nocoredump.upload.maximum_size=1966080

Thanks a lot for any hint to move forward...

Pavol

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.