How to send data from sd card to another device via bluetooth?
Posted: 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:
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!
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));
}
}
Thanks!