BluetoothLE connection, GATT and data

I have been trying to get my head around BluetoothLE using the example available here

https://www.instructables.com/ESP32-BLE-Android-App-Arduino-IDE-AWESOME/

My implementation is ESP32 S3 and Rd-03d/LD2450 radar head with the display to be on an Android tablet. However, before I get that far I need to be able to get the data from the ESP32 to AI2

At first, I was trying to get a CSV string sent over in chunks and then reassemble them in AI2, that was not working so I did consider changing the MTU but thought I had better try GATT as that is the way it should be

To simplify things the ESP is sending three CSV messages with their own characteristic UUIDs

String longMessage1 = "The,quick,brown,dog\n";
String longMessage2 = "jumps,over,the,lazy\n";
String longMessage3 = "dog,quickly\n";

These are being sent continuously and I have nRF Connect on the tablet confirming the transmission.

I have two problems, #1 reliably getting AI2 to connect and then #2 doing anything sensible with the data.

Once I get a connection, I can see the messages coming over (debug text boxes) but only if I disable the “if” statements in BluetoothLE1.StringsRecieved. It does not work even with only the “if-not- is list empty?- get stringValues” enabled.

The various connect/disconnect buttons and text boxes were to try to determine what worked and what didn’t connection wise.

Any clues please?

Radar_BLE_V1.aia (202.5 KB)

A bit of an update I have now got past the first "if" in StringsReceived but when it gets into the second "if" it grinds to a halt.

I have now tested to see if the string is longer than just "()" and then removed them from the CSV string.

The disabled bit enabled so you can see what i am trying to do

The connection is still a problem

You only need to register once, so disable the clock afterwards. You don't want the registrations piling up.

Don't apply text blocks to lists like stringvalues.
Either select item 1 or process it in a For Each Item in List loop. By the nature of the event, the list will never be an empty list (not to be confused with empty text.)

Thank you. I will try that. I think the original had the used an index list but I removed it in my hacking for an answer. When I process each stringvalue by an index list do I still need to strip the brackets prior?

I occurred to me overnight would my use of the Thunkables aia from the original post pose any problems? When I imported it the BLE extension was out of date. Does that mean all the other code, behind the imported blocks, is also out of date? Or at least Thunkables code rather than the latest AI2 version of the code?

The latest version handles permissions better.

Aside from connection blocks, everything else looks the same.

If you see brackets, you are confusing text-ified lists with lists (which can not be seen, only selected from and manipulated with list blocks in memory.)

The [ brackets are JSON notation, which is a common and informative text wrapper for lists and dictionaries, good for text file packaging, but requires decoding back to lists for active use.

The latest test version of the "StringsReceived". None of the Buffer_Listx get populated (Debug4 text) with the 3 methods being tried. Enabling/disabling the set stringValues block that strips the () makes a difference apart from the Debug2 text changing to with or without brackets.

Also I can't understand why I an now getting () brackets when I am sure in my last app I was seeing brackets.

Any clues please?

Look in the Project Properties to see if the flag that turns on JSON representation of lists is turned on.

The ( ) wrappers are obsolete, compared to the JSON encoding.

You should not be applying a text length block to a list. That forces text conversion of the list, into whatever is your current default.

There are better blocks for testing lists, like
is list empty

I covered that in a prior post.

P.S. Read the Introductory articles on How to Work With Lists

This now works with the JSON flag corrected.

The comparison of the characteristic UUID's failed for 2 reasons #1 because I was using a logic compare rather than a text compare and #2 despite the UUIDS being declared in uppercase in both the ESP32 and AI2 code they were being sent from the ESP32 in lower case. This meant that compare tests failed and none of the lists were being populated

As the string is received as ["The,quick"] striping off the [" "] allows "list from csv row - text" block to be used to populate the list.

Amongst other things the comms problem has been mainly solved or at least understood. The ESP32 code stops advertising once the connection is made. If the connection drops it needs a reset to get it to advertise again. Then the AI2 app can reconnect.

or this works as well

Screenshot of the 3 lists Block 1-3 and the lower case UUID

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.