viktorvano / Bluetooth-for-STM32-and-Android

Bluetooth Classic and Bluetooth LE examples for STM32 and Android + RFID PN532
Apache License 2.0
80 stars 46 forks source link

Sending ECG Data via BLE (EM9301) on MaxRefDes100# HealthSensor Platform #2

Open vnm1911 opened 3 years ago

vnm1911 commented 3 years ago

Hello Viktor,

I saw your tutorial video on YouTube. STM32 and Android tutorial - ECG (single lead, 2 and 3 electrode configuration) It is really good. I thank you for that.

We are trying to develop a multi sensor wearable device using MaxRefDes100# and we are struggling with sending ECG data to mobile device via on chip BLE (EM9301). The onboard Microcontroller is Max32620 and ECG sensor is Max30003 (and other sensors).

Here are the useful links to the device https://media.digikey.com/pdf/Data%20Sheets/Maxim%20PDFs/MAXREFDES100_Web.pdf https://www.maximintegrated.com/en/design/reference-design-center/system-board/6312.html

We need to send almost 400 bytes only for ECG, but we are unable to change the default byte size which is 33 bytes I think.

We will be really thankful if you could pls help in any way.

Thanks and Regards VM

viktorvano commented 3 years ago

Well a standard BLE packet size is 20 bytes only. If you want to send more, you need to split the buffer contents into those packets of 20 bytes. That's normally packets are sent as string ending with LF or something: 12,11,15,16,20,.......,14\n

So if you will receive a packet that contains '\n' you know that's the end of a message.

vnm1911 commented 3 years ago

Well a standard BLE packet size is 20 bytes only. If you want to send more, you need to split the buffer contents into those packets of 20 bytes. That's normally packets are sent as string ending with LF or something: 12,11,15,16,20,.......,14\n

So if you will receive a packet that contains '\n' you know that's the end of a message.

Thank you very much for a very prompt reply. You are very kind. Okay we will try that again. But my concern is will there be loss of data and hence eventually a distortion in ECG waveform? We will try and will report you our progress soon.

viktorvano commented 3 years ago

Just another info regarding BLE: In Bluetooth 4.0, BLE was introduced with a maximum payload of 33 bytes (not including Access Address and CRC fields). Each layer in the protocol stack takes its cut:

2 bytes for packet header (type and length), 4 bytes for MIC (when encryption is enabled), 4 bytes for L2CAP header (channel ID and packet length), ATT protocol is left with 23 bytes, which is the default and minimal MTU for ATT protocol. With an ATT write request (or notification), 3 bytes are used by command type and attribute ID, 20 bytes are left for the attribute data.