CircuitPython Blinka BLE ble_json_central.py throws KeyError

CircuitPython on hardware including Adafruit's boards, and CircuitPython libraries using Blinka on host computers.

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
seandoyle
 
Posts: 23
Joined: Thu Apr 26, 2012 12:49 pm

CircuitPython Blinka BLE ble_json_central.py throws KeyError

Post by seandoyle »

I'm having some difficulties sending custom JSON messages over BLE from a RP2040/AirLift to a Raspberry Pi Zero W. The RP2040/Airlift seems to be working fine - I can read the values in the AdaFruit Bluefruit LE Connect iOS app.

When I try running the example code ble_json_peripheral.py on the RP2040 and the ble_json_central.py on the Zero W I get the following error:

Code: Select all

$ python ble_json_central.py 
Scanning for BLE device advertising our sensor service...
Connected
Traceback (most recent call last):
  File "/home/sean/CakeControl/ble_json_central.py", line 26, in <module>
    service = connection[SensorService]
  File "/home/sean/.local/lib/python3.9/site-packages/adafruit_ble/__init__.py", line 112, in __getitem__
    raise KeyError("{!r} object has no service {}".format(self, key))
KeyError: "<adafruit_ble.BLEConnection object at 0xb5471d18> object has no service <class 'ble_json_service.SensorService'>"
So - it seems to make the connection just fine (and the RP2040's ble_json_central.py handles the connection and disconnection).

When i try to inspect the central's connection object it's consistent with the Python KeyError but I don't know how to proceed. Any suggestions welcomed.

Here are the Python libraries:

Code: Select all

Adafruit-Blinka==8.19.0
adafruit-blinka-bleio==4.1.0
adafruit-circuitpython-ble==10.0.2
adafruit-circuitpython-busdevice==5.2.5
adafruit-circuitpython-requests==1.13.3
adafruit-circuitpython-typing==1.9.3
Adafruit-PlatformDetect==3.46.0
Adafruit-PureIO==1.1.10
adafruit-python-shell==1.6.0
args==0.1.0
async-timeout==4.0.2
bleak==0.20.2
certifi==2020.6.20
chardet==4.0.0
clint==0.5.1
colorzero==1.1
dbus-fast==1.86.0
distro==1.5.0
gpiozero==1.6.2
idna==2.10
numpy==1.19.5
picamera2==0.3.9
pidng==4.0.9
piexif==1.1.3
Pillow==8.1.2
pyftdi==0.54.0
pyserial==3.5
python-apt==2.2.1
python-prctl==1.7
pyusb==1.2.1
requests==2.25.1
rpi-ws281x==5.0.0
RPi.GPIO==0.7.1
simplejpeg==1.6.4
six==1.16.0
spidev==3.5
ssh-import-id==5.10
sysv-ipc==1.1.0
toml==0.10.1
typing-extensions==4.0.1
urllib3==1.26.5
v4l2-python3==0.3.2
The version of Linux:

Code: Select all

Linux raspberrypi 6.1.21+ #1642 Mon Apr  3 17:19:14 BST 2023 armv6l GNU/Linux
And the version of bluez-firmware:

Code: Select all

apt list bluez-firmware -a
Listing... Done
bluez-firmware/stable,now 1.2-4+rpt10 all [installed]
bluez-firmware/stable 1.2-4 all

Locked
Please be positive and constructive with your questions and comments.

Return to “Adafruit CircuitPython”