cancel
Showing results for 
Search instead for 
Did you mean: 

Best approach to send large chunks of bytes using BlueNRG-2 on STEVAL-STWINKT1

moniosni
Associate II

Hello all!

I have a STEVAL-STWINKT1 board and I have created my custom services and characteristics to be able to send to a Raspberry Pi an uint8_t array of 240 bytes.

From the RPi side, I am using bluepy to connect to my board and receive the notifications from it.

However, I would like to send this array as if it was 10 times larger, hence 2400 byets long, and accumulate it on the RPi side untill all 10 iterations have been finished.

What's the best approch to do so?

From the STWINKT1 side, I have created a for loop where I call:

aci_gatt_update_char_value(HWServW2STHandle, MY_hwHandle, 0, sizeof(my_buff) ,my_buff);

HAL_Delay(2);

Whereas, on the RPi side I have a while loop where I append to a list the incoming bytearray from the characteristic.

But after 4-5 iterations, the connection is discontinued and I am not able to accumulate all 10 iterations.

What would be the best approach to create a "stream" sending large amount of bytes to the RPi?

2 REPLIES 2
Scott Löhr
Senior II

It seems like you need to debug and find what is causing the link to drop - a tight loop on both sides doing RF-intensive work sounds like a likely culprit (unless you have your RTOS and task priorities and work very well apportioned on both sides). A loop receiving on the RPi side sounds wrong - the BLE stack should be notifying you whenever a update is received on a Characteristic and that should be enough. The loop sending from the BlueNRG side could be converted into a slower paced timer event. Regardless, it seems like you need to add a little structure to your packets, at least a header, so that the client side can determine first that it should receive 10, and then that it did receive 10 different packets.

moniosni
Associate II

Hello Scott!

Thank you very much for your reply and for your hints! I will definetely try them!

I should have mentioned that I don't use RTOS on the STWINKT1 side, just bare metal C. I have based my code on the project "BLE_SampleApp" from the examples that come with this board (STSW-STWINKT01)

From the RPi side, I used rasppi_ble_receiver.py script (https://gist.github.com/garystafford/1a8da165f15bc576add48735c285ed8b) , which uses the BluePy package, where the author has a while True loop which constantly receives notifications from the characteristic that he wishes.

What I understand is that for receiving consecutive packets this approach is not optimal. Maybe I should use the waitForNotifications() method of the class Peripheral (https://github.com/IanHarvey/bluepy/blob/master/bluepy/btle.py), so I could implement the approach that you indicated.