How to send data from sd card to another device via bluetooth?

Pepper&Salt
Posts: 1
Joined: Sat May 19, 2018 9:11 am

How to send data from sd card to another device via bluetooth?

Postby Pepper&Salt » Sat May 19, 2018 9:19 am

I have some few files in my sd card module which is connected to my esp32. I would like to create a function in which if I send it the file name via the Bluetooth Serial it should send the file to the device. But I do not know how to do that I googled for help. But I can't find anything useful for now I can only create a sketch that will show me the contents of the sd card module via bluetooth:

Code: Select all

/*
 * Connect the SD card to the following pins:
 *
 * SD Card | ESP32
 *    D2       -
 *    D3       SS
 *    CMD      MOSI
 *    VSS      GND
 *    VDD      3.3V
 *    CLK      SCK
 *    VSS      GND
 *    D0       MISO
 *    D1       -
 */
#include "FS.h"
#include "SD.h"
#include "SPI.h"
#include "BluetoothSerial.h"


 
BluetoothSerial SerialBT;

void listDir(fs::FS &fs, const char * dirname, uint8_t levels){
    SerialBT.printf("Listing directory: %s\n", dirname);

    File root = fs.open(dirname);
    if(!root){
        SerialBT.println("Failed to open directory");
        return;
    }
    if(!root.isDirectory()){
        SerialBT.println("Not a directory");
        return;
    }

    File file = root.openNextFile();
    while(file){
        if(file.isDirectory()){
            SerialBT.print("  DIR : ");
            SerialBT.println(file.name());
            if(levels){
                listDir(fs, file.name(), levels -1);
            }
        } else {
            SerialBT.print("  FILE: ");
            SerialBT.print(file.name());
            SerialBT.print("  SIZE: ");
            SerialBT.println(file.size());
        }
        file = root.openNextFile();
    }
}

void setup() {
    SerialBT.begin("ESP32SD"); 
  pinMode(22, INPUT_PULLUP);

}

 void loop() {
if (digitalRead(22) == LOW) {
    if(!SD.begin()){
        SerialBT.println("Card Mount Failed");
        return;
    }
    uint8_t cardType = SD.cardType();

    if(cardType == CARD_NONE){
        SerialBT.println("No SD card attached");
        return;
    }

    SerialBT.print("SD Card Type: ");
    if(cardType == CARD_MMC){
        SerialBT.println("MMC");
    } else if(cardType == CARD_SD){
        SerialBT.println("SDSC");
    } else if(cardType == CARD_SDHC){
        SerialBT.println("SDHC");
    } else {
        SerialBT.println("UNKNOWN");
    }

    uint64_t cardSize = SD.cardSize() / (1024 * 1024);
    SerialBT.printf("SD Card Size: %lluMB\n", cardSize);

    listDir(SD, "/", 0);
    
    SerialBT.printf("Total space: %lluMB\n", SD.totalBytes() / (1024 * 1024));
    SerialBT.printf("Used space: %lluMB\n", SD.usedBytes() / (1024 * 1024));
}
 }

  

I am a newbie. I even looked up the bluetooth document of the esp32 provided by expressif. But I can't find it. Is it not supported by the SDK?

Thanks!

Jaben23
Posts: 2
Joined: Sat May 22, 2021 11:54 pm

Re: How to send data from sd card to another device via bluetooth?

Postby Jaben23 » Sat May 22, 2021 11:58 pm

BRO!!! I want to do the same thing, but I can´t find anything, did you make it work?? can you share your´e code? I want to send de data created from my SD by bluetooth to my phone

Who is online

Users browsing this forum: Valter and 144 guests