0

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.

gsot96
  • 1
  • 1
    Welcome to StackOverflow. Python on Android is a niche development toolchain and Android bluetooth has its own quirks. The tool that you are using has almost no [github issue tickets](https://github.com/b3b/pythonhere/issues), and the [bluetooth library has a few](https://github.com/b3b/able/issues) which means that there are very few people beyond the project authors who might know anything. You may want to look for similar posts and/or ask there for a response. For newbies I would advise staying with common dev tools (PC/Android Studio/etc.) as there is better community support. – Morrison Chang Sep 16 '22 at 01:11

0 Answers0