BLE data communication with Tympan

Hello Tympan Community,
We have developed an app in Flutter that communicates with Tympan Rev E via BLE. The data sent from app are received in Tympan as chunks instead of complete data in one go.
For example, the data sent from app : 123,28,-20,-22,-16,-14,-15,-18,-21
It is received at Tympan as: RECV 14 0 RECV 14 18 123,28,-20,-22,-16RECV 14 16 ,-14,-15,-18,-21

I wish to make Tympan to receive the BLE data sent from the app as once completely in one go. How can I achieve that ?

Hi!

I believe that you are seeing the extra text added by the Bluetooth module when receiving BLE data. Two questions:

  1. Do you know if you are attempting a BLE connection or if you are attempting a Bluetooth Classic (SPP protocol) connection?

  2. Also, in your Tympan code, are you reading the incoming data using a command like Serial1.read(), or are you using the Tympan “BLE” class to handle the messages?

Chip

Hi chip,
I’m using BLE for the communication. After connecting to Tympan via BLE, our flutter app lists all the services and characteristics from Tympan and I’m writing the data to be sent to one of the characteristics.
I’m using the EchoBLE code provided by Tympan for receiving the data to Tympan.

Hi!

The “EchoBLE” example is intended for use in debugging the details of the BLE link itself, rather than being an example for everyday use of the bluetooth link.

Instead, I would recommend looking at the example 06-AppTutorial/BasicGain_wApp.

As shown in this sketch, the key elements of using the BLE link are:

  1. Instantiate the BLE class: BLE ble(&myTympan);
  2. In your setup(), call the BLE setup method: ble.setupBLE(myTympan.getBTFirmwareRev());
  3. In your loop(), get any BLE messages that have arrived: String msgFromBle; int msgLen = ble.recvBLE(&msgFromBle);
  4. Interpret the string of received characters however you like. I usually take the old-school approach of looking at each character in the String individually (respondToByte(msgFromBle[i])), but you don’t have to do it this way. When you use recvBLE, you get the whole message that was transmitted from the phone, so you might choose to interpret it as a complete message rather than character-by-character.

By using the method described above, you will not have to deal with the “RECV” characters that you mentioned in your original post.

Chip

Hi,
Following the methods you provided, I could get the data as expected now.
Thank you.

Yay! I’m glad it worked!

Hi,
By following the methods you shared, I could eliminate the extra text added by Bluetooth module. When I print the received data using Serial.print(data), it appears like received on one go.
But, when I print the same using Serial.println(data), it prints as two or three chunks.
It creates an issue while parsing the received data using the delimiter (here it is comma).

How can I solve this issue ?
Changing the MTU size or any other ways can help me with this ?

Hi, to send a message in BLE mode, you need to use the ‘sendMessage’ command. In the BasicGain_wApp example that I linked earlier, it looks like this:

‘ble.sendMessage(str);’

Where str is your string of text.

Chip