Search code examples
xamarin.formsarduinobluetoothbluetooth-lowenergyesp32

Arduino ESP32 receive file over BLE (for OTA update)


I want to send a file (bin) from my Xamarin Forms (C#) iOS App over BLE (https://github.com/xabre/xamarin-bluetooth-le) to my ESP32 (Arduino). That file would be a bin file for updating. I found already a solution on how to update the ESP32 out of spiffs (arduino-esp32 do OTA via BLE) but does anyone know how I can receive the file with the ESP32 and save it into spiffs?

(The BLE connection app to esp32 is already fully working, I can send texts, but I don't know how to send files)

Best regards nflug


Solution

  • You have to send the file content as individual bytes and save it to SPIFFS

    You can create and write to a binary file using the function below (Arduino code)

    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();
    }
    

    Check out the usage here ESP32_BLE_OTA_Arduino.

    I have also created an android app to upload the file ESP32_BLE_OTA_Android