Why does my BLE python code (using Jupyter and PythonHere) NOT detect any devices?

Viewed 21

I am very new in programming, I am using my iPad to write python code. My end goal is to create an android app that utilises BLE (bluetooth low energy) technology to act as a central, in order to get the RSSI values of some stationary beacons (peripherals).

As a programming environment, I am using an iPadOS app called Carnets. It incorporates Jupyter Notebooks and runs locally on the iPad.

Then I am using an Android app called PythonHere, which allows me to write python code on Carnets that is executed on my Android device, through this app. The ways to establish this connection is describes here https://herethere.me/pythonhere/app.html

PythonHere includes a library called able, that allows the use of Android BLE services.

So my code looks like this: (I am denoting individual Jupyter cells with 4 hyphens here, for lack of a better way to do this. I sequentially run every cell when I test my ‘application’)

!pip install pythonhere
———-
import pythonhere
———-
%load_ext pythonhere
———-
%connect-there
———-
%%there 
from able import BluetoothDispatcher
from kivy.logger import Logger

class BLE(BluetoothDispatcher):
    def on_device(self, device, rssi, advertisement):
        # some device is found during the scan
        name = device.getName()
        Logger.info('A device was found')
        if name and name.startswith('Amaz'):  # this is my watch 
            self.device = device
            self.stop_scan()
            
ble = BLE()
————
%%there
ble.start_scan()
————
%there -b log
————
%%there
ble.stop_scan()

With this, I am trying to see if it detects any device at all. The scan starts, because I get a prompt on my Android phone to allow the use of bluetooth services, but then the logger doesn’t output anything.

Am I supposed to use an additional function of the BluetoothDispatcher class before on_device? Though, I can’t find anything relevant neither on the documentation, nor on the examples of the able library https://herethere.me/able/about.html

Should I perhaps compile the code and make an actual test app to try directly on the Android device itself? Or am I missing something else? Any help would be appreciated.

0 Answers
Related