Due to high demand expect some shipping delays at this time, orders may not ship for 1-2 business days.
0

Problems getting central UART to recognize peripheral UART
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

Problems getting central UART to recognize peripheral UART

by hufemj on Wed Apr 28, 2021 1:19 pm

I'm having trouble getting the UART central running a Raspberry Pi 4 with Python 3.7.3 and CircuitPython to recognize a UART peripheral running on an nr52840 Feather via CircuitPython. LightBlue recognizes the peripheral and can connect to it. The central device is seeing other peripherals and maybe the UART peripheral, but it is not recognizing it as having a UARTService. I'm using the code examples provided here: https://learn.adafruit.com/circuitpytho ... rt-example

Any ideas on what the problem might be or suggestions on how to figure out what's going on?

Also, please note that I haven't let LightBlue remain connected, since that would cause the peripheral to stop advertising.

Thanks!

Mark

hufemj
 
Posts: 15
Joined: Fri Oct 12, 2018 1:43 pm

Re: Problems getting central UART to recognize peripheral UA

by mikeysklar on Fri Apr 30, 2021 2:55 pm

Mark,

Just to confirm. You are running the ble_eval_client on your Pi and you are running the code.py that starts the advertisement on your nRF52?

Are you running CircuitPython 6.2 stable on your nRF52? Did you download the bundle of the guide page or use the github library for the latest library release?

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

Re: Problems getting central UART to recognize peripheral UA

by hufemj on Sat May 01, 2021 12:31 pm

Yes. I am running ble_eval_client.py on the Pi. It is seeing advertisements, just not an advertisement that satisfies:

if UARTService in ad.services

I can connect to the nRF52 with both Bluefruit Connect and LightBlue. I put a print statement in ble_eval_client.py at the top of the for loop and it displays BoundServiceList for one or more BLE peripherals that looks like this:

<BoundServiceList: 00001800-0000-1000-8000-00805f9b34fb, 00001801-0000-1000-8000-00805f9b34fb, 0000180a-0000-1000-8000-00805f9b34fb, 0000180d-0000-1000-8000-00805f9b34fb, 0000180f-0000-1000-8000-00805f9b34fb>

When the nRF52 connects to Bluefruit Connect, the above BoundServiceList ceases to be displayed on the Pi, I guess because it belongs to the nRF52, which stops advertising.

I downloaded the bundle from the guide page. As a side note, the README.txt file refers to a code.py file, but there's no code.py file in the zip file. I'm assuming that ble_eval_server.py needs to be renamed code.py on the CIRCUITPY drive.

CircuitPython 6.2.0 is running on the nRF52.

Thanks.

Mark

hufemj
 
Posts: 15
Joined: Fri Oct 12, 2018 1:43 pm

Re: Problems getting central UART to recognize peripheral UA

by mikeysklar on Mon May 03, 2021 2:51 pm

Mark,

Thank you for providing the additional details of your setup. You are correct about renaming the file to code.py. I guess that is something we can add to the guide bundle to be more explicit.

It sounds as though the code is executing properly in that you see the advertisement and connect.

Are you able to run the ble_eval_client.py script on the Pi side and run some of the commands suggested in the example screen shot:

34816C50-B540-42FD-B857-6BE729546A56.png
34816C50-B540-42FD-B857-6BE729546A56.png (27.15 KiB) Viewed 96 times

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

Re: Problems getting central UART to recognize peripheral UA

by hufemj on Mon May 03, 2021 5:02 pm

Hi Mike,

I didn't make it clear in my earlier post. The Pi sees the advertisement, but doesn't find a match for the service it's looking for, UARTService. I added a print statement to show the advertised services. Unfortunately, I don't know how to display the value for UARTService to visually compare against the list of services provided.

I can connect via Bluefruit Connect and I can run eval commands successfully on the iPhone app, so code.py is working fine.

Thanks.

Mark
Attachments
ble_eval_client.py
(932 Bytes) Not downloaded yet

hufemj
 
Posts: 15
Joined: Fri Oct 12, 2018 1:43 pm

Re: Problems getting central UART to recognize peripheral UA

by mikeysklar on Tue May 04, 2021 11:08 am

It surprises me that such a short sample of code can not be matching the UART service correctly. However, just to remove any obvious obstacles can you upgrade the nRF52 bootloader to the latest. We are up to 0.5.0.

https://github.com/adafruit/Adafruit_nR ... /tag/0.5.0
https://learn.adafruit.com/introducing- ... bootloader

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

Re: Problems getting central UART to recognize peripheral UA

by hufemj on Tue May 04, 2021 3:06 pm

No luck. First I tried installing adafruit-nrfutil via pip3, which seemed to work. Except, adafruit-nrfutil was not found via the command line. Then I installed it from source, but I'm getting an error. Here's the info:

mark@Mac-mini Downloads %
mark@Mac-mini Downloads % adafruit-nrfutil version
adafruit-nrfutil version 0.5.3.post13
mark@Mac-mini Downloads % ls -la feather*
-rw-rw-rw-@ 1 mark staff 435816 May 4 14:44 feather_nrf52840_express_bootloader-0.5.0.zip
mark@Mac-mini Downloads % ls /dev/cu*
/dev/cu.Bluetooth-Incoming-Port /dev/cu.debug-console /dev/cu.usbmodem113101 /dev/cu.wlan-debug
mark@Mac-mini Downloads % adafruit-nrfutil --verbose dfu serial --package feather_nrf52840_express_bootloader-0.5.0.zip -p /dev/cu.usbmodem113101 -b 115200 --singlebank --touch 1200
Traceback (most recent call last):
File "/Library/Frameworks/Python.framework/Versions/3.9/bin/adafruit-nrfutil", line 33, in <module>
sys.exit(load_entry_point('adafruit-nrfutil==0.5.3.post13', 'console_scripts', 'adafruit-nrfutil')())
File "/Users/mark/Library/Python/3.9/lib/python/site-packages/click/core.py", line 829, in __call__
return self.main(*args, **kwargs)
File "/Users/mark/Library/Python/3.9/lib/python/site-packages/click/core.py", line 782, in main
rv = self.invoke(ctx)
File "/Users/mark/Library/Python/3.9/lib/python/site-packages/click/core.py", line 1259, in invoke
return _process_result(sub_ctx.command.invoke(sub_ctx))
File "/Users/mark/Library/Python/3.9/lib/python/site-packages/click/core.py", line 1259, in invoke
return _process_result(sub_ctx.command.invoke(sub_ctx))
File "/Users/mark/Library/Python/3.9/lib/python/site-packages/click/core.py", line 1066, in invoke
return ctx.invoke(self.callback, **ctx.params)
File "/Users/mark/Library/Python/3.9/lib/python/site-packages/click/core.py", line 610, in invoke
return callback(*args, **kwargs)
File "/Users/mark/Library/Python/3.9/lib/python/site-packages/nordicsemi/__main__.py", line 288, in serial
dfu = Dfu(package, dfu_transport=serial_backend)
File "/Users/mark/Library/Python/3.9/lib/python/site-packages/nordicsemi/dfu/dfu.py", line 66, in __init__
self.manifest = Package.unpack_package(self.zip_file_path, self.unpacked_zip_path)
File "/Users/mark/Library/Python/3.9/lib/python/site-packages/nordicsemi/dfu/package.py", line 364, in unpack_package
with open(os.path.join(target_dir, Package.MANIFEST_FILENAME), 'r') as f:
FileNotFoundError: [Errno 2] No such file or directory: '/var/folders/v_/6xmlj8dc8xl0d5001s70sbb80000gr/T/nrf_dfu_2c_ovvvf/unpacked_zip/manifest.json'
mark@Mac-mini Downloads %

I'm running Python 3.9.4 on Mac OS 11.2.3.

Thanks.

Mark

hufemj
 
Posts: 15
Joined: Fri Oct 12, 2018 1:43 pm

Re: Problems getting central UART to recognize peripheral UA

by mikeysklar on Thu May 06, 2021 11:43 am

Hi Mark,

Thanks for trying the bootloader install. I think I see the issue. The confusion is caused by the way we package the bootloader. You have the right idea here using the adafruit-nrfutil and downloading the bootloader.zip. However, you need unzip that file and give adafruit-nrfutil the zip file within the zip. That is the actual bootloader instead of the entire bundle.

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

Re: Problems getting central UART to recognize peripheral UA

by hufemj on Thu May 06, 2021 2:29 pm

Okay. Good news/bad news.

The good news is that the bootloader command looks like it works. The bad news is that Mu no longer connects with the board and the USB shows as drive FTHR840BOOT. That is, it doesn't change to CIRCUITPYTHON. The command line dialog is below and a screenshot showing the drive is attached. At this point, I'm totally at a loss and don't know what to do. I'm sure it's something simple that I'm overlooking.

mark@Mac-mini feather_nrf52840_express_bootloader-0.5.0 % !123
adafruit-nrfutil --verbose dfu serial --package feather_nrf52840_express_bootloader-0.5.0_s140_6.1.1.zip -p /dev/cu.usbmodem13101 -b 115200 --singlebank --touch 1200
Upgrading target on /dev/cu.usbmodem13101 with DFU package /Users/mark/Downloads/feather_nrf52840_express_bootloader-0.5.0/feather_nrf52840_express_bootloader-0.5.0_s140_6.1.1.zip. Flow control is disabled, Single bank, Touch 1200
Touched serial port /dev/cu.usbmodem13101
Opened serial port /dev/cu.usbmodem13101
Starting DFU upgrade of type 3, SoftDevice size: 151016, bootloader size: 39000, application size: 0
Sending DFU start packet
Sending DFU init packet
Sending firmware file
########################################
########################################
########################################
########################################
########################################
########################################
########################################
########################################
########################################
############
Activating new firmware

DFU upgrade took 21.018418788909912s
Device programmed.
Attachments
USB drive.png
USB drive.png (70.53 KiB) Viewed 58 times

hufemj
 
Posts: 15
Joined: Fri Oct 12, 2018 1:43 pm

Re: Problems getting central UART to recognize peripheral UA

by mikeysklar on Fri May 07, 2021 9:55 am

Good job updating the firmware. That process looks correct. You should be able to verify the version on your Feather by looking at the INFO_UF2.TXT contents.

It looks like your device is still in "BOOTLOADER" mode so you will need to eject it let it power off and try plugging it back into your computer. If that does not work you are still getting a BOOT device being mounted then drop a new copy of CircuitPython 6.2 (UF2 file) on the drive to reinstall.

The Feather should show up as CIRCUITPY which is the only name that the Mu editor will recognize.

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

Re: Problems getting central UART to recognize peripheral UA

by hufemj on Fri May 07, 2021 11:38 am

Okay. Unmounting didn't work, but installing a new UF2 file did.

However, we're back to where we started from. ble_eval_client.py still does not find UARTService in adv.services and therefore does not attempt a connection:

if UARTService in adv.services:
uart_connection = ble.connect(adv)
print("Connected")
break

Any thoughts on how to proceed?

Mark

hufemj
 
Posts: 15
Joined: Fri Oct 12, 2018 1:43 pm

Re: Problems getting central UART to recognize peripheral UA

by mikeysklar on Sat May 08, 2021 9:18 am

Mark,

Glad the CircuitPython UF2 re-install was successful and now you have a fresh bootloader. The last part to check is to confirm that you are on our latest library drop. Are you using the the 20210507 library drop?

https://circuitpython.org/libraries

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

Re: Problems getting central UART to recognize peripheral UA

by hufemj on Sat May 08, 2021 1:50 pm

Mike,

Done. adafruit-circuitpython-bundle-6.x-mpy-20210507, from github.

ble_eval_client.py on the Pi still does not recogize UARTService among the services advertised.

Mark

hufemj
 
Posts: 15
Joined: Fri Oct 12, 2018 1:43 pm

Re: Problems getting central UART to recognize peripheral UA

by hufemj on Sat May 08, 2021 3:02 pm

Okay. First, I am not an OO expert. That's my excuse for the attached code. I put a bunch of debug print statements into ble_eval_client_mjh.py to see if I could find an identifier for UARTService to try and figure out why it wasn't identified within the services list. But, I wasn't able to do that. However, there's another example in the Adafruit documentation somewhere that used the mac address. So, modified the client code to check for the address and, voila, the devices connected and the application works.

My guess is that the problem with the UARTService comparison lies with the Raspberry Pi adafruit_ble library. There appeared to be a number of methods defined for comparison, e.g. gt, lt le, etc., and maybe there's a trailing byte that doesn't belong there that prevents two strings that look the same to not be equal. Just a thought.

Not sure how to update the CircuitPython libraries on the Raspberry Pi.

Thanks.

Mark
Attachments
ble_eval_client_mjh.py
(1.67 KiB) Downloaded 1 time

hufemj
 
Posts: 15
Joined: Fri Oct 12, 2018 1:43 pm

Re: Problems getting central UART to recognize peripheral UA

by mikeysklar on Sat May 08, 2021 8:02 pm

hufemj,

Good work going with a mac address versus finicky service identifier. Clever.

If you wanted to update the library on the Raspberry Pi side the syntax would look like:

Code: Select all | TOGGLE FULL SIZE
sudo pip3 install --upgrade adafruit_ble


Now if that does not resolve it you could use the Raspberry Pi to peek a little deeper to what is being advertised on your nRF52. This is an example of what I use on my Pi's to discover new BLE hardware services.

Code: Select all | TOGGLE FULL SIZE
pi@pidev:~ $ sudo bluetoothctl
Agent registered
[Logitech X50]# scan on
Discovery started
[CHG] Controller DC:A6:32:D2:9A:90 Discovering: yes
[NEW] Device CC:FD:D2:4F:82:1D Xtactor
[NEW] Device 70:81:53:04:20:4F 70-81-53-04-20-4F
[NEW] Device 4F:13:A6:7A:67:B6 4F-13-A6-7A-67-B6
[NEW] Device A0:38:F8:AD:39:D0 oura_A038F8AD39D0
[Logitech X50]# connect CC:FD:D2:4F:82:1D
Attempting to connect to CC:FD:D2:4F:82:1D
[CHG] Device CC:FD:D2:4F:82:1D Connected: yes
Connection successful

# scan off
Discovery stopped
[CHG] Controller DC:A6:32:D2:9A:90 Discovering: no
[CHG] Device D1:72:15:C7:30:93 RSSI is nil
[CHG] Device A0:38:F8:AD:39:D0 RSSI is nil
[CHG] Device 40:6C:1E:DB:DB:84 TxPower is nil
[CHG] Device 40:6C:1E:DB:DB:84 RSSI is nil
[CHG] Device 74:C1:D2:DD:04:D6 TxPower is nil
[CHG] Device 74:C1:D2:DD:04:D6 RSSI is nil
```

[Xtactor]# info
Device CC:FD:D2:4F:82:1D (random)
        Name: Xtactor
        Alias: Xtactor
        Appearance: 0x03c0
        Paired: no
        Trusted: no
        Blocked: no
        Connected: yes
        LegacyPairing: no
        UUID: Generic Access Profile    (00001800-0000-1000-8000-00805f9b34fb)
        UUID: Generic Attribute Profile (00001801-0000-1000-8000-00805f9b34fb)
        UUID: Device Information        (0000180a-0000-1000-8000-00805f9b34fb)
        UUID: Battery Service           (0000180f-0000-1000-8000-00805f9b34fb)
        UUID: Nordic Semiconductor ASA  (0000fe59-0000-1000-8000-00805f9b34fb)
        UUID: Vendor specific           (8ec9f001-f315-4f60-9fb8-838830daea50)
        UUID: Vendor specific           (8ec9f00a-f315-4f60-9fb8-838830daea50)
        UUID: Vendor specific           (8ec9f00b-f315-4f60-9fb8-838830daea50)
        UUID: Vendor specific           (8ec9f00d-f315-4f60-9fb8-838830daea50)
        RSSI: -61

[Xtactor:/service002b]# list-attributes
Primary Service
        /org/bluez/hci0/dev_CC_FD_D2_4F_82_1D/service0030
        0000fe59-0000-1000-8000-00805f9b34fb
        Nordic Semiconductor ASA
Characteristic
        /org/bluez/hci0/dev_CC_FD_D2_4F_82_1D/service0030/char0031
        8ec90003-f315-4f60-9fb8-838830daea50
        Vendor specific
Descriptor
        /org/bluez/hci0/dev_CC_FD_D2_4F_82_1D/service0030/char0031/desc0033
        00002902-0000-1000-8000-00805f9b34fb
        Client Characteristic Configuration
Primary Service
        /org/bluez/hci0/dev_CC_FD_D2_4F_82_1D/service002b
        0000180a-0000-1000-8000-00805f9b34fb
        Device Information
Characteristic
        /org/bluez/hci0/dev_CC_FD_D2_4F_82_1D/service002b/char002e
        00002a26-0000-1000-8000-00805f9b34fb
        Firmware Revision String
Characteristic
        /org/bluez/hci0/dev_CC_FD_D2_4F_82_1D/service002b/char002c
        00002a29-0000-1000-8000-00805f9b34fb
        Manufacturer Name String
Primary Service
        /org/bluez/hci0/dev_CC_FD_D2_4F_82_1D/service0022
        8ec9f001-f315-4f60-9fb8-838830daea50
        Vendor specific
Characteristic
        /org/bluez/hci0/dev_CC_FD_D2_4F_82_1D/service0022/char0025
        8ec9eeee-f315-4f60-9fb8-838830daea50
        Vendor specific
Characteristic
        /org/bluez/hci0/dev_CC_FD_D2_4F_82_1D/service0022/char0023
        8ec9fddd-f315-4f60-9fb8-838830daea50
        Vendor specific
Primary Service
        /org/bluez/hci0/dev_CC_FD_D2_4F_82_1D/service001f
        8ec9f00b-f315-4f60-9fb8-838830daea50
        Vendor specific
Characteristic
        /org/bluez/hci0/dev_CC_FD_D2_4F_82_1D/service001f/char0020
        8ec9deef-f315-4f60-9fb8-838830daea50
        Vendor specific
Primary Service
        /org/bluez/hci0/dev_CC_FD_D2_4F_82_1D/service001b
        8ec9f00a-f315-4f60-9fb8-838830daea50
        Vendor specific
Characteristic
        /org/bluez/hci0/dev_CC_FD_D2_4F_82_1D/service001b/char001c
        8ec9beea-f315-4f60-9fb8-838830daea50
        Vendor specific
Descriptor
        /org/bluez/hci0/dev_CC_FD_D2_4F_82_1D/service001b/char001c/desc001e
        00002902-0000-1000-8000-00805f9b34fb
        Client Characteristic Configuration
Primary Service
        /org/bluez/hci0/dev_CC_FD_D2_4F_82_1D/service000e
        8ec9f00d-f315-4f60-9fb8-838830daea50
        Vendor specific
Characteristic
        /org/bluez/hci0/dev_CC_FD_D2_4F_82_1D/service000e/char0019
        8ec9beed-f315-4f60-9fb8-838830daea50
        Vendor specific
Characteristic
        /org/bluez/hci0/dev_CC_FD_D2_4F_82_1D/service000e/char0017
        8ec9feed-f315-4f60-9fb8-838830daea50
        Vendor specific
Characteristic
        /org/bluez/hci0/dev_CC_FD_D2_4F_82_1D/service000e/char0014
        8ec9beee-f315-4f60-9fb8-838830daea50
        Vendor specific
Descriptor
        /org/bluez/hci0/dev_CC_FD_D2_4F_82_1D/service000e/char0014/desc0016
        00002902-0000-1000-8000-00805f9b34fb
        Client Characteristic Configuration
Characteristic                                                                                                         
        /org/bluez/hci0/dev_CC_FD_D2_4F_82_1D/service000e/char0011
        8ec9beeb-f315-4f60-9fb8-838830daea50
        Vendor specific
Descriptor
        /org/bluez/hci0/dev_CC_FD_D2_4F_82_1D/service000e/char0011/desc0013
        00002902-0000-1000-8000-00805f9b34fb
        Client Characteristic Configuration
Characteristic
        /org/bluez/hci0/dev_CC_FD_D2_4F_82_1D/service000e/char000f
        8ec9beef-f315-4f60-9fb8-838830daea50
        Vendor specific
Primary Service
        /org/bluez/hci0/dev_CC_FD_D2_4F_82_1D/service000a
        00001801-0000-1000-8000-00805f9b34fb
        Generic Attribute Profile
Characteristic
        /org/bluez/hci0/dev_CC_FD_D2_4F_82_1D/service000a/char000b
        00002a05-0000-1000-8000-00805f9b34fb
        Service Changed
Descriptor
        /org/bluez/hci0/dev_CC_FD_D2_4F_82_1D/service000a/char000b/desc000d
        00002902-0000-1000-8000-00805f9b34fb
        Client Characteristic Configuration

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

Please be positive and constructive with your questions and comments.