Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for native Bluetooth LE on RPi5 #1120

Closed
rgillan opened this issue Aug 20, 2024 · 7 comments · Fixed by #1242
Closed

Support for native Bluetooth LE on RPi5 #1120

rgillan opened this issue Aug 20, 2024 · 7 comments · Fixed by #1242
Labels
question Further information is requested

Comments

@rgillan
Copy link

rgillan commented Aug 20, 2024

Having some challenges in running the matter-node-shell with --ble on a RaspberryPi 5 and think it's down in the actual HCI code. Trying to commission an Eve Door&Window using the inbuilt BT radio on the cpu module. Running the shell in debug shows it starts the controller with BLE, but then there's an error in the NobleBLEClient reset and the discovery never happens:

dev-rpi5-84:/opt/matter.js# npm run shell -- --ble

> shell
> matter-run packages/matter-node-shell.js/src/app.ts --ble

2024-08-20 23:10:19.406 INFO   Node                 Storage location: .matter-shell-0 (Directory)
Started Node #0 (Type: controller) with BLE
matter-node> config ble-hci get
Current BLE HCI ID: 0
Done.
matter-node> config thread-credentials get
Current Thread network credentials: name="xxxxx", Operational-Dataset="********************************************************************************************************************************************************************************************************"
Done.
matter-node> config loglevel get
Current Loglevel for Console: debug
Done.
matter-node> commission pair --pairingCode 2023-092-0090 --ble
2024-08-20 23:11:08.134 INFO   Node                 matter.js shell controller started for node 0
2024-08-20 23:11:08.135 DEBUG  MatterServer         Adding CommissioningController using storage key "0".
2024-08-20 23:11:08.136 DEBUG  MatterServer         Mdns instances not yet created, delaying node preparation.
2024-08-20 23:11:08.139 DEBUG  UdpChannelNode       Socket created and bound remoteAddress: undefined:5353 localAddress: 0.0.0.0:5353
2024-08-20 23:11:08.145 DEBUG  UdpChannelNode       Socket created and bound remoteAddress: undefined:5353 localAddress: :::5353
2024-08-20 23:11:08.148 DEBUG  UdpChannelNode       Socket created and bound remoteAddress: undefined:5353 localAddress: 0.0.0.0:5353
2024-08-20 23:11:08.152 DEBUG  UdpChannelNode       Socket created and bound remoteAddress: undefined:5353 localAddress: :::5353
2024-08-20 23:11:08.154 DEBUG  UdpChannelNode       Socket created and bound remoteAddress: undefined:undefined localAddress: 0.0.0.0:51328
2024-08-20 23:11:08.155 DEBUG  UdpChannelNode       Socket created and bound remoteAddress: undefined:undefined localAddress: :::55709
2024-08-20 23:11:08.168 DEBUG  RootCertif~teManager Loaded root certificate with ID 0 from storage
2024-08-20 23:11:08.177 DEBUG  Fabric               FabricBuilder setOperationalCert: nodeId=3524444298714960797, fabricId=1, caseAuthenticatedTags=undefined
{"discovery":{"knownAddress":"undefined","identifierData":{"shortDiscriminator":8},"discoveryCapabilities":{"ble":true,"onIpNetwork":true}},"passcode":32917765,"commissioning":{"nodeId":"undefined","regulatoryLocation":1,"regulatoryCountryCode":"XX"}}
2024-08-20 23:11:08.205 DEBUG  NobleBleClient       Error resetting BLE device via noble (can be ignored, we just tried): EINVAL, Invalid argument
2024-08-20 23:11:08.205 INFO   MatterController     Commissioning device with identifier {"shortDiscriminator":8} and 2 scanners and knownAddress "undefined"
2024-08-20 23:11:08.206 INFO   ControllerDiscovery  Start Discovering devices using identifier {"shortDiscriminator":8} ...
2024-08-20 23:11:08.206 DEBUG  MdnsScanner          Registered waiter for query _S8._sub._matterc._udp.local with timeout 30 seconds
2024-08-20 23:11:08.207 DEBUG  NobleBleClient       noble state is not poweredOn ... delay scanning till poweredOn
2024-08-20 23:11:08.207 DEBUG  MdnsScanner          Set 2 query records for query _S8._sub._matterc._udp.local: [{"name":"_matterc._udp.local","recordClass":1,"recordType":12},{"name":"_S8._sub._matterc._udp.local","recordClass":1,"recordType":12}]
2024-08-20 23:11:08.208 DEBUG  BleScanner           Registered waiter for query SD:8 with timeout 30 seconds
2024-08-20 23:11:08.212 DEBUG  MdnsScanner          Sending 2 query records for 1 queries with 0 known answers. Re-Announce in 1.5 seconds
2024-08-20 23:11:08.214 DEBUG  UdpChannelNode       Socket created and bound remoteAddress: undefined:5353 localAddress: 0.0.0.0:5353
2024-08-20 23:11:08.215 DEBUG  UdpChannelNode       Socket created and bound remoteAddress: undefined:5353 localAddress: :::5353
2024-08-20 23:11:08.215 DEBUG  UdpChannelNode       Socket created and bound remoteAddress: undefined:5353 localAddress: :::5353
2024-08-20 23:11:08.216 DEBUG  UdpChannelNode       Initialize multicast address: 192.168.42.84:5353 interface: eth0 type: udp4
2024-08-20 23:11:08.216 DEBUG  UdpChannelNode       Initialize multicast address: ::%eth0:5353 interface: eth0 type: udp6
2024-08-20 23:11:08.217 DEBUG  UdpChannelNode       Initialize multicast address: ::%wpan0:5353 interface: wpan0 type: udp6
2024-08-20 23:11:09.713 DEBUG  MdnsScanner          Sending 2 query records for 1 queries with 0 known answers. Re-Announce in 3 seconds
2024-08-20 23:11:12.713 DEBUG  MdnsScanner          Sending 2 query records for 1 queries with 0 known answers. Re-Announce in 6 seconds
2024-08-20 23:11:18.714 DEBUG  MdnsScanner          Sending 2 query records for 1 queries with 0 known answers. Re-Announce in 12 seconds
2024-08-20 23:11:30.715 DEBUG  MdnsScanner          Sending 2 query records for 1 queries with 0 known answers. Re-Announce in 24 seconds
2024-08-20 23:11:38.207 DEBUG  MdnsScanner          Finishing waiter for query _S8._sub._matterc._udp.local, resolving: true
2024-08-20 23:11:38.208 DEBUG  MdnsScanner          Removing last query _S8._sub._matterc._udp.local and stopping announce timer
2024-08-20 23:11:38.208 INFO   ControllerDiscovery  Found 0 devices using identifier {"shortDiscriminator":8}
2024-08-20 23:11:38.209 DEBUG  BleScanner           Finishing waiter for query SD:8, resolving: true
2024-08-20 23:11:38.209 DEBUG  NobleBleClient       Stop BLE scanning for Matter Services ...

The OS bluetooth checks all pass ok:

dev-rpi5-84:/opt/matter.js#  hcitool dev
Devices:
	hci0	2C:CF:67:10:14:80
dev-rpi5-84:/opt/matter.js# dmesg | grep -i bluetooth
[    7.223441] Bluetooth: Core ver 2.22
[    7.223489] NET: Registered PF_BLUETOOTH protocol family
[    7.223492] Bluetooth: HCI device and connection manager initialized
[    7.223498] Bluetooth: HCI socket layer initialized
[    7.223502] Bluetooth: L2CAP socket layer initialized
[    7.223511] Bluetooth: SCO socket layer initialized
[    7.281261] Bluetooth: HCI UART driver ver 2.3
[    7.281274] Bluetooth: HCI UART protocol H4 registered
[    7.281277] Bluetooth: HCI UART protocol BCSP registered
[    7.281333] Bluetooth: HCI UART protocol LL registered
[    7.281337] Bluetooth: HCI UART protocol ATH3K registered
[    7.281353] Bluetooth: HCI UART protocol Three-wire (H5) registered
[    7.281471] Bluetooth: HCI UART protocol Intel registered
[    7.281540] Bluetooth: HCI UART protocol Broadcom registered
[    7.281556] Bluetooth: HCI UART protocol QCA registered
[    7.281558] Bluetooth: HCI UART protocol AG6XX registered
[    7.281567] Bluetooth: HCI UART protocol Marvell registered
[    7.639738] Bluetooth: hci0: BCM: chip id 107
[    7.639980] Bluetooth: hci0: BCM: features 0x2f
[    7.641100] Bluetooth: hci0: BCM4345C0
[    7.641112] Bluetooth: hci0: BCM4345C0 (003.001.025) build 0000
[    7.642641] Bluetooth: hci0: BCM4345C0 'brcm/BCM4345C0.raspberrypi,5-model-b.hcd' Patch
[    8.343332] Bluetooth: hci0: BCM: features 0x2f
[    8.344690] Bluetooth: hci0: BCM43455 37.4MHz Raspberry Pi 3+-0190
[    8.344694] Bluetooth: hci0: BCM4345C0 (003.001.025) build 0382
[    8.344994] Bluetooth: hci0: BCM: Using default device address (43:45:c0:00:1f:ac)
[   16.441935] Bluetooth: BNEP (Ethernet Emulation) ver 1.3
[   16.441945] Bluetooth: BNEP filters: protocol multicast
[   16.441953] Bluetooth: BNEP socket layer initialized
[   16.444194] Bluetooth: MGMT ver 1.22
dev-rpi5-84:/opt/matter.js# bluetoothctl
Waiting to connect to bluetoothd...[bluetooth]# hci0 new_settings: powered bondable ssp br/edr le secure-conn 
[bluetooth]# Agent registered
[bluetooth]# [CHG] Controller 2C:CF:67:10:14:80 Pairable: yes
[bluetooth]# power on
[bluetooth]# Changing power on succeeded
[bluetooth]# scan on
[bluetooth]# SetDiscoveryFilter success
[bluetooth]# hci0 type 7 discovering on
[bluetooth]# Discovery started
[bluetooth]# [CHG] Controller 2C:CF:67:10:14:80 Discovering: yes
[bluetooth]# [NEW] Device 68:D3:7F:11:3F:EE 68-D3-7F-11-3F-EE
[bluetooth]# [NEW] Device 44:B1:87:B9:3C:94 44-B1-87-B9-3C-94
[bluetooth]# [NEW] Device 1A:57:2C:37:E1:BC 1A-57-2C-37-E1-BC
[bluetooth]# [NEW] Device 5F:E6:6B:72:21:DE 5F-E6-6B-72-21-DE
[bluetooth]# [NEW] Device D5:52:6A:56:3A:05 EveDoor5083E
[bluetooth]# [NEW] Device 6C:4A:85:4B:9B:59 6C-4A-85-4B-9B-59
[bluetooth]# [NEW] Device 17:D3:AA:30:5B:FC 17-D3-AA-30-5B-FC
[bluetooth]# [NEW] Device 69:CE:35:48:20:37 69-CE-35-48-20-37
[bluetooth]# [NEW] Device 6D:DB:A3:41:1D:1B 6D-DB-A3-41-1D-1B
[bluetooth]# [NEW] Device 5F:B3:D2:3F:AE:90 5F-B3-D2-3F-AE-90
[bluetooth]# scan off
[bluetooth]# hci0 type 7 discovering off
[bluetooth]# Discovery stopped

Happy to help debug/fix if someone can help point me where we should be looking.

@rgillan
Copy link
Author

rgillan commented Aug 21, 2024

could be something to do with:
abandonware/noble#341

@Apollon77
Copy link
Collaborator

Apollon77 commented Aug 21, 2024

First question: which user calls it? Root? If not are capabilities set correctly for nodejs executable? See readme ... or https://github.com/stoprocent/noble?tab=readme-ov-file#running-without-rootsudo-linux-specific because in fact the hci cannot be connected. Let's start with the basics ;-)

@Apollon77 Apollon77 added the question Further information is requested label Aug 21, 2024
@rgillan
Copy link
Author

rgillan commented Aug 21, 2024

@Apollon77 it looks like a noble/node-bluetooth-hci-socket issue. We have tried both as root and non-root; and it appears that the issue is either nodejs20 or Ubuntu 24.04 related (not here sorry). We have written a simple test unit with just the noble/hci socket issue and it never gets the poweredOn event. Other than tracking you can probably close it here.

@stoprocent
Copy link

Hi guys I have created an update on @stoprocent/noble to address this now:

@stoprocent
Copy link

@Apollon77 any results?

@Apollon77
Copy link
Collaborator

Planned for tomorrow

@Apollon77
Copy link
Collaborator

verified .. works for me

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants