0

BleakDBusError in BLE UART tutorial
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

BleakDBusError in BLE UART tutorial

by lamachine on Tue Apr 06, 2021 1:48 pm

I seem to have the midas touch in reverse with BLE. I have found errors in just about everything I have tried. As with my other post regarding logging blinka data, I decided to try the BLE UAR tutorial by Dan Halbert. I upgraded bluez-firmaware, rebooted, and contiued to follow instructions. The python software gets the connection, but when I type in anything it crashes out. I simply want to log data like the cpu temperature, but continue to struggle.

Code: Select all | TOGGLE FULL SIZE
Trying to connect...
Connected
Eval: 42
42Traceback (most recent call last):
  File "blue_eval_client.py", line 26, in <module>
    uart_service.write(b'\n')
  File "/home/pi/.local/lib/python3.7/site-packages/adafruit_ble/services/nordic.py", line 99, in write
    self._tx.write(buf)
  File "/home/pi/.local/lib/python3.7/site-packages/adafruit_ble/characteristics/stream.py", line 34, in write
    self.bound_characteristic.value = buf[offset : offset + 20]
  File "/home/pi/.local/lib/python3.7/site-packages/_bleio/common.py", line 579, in value
    response=self.properties & Characteristic.WRITE,
  File "/home/pi/.local/lib/python3.7/site-packages/_bleio/common.py", line 140, in await_bleak
    return future.result(timeout)
  File "/usr/lib/python3.7/concurrent/futures/_base.py", line 432, in result
    return self.__get_result()
  File "/usr/lib/python3.7/concurrent/futures/_base.py", line 384, in __get_result
    raise self._exception
  File "/home/pi/.local/lib/python3.7/site-packages/bleak/backends/bluezdbus/client.py", line 812, in write_gatt_char
    assert_reply(reply)
  File "/home/pi/.local/lib/python3.7/site-packages/bleak/backends/bluezdbus/utils.py", line 23, in assert_reply
    raise BleakDBusError(reply.error_name)
bleak.exc.BleakDBusError: org.bluez.Error.NotPermitted

lamachine
 
Posts: 35
Joined: Thu Feb 25, 2021 5:01 pm

Re: BleakDBusError in BLE UART tutorial

by mikeysklar on Wed Apr 07, 2021 6:21 pm

Which guide are you following? What devices are you using? It looks a Raspberry Pi is in the mix here. Is it running the current Pi OS release?

mikeysklar
 
Posts: 4594
Joined: Mon Aug 01, 2016 8:10 pm

Re: BleakDBusError in BLE UART tutorial

by lamachine on Mon Apr 12, 2021 2:58 pm

I am following https://learn.adafruit.com/bluefruit-nrf52-feather-learning-guide/central-bleuart

I have a large batch of nRF52840 and running the python central on a (fully updated) Pi4 and updated the firmware for bluez.

I am also trying to run central on another nRF52840.

Bottom line is I need ANY kind of BLE central to read up to 100 BLE advertised data points and log it to a Pi. This can be with Pi BLE or with a serial connection to an nRF52840. Check out my other forum questions for more insight into my trials and tribulations.

https://forums.adafruit.com/search.php?author_id=471534&sr=posts

lamachine
 
Posts: 35
Joined: Thu Feb 25, 2021 5:01 pm

Re: BleakDBusError in BLE UART tutorial

by mikeysklar on Mon Apr 12, 2021 7:03 pm

Following the ble-uart example can you try running the ble_eval_server.py on your Pi and running the ble_eval_client.py code on your nRF52. It looks like you are running it the other way around? I've not seen an example of talking to so many device over BLE, but maybe we should just start with getting the example code working using two devices before getting into the many devices scenario.

https://learn.adafruit.com/circuitpytho ... rt-example

; server
Code: Select all | TOGGLE FULL SIZE
# Provide an "eval()" service over BLE UART.

from adafruit_ble import BLERadio
from adafruit_ble.advertising.standard import ProvideServicesAdvertisement
from adafruit_ble.services.nordic import UARTService

ble = BLERadio()
uart = UARTService()
advertisement = ProvideServicesAdvertisement(uart)

while True:
    ble.start_advertising(advertisement)
    print("Waiting to connect")
    while not ble.connected:
        pass
    print("Connected")
    while ble.connected:
        s = uart.readline()
        if s:
            try:
                result = str(eval(s))
            except Exception as e:
                result = repr(e)
            uart.write(result.encode("utf-8"))


; client

Code: Select all | TOGGLE FULL SIZE
# Connect to an "eval()" service over BLE UART.

from adafruit_ble import BLERadio
from adafruit_ble.advertising.standard import ProvideServicesAdvertisement
from adafruit_ble.services.nordic import UARTService

ble = BLERadio()

uart_connection = None

while True:
    if not uart_connection:
        print("Trying to connect...")
        for adv in ble.start_scan(ProvideServicesAdvertisement):
            if UARTService in adv.services:
                uart_connection = ble.connect(adv)
                print("Connected")
                break
        ble.stop_scan()

    if uart_connection and uart_connection.connected:
        uart_service = uart_connection[UARTService]
        while uart_connection.connected:
            s = input("Eval: ")
            uart_service.write(s.encode("utf-8"))
            uart_service.write(b'\n')
            print(uart_service.readline().decode("utf-8"))

mikeysklar
 
Posts: 4594
Joined: Mon Aug 01, 2016 8:10 pm

Re: BleakDBusError in BLE UART tutorial

by lamachine on Tue Apr 13, 2021 4:11 pm

Following instructions, got an error and looking into it through GIT right now.

pi@HDPi:~/Adafruit_CircuitPython_BLE_BroadcastNet/examples $ python3 ble_eval_server.py
Traceback (most recent call last):
File "ble_eval_server.py", line 12, in <module>
ble.start_advertising(advertisement)
File "/home/pi/.local/lib/python3.7/site-packages/adafruit_ble/__init__.py", line 195, in start_advertising
timeout=0 if timeout is None else timeout,
File "/home/pi/.local/lib/python3.7/site-packages/_bleio/common.py", line 188, in start_advertising
raise NotImplementedError("Advertising not implemented")
NotImplementedError: Advertising not implemented

lamachine
 
Posts: 35
Joined: Thu Feb 25, 2021 5:01 pm

Re: BleakDBusError in BLE UART tutorial

by lamachine on Tue Apr 13, 2021 4:24 pm

I was working with tannewt (don't know how to flag him here) with some issues, and his name is on the contributors to https://github.com/adafruit/Adafruit_CircuitPython_BLE/blob/2f7915018a3fa94597177eb51fb5ab9d5b66ddde/adafruit_ble/__init__.py

Code: Select all | TOGGLE FULL SIZE
def start_advertising(
        self, advertisement, scan_response=None, interval=0.1, timeout=None
    ):
        """
        Starts advertising the given advertisement.
        :param buf scan_response: scan response data packet bytes.
            If ``None``, a default scan response will be generated that includes
            `BLERadio.name` and `BLERadio.tx_power`.
        :param float interval:  advertising interval, in seconds
        :param int timeout:  advertising timeout in seconds.
            If None, no timeout.
        ``timeout`` is not available in CircuitPython 5.x and must be `None`.
        """


It looks like it wants timeout in seconds
https://circuitpython.readthedocs.io/en/latest/shared-bindings/_bleio/index.html

start_advertising(self, data: _typing.ReadableBuffer, *, scan_response: Optional[_typing.ReadableBuffer] = None, connectable: bool = True, anonymous: bool = False, timeout: int = 0, interval: float = 0.1) → None
Starts advertising until stop_advertising is called or if connectable, another device connects to us.

Parameters
data (ReadableBuffer) – advertising data packet bytes

scan_response (ReadableBuffer) – scan response data packet bytes. None if no scan response is needed.

connectable (bool) – If True then other devices are allowed to connect to this peripheral.

anonymous (bool) – If True then this device’s MAC address is randomized before advertising.

timeout (int) – If set, we will only advertise for this many seconds. Zero means no timeout.

interval (float) – advertising interval, in seconds

lamachine
 
Posts: 35
Joined: Thu Feb 25, 2021 5:01 pm

Re: BleakDBusError in BLE UART tutorial

by lamachine on Wed Apr 14, 2021 3:16 pm

DOH! Server means Feather... client means Pi. Connected and crashing for another reason. Please consider this closed.

lamachine
 
Posts: 35
Joined: Thu Feb 25, 2021 5:01 pm

Please be positive and constructive with your questions and comments.