Problem communicating from circuitpython to appinventor + Bluetooth Ble

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)
Cordially
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
Cordially
Mr Mathieu
image reception

Good morning,
yes the code_python.pdf is complete
This is a simple code to test two way bluetooth communication.
Cordially
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)
data = "45.45.3.70"
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
Cordially
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
Cordially
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.

https://docs.circuitpython.org/projects/ble/en/latest/api.html#adafruit_ble.BLEConnection.connected

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
Cordially
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?

That's all very good news. I have been unable to view the HeartRateMonitor Blocks, the Blocks Area is corrupted (probably occurred during the upload to the forum post). However, it contains a very old version of the BLE extension - you will need to update that to the latest extension version, which contains all the other technical updates since version 2 (version 2 is very very old).

Good morning,
I normally updated the bluetooth extension. I have verified that the app still works with this update.
I attach the aia file of the application to communicate from circuitpython to the tablet
Cordially
Mr Mathieu
HeartRateMonitorGM_V11.aia (331.2 KB)

Good morning,

I have finally just finished the AppInventor application which allows communication in Bluetooth Ble with the M4 Airlift lite metro card.
I thank Christophe John Ward for his help, his explanations and the time he devoted to my various problems.
Communication is essentially done through character strings.
From the tablet I can control a servo motor and read information from the sensors.
Attached is the pdf containing the Python program and AppInventor
Cordially
Mr Mathieu
explication_projet_Bluetooth_AppInventor.pdf (490.0 KB)
appli_pubelle_Ble_v11.aia (883.9 KB)

That is good news Mr Mathieu - I'm not sure I was that helpful, but I hoped at least to keep you exploring all the possibilities to find the solution.