2

My project is to transfer an image wirelessly via BLE from my Sparkfun EDGE board using the Arduino IDE to another laptop. In the following, for simplicity, I have reduced the program to transmit integers via BLE. This already works but it takes a long time (~0.5 seconds) to transfer a few bytes. However, from the BLE specifications, much more should be possible. This is the stripped down code for the Board using Arduino:


#include <ArduinoBLE.h>
#include "utility/HCI.h"    // needed for sendcommand
#include <string>

const char BLE_PERIPHERAL_NAME[] = "Peripheral Hello World BLE"; BLEService Test("83436682-10c6-4dad-acb1-133927f3f080"); BLEStringCharacteristic HelloWorlds("83436682-10c6-4dad-acb1-133927f3f080", BLERead | BLENotify, 512);

#define SERIAL_PORT Serial #define BAUD_RATE 115200 //(originally, 460800)

void setup() {

// Start up serial monitor SERIAL_PORT.begin(BAUD_RATE);

#ifdef BLE_Debug BLE.debug(SERIAL_PORT); // enable display HCI commands #endif BLE.setLocalName(BLE_PERIPHERAL_NAME); BLE.begin();

BLE.setAdvertisedService(Test);

Test.addCharacteristic(HelloWorlds);

BLE.addService(Test); BLE.advertise(); //BLE part end }

void loop(){ int period=3000; //minimum time [ms] to be spent in each loop. This is to give the BLE enought time to transmit. To be adjusted depending on the test. unsigned long timing=millis();

BLE.poll();

int v1;
v1 = rand() % 100; 

//Generate 8 integer to be transmitted
String sixteen=String(v1);
for (uint32_t ccc=0; ccc &lt; 8; ccc=ccc+1){

  v1 = rand() % 100; 
  sixteen = sixteen + &quot; &quot; +String(v1);      
}

HelloWorlds.writeValue(sixteen); SERIAL_PORT.print(sixteen); SERIAL_PORT.print(" ");

while(millis() < timing + period){ }

}

The code compiles, runs on the EDGE board and I receive the random bytes on my phone (NRF app) as well as on the other laptop. On the other laptop, I use gatttool in the Ubuntu terminal to receive the packets:

gatttool -I
connect C0:4B:39:C9:B1:04
char-read-hnd c

(I obtain the handle "c" through inspecting the characteristics before). Then, I do receive the String, but it takes the some hundreds of milliseconds until the integers are displayed. I also automated this in a Python script using pexpect and then print the timestamps after the sendline and expect command and it shows the time difference of ~hundreds of milliseconds.

The data rate that I target should be at least hundreds of bytes per second.

Thank you kind community.

0 Answers0