Problem communicating from circuitpython to appinventor + Bluetooth Ble

Good morning,

I'm working on the circuitpython Metro M4 airlitf board with a Ble bluetooth and appinventor.
I tested my python code with the Adafruit app "Bluefruit LE Connect app provides iOS & Android". I can send and receive data on this app.
I have a problem communicating from circuitpython to appinventor.

I must make an error in my code for the reception, but after consulting forums I do not see my error. I do not receive the value "45,45.3,70" on appinventor.
When I send the value 3 from appinventor to the circuitpython board the python code should return me the value "45,45.3,70" and nothing happens.

Thank you for your help

Attached are the python and aia files from appinventor and an image of the serial communication

Mr Mathieu
appli_pubelle_Ble.aia (276.8 KB)

code_python.pdf (17.7 KB)

I would loosen up that test, to see what is incoming.

In case I missed something else, here is what you should have posted:


You might also add a RegisterforStrings BLE block after your connection completes, to automatically receive Strings when they arrive.

Hello Mr Mathieu - welcome to the forum.

Looking at the Adafruit script, they have omitted the use of UUIDs, which is the bedrock of BLE. Normally we would either change the code to use UUIDs or communicate with Classic Bluetooth instead. However, I see you have modified the code.

Is the value 3 received?

Good morning,
Yes the circuitpython board receives the value 3 and displays the message "reading sensors" in the REPL
and then send the following command uart.write(donnees)
Mr Mathieu

I see in the App that there are UUIDs - the pdf of the script, is that the entire script?

That isn't going to be received by the App because it's expecting a Characteristic value.

Good morning
I removed the test and it does not change. I still have no reception
Mr Mathieu
image reception

Good morning,
yes the code_python.pdf is complete
This is a simple code to test two way bluetooth communication.
Mr Mathieu

....because your Script is not identifying the value type (Characteristic UUID) and not sending the value as a Characteristic. Therefore, the data will never be received.

I think there are three possible remedies:

  1. Find another Python script that supports the BLE GATT system. I can confirm that the Service UUID in the App is correct for UART communication.

  2. Instead of BLE, use Classic Bluetooth in the App (No GATT required), with minor change to the existing Script.

  3. Use a script written in C that supports the BLE GATT system (99.99% of App Inventor Users do this because the Arduino platform supports it too). There are many examples in the forum.

Concerning the original Script, are the UUIDs defined in one of the files we cannot see ('from ###')?

Concerning the App code, Google requires location to be switched on and depending on your Android version, certain permissions are required too. That's all missing from your Blocks but is easy to add.

Hi again Mr Mathieu

Attached is an edited version of your App Inventor file. I have made these changes:

  1. Updated the BLE extension to the latest version (this is a Beta and will be updated again soon)

  2. Added permission requests

  3. Added a location sensor component (else the permission for Location would be rejected)

  4. Added the Block "Register for Strings" - you cannot receive a String Stream without first registering this requirement.

  5. Corrected the use of 'upcase' in the strings received Block

What we need: Details!

  1. Is the ESP32 stand-alone or connected to a microcontroller (e.g. Arduino)

  2. I have assumed the Python version is outputting UTF-16 strings - is that true?

  3. The permissions assume that your Smartphone is Android v12. If not, what is it's Android version?

appli_pubelle_Ble_edit.aia (286.1 KB)

Good morning,
I work on the circuitpython metro m4 board with airlift lite integrated on the board.
the data sent by the command uart.write

code_python.pdf (70.4 KB)
data = ""
I am using M7 tablet with android 9
attached the pdf file with the python code and an image of the appinventor application's interaction with python
Mr Mathieu

Hi again Mr Mathieu

We are not making any progress yet, but the details about the hardware help greatly. :sunglasses:

In the Python script, which Adafruit defined to work with their App, the file bleio is imported. We need to see that file.

Also in the script, the word 'adapter' is defined, starting the ESP32 bluetooth. In the English language, adapter (adaptor) would describe an add-on module (hardware), but I think you are invoking BLE when perhaps the original script used WiFi? I ask because 'airlift lite' specifically targets WiFi whereas 'airlift' targets both WiFi and BLE. ESP32 models from 2019 support BLE 5.0 with GATT, as does App Inventor, so the bleio file is key.

There are a number of Lenovo M7 tablet versions - we need to know the exact model that you are using.

Thank you for the diagram - a picture paints a thousand words!

Edit - is Python string output UTF-16 or UTF-8?

Good morning,
sorry to answer you so late, but I spent 3 days in my family.
For the tablet it is the model: Lenovo TB-7305F with android 9
For the _bleio library I used it to see the MAC address. I don't know if I should use it.
I'm new to coding in python, but I'm not familiar with object programming.
for UTF-16 or UTF-8 I don't know. I am using mu editor software to program Circuitpython board
Adafruit's python scipt works great with Bluefruit Connect software
Mr Mathieu

... that would be because it's their hardware, their script and their Software :grin:

What I can tell you is, we have had more issues with Adafruit hardware than any other I can think of, mostly because they are a little unconventional - they are perhaps not really expecting us to use anything other than their software with their boards but they do at least have libraries for the Arduino IDE (C language).

We need to see that file - hopefully it is that file that supports BLE GATT.

Edit: Well actually adafruit_ble is built on top of bleio and it isn't using BLE GATT.

Important: In your App Inventor Project, you Have a Service UUID and two Characteristic UUIDs - where did you get those from? They are what we want to work with in the Script.

The Lenovo M7 is a nice Tablet. I have been trying to find out it's Bluetooth Version based on the model TB-7305F, but unfortunately there are a few sub-versions, including only having WiFi, no Bluetooth at all.

Bluetooth version is usually something Android devices do not tell you - if you still have the box, it probably states the version on there. If you can't find the Bluetooth Version, there is a free App on Google Play that can:

We need to know the Bluetooth version number that your M7 supports. On Android 9, I expect it will be version 4.0 at least, but can't be sure without verification.

If I can find the time, I'll create a Classic Bluetooth App - Classic BT works with Serial (UART).

... forgot to ask - did you try the Project (.aia) file I posted (see Post#12)?. In the Strings Received Block, if anything is received, it is displayed in text_aff.

Try compiling the Project and installing the APK on the M7.

Good morning,

For lenovo M7 tablet TB-7305F WLAN 802 11 B/G/N + BT 4.0 with Android 9
This afternoon I managed to receive information from the circuitpython board to the tablet. I modified a file from "Jose Luis Núñez hacked by Gordon Moore"
So I have an application to transmit and another to receive data in bluetooth.
On the other hand, my trash application must work in both directions, I still have work to do.
I removed the _bleio library from the python code and I have no error.
For the UUIDs, the Adafruit application displays them on the Bluefruit Connect application.
I am a teacher with a Terminal class, I only have 2 hours of lessons per week. I can't teach two programming languages ​​to my students. The python language is required for the written test of the baccalaureate, that's why I chose circuitpython.
your appinventor application is easy to learn for students. I'm sure if I can make my application work in the sense of bluetooth communication, other SI teachers will surely be interested
Mr Mathieu
attached the code in python of the apllications and appi aia
connunication sens1 sens2.pdf (19.1 KB)
HeartRateMonitorGM_V11.aia (313.7 KB)

Hi Mr Mathieu

I agree - but isn't it important to teach them how to use BLE in the way it is intended?