Hello,
How can I send data over 20bytes via ble?
Let's say the file I want to send is 1MB, how can I send it via BLE and how long does it take?
I have an Esp32 card and I saved the data from mpu6050 into this card, it is about 1 MB. How can I send it via BLE?
Interesting project but we are not a free design or code writing service. We will be happy help out with your design and or code but first you have to make an attempt to design it, write it, post it and explain what is not working properly.
If there is hardware it is always best to post links to technical information as there are many versions of the same or different items. Since we cannot see your project, my eyes are to weak, you need to post using the language of electronics, an annotated schematic (best) or a clear picture of a drawing.
Pictures never hurt. Frizzing diagrams are not considered schematics here.
Break the file into 20 byte chunks, and send those one at a time, 50000 times for 1 MB.
You would have much easier time using ESP-NOW to send the data.
#include <BLEDevice.h>
#include <BLEUtils.h>
#include <BLEServer.h>
#include <SPIFFS.h>
#define SERVICE_UUID "4fafc201-1fb5-459e-8fcc-c5c9c331914b"
#define CHARACTERISTIC_UUID "beb5483e-36e1-4688-b7f5-ea07361b26a8"
#define CHUNK_SIZE 20 // Bir BLE paketine sığacak maksimum veri boyutu
BLECharacteristic* pCharacteristic;
void setup() {
Serial.begin(115200);
SPIFFS.begin(true); // SPIFFS dosya sistemi başlatılıyor
BLEDevice::init("ESP32_BLE");
BLEServer *pServer = BLEDevice::createServer();
BLEService *pService = pServer->createService(SERVICE_UUID);
// BLE characteristic oluştur
pCharacteristic = pService->createCharacteristic(
CHARACTERISTIC_UUID,
BLECharacteristic::PROPERTY_READ
);
pService->start();
// BLE reklamını başlat
BLEAdvertising *pAdvertising = pServer->getAdvertising();
pAdvertising->start();
sendFileDataOverBLE("/data.txt");
}
void loop() {
}
void sendFileDataOverBLE(const char* filename) {
// Dosyayı aç
File file = SPIFFS.open(filename, "r");
if (!file) {
Serial.println("Dosya açılamadı!");
return;
}
// Dosyadaki veriyi BLE üzerinden gönder
while (file.available()) {
// Parçayı al ve BLE üzerinden gönder
char chunk[CHUNK_SIZE + 1];
int bytesRead = file.readBytes(chunk, CHUNK_SIZE);
chunk[bytesRead] = '\0'; // Null-terminator ekle
pCharacteristic->setValue(chunk);
pCharacteristic->notify();
delay(50); // Bir sonraki pakete geçmeden önce kısa bir gecikme
}
// Dosyayı kapat
file.close();
}
My code is like this, but when I look at the nrf connect application, I see that only the last data has arrived (I am not sure if it is the last one).
Only 1 row of data arrives.
How can I fix this or how can I divide it into 20 bytes?
@jremington @gilshultz
This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.