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

Bluetooth detection: better way to identify BT interface #96

Closed
shawaj opened this issue Aug 6, 2021 · 12 comments
Closed

Bluetooth detection: better way to identify BT interface #96

shawaj opened this issue Aug 6, 2021 · 12 comments
Assignees

Comments

@shawaj
Copy link
Member

shawaj commented Aug 6, 2021

Similar to #88 but for BT instead of LTE

Currently, we identify "BT detected" by looking for the USB ID of the bluetooth module:

def set_diagnostics_bt_lte(diagnostics):
devices = {
'BT': '0a12',
'LTE': '2c7c'
}
for dev_type, dev_addr in devices.items():
resp = os.popen('grep 0a12 /sys/bus/usb/devices/*/idVendor').read()
if dev_addr in resp:
diagnostics[dev_type] = True
else:
diagnostics[dev_type] = False
return diagnostics

Whilst this works, it is a little bit cumbersome IMO, and doesn't allow checking for in-built bluetooth hardware (which we will have on future hardware - for example the light hotspots).

So ideally, we need a better way to identify the bluetooth interface. Perhaps by checking for a device with hcitool dev or hciconfig -a

@shawaj
Copy link
Member Author

shawaj commented Nov 19, 2021

@marvinmarnold @vpetersson need to get this resolved in order for diagnostics to work properly with RockPi

@marvinmarnold
Copy link
Contributor

Will keep an eye on this. Its in our next sprint (started today). @posterzh is about to start working on it.

@shawaj
Copy link
Member Author

shawaj commented Nov 19, 2021

Sweet 👌

@shawaj shawaj mentioned this issue Nov 20, 2021
@posterzh
Copy link
Contributor

posterzh commented Nov 21, 2021

There are 3 utilities for us to get BLE devices.

  • hcitool dev
  • hciconfig -a
  • bluetoothctl list
    image

To get list of bluetooth devices programatically, we can use dbus for that.

Bluetoothctl uses Bluez5. Bluez5 exposes interfaces in the DBus for each functionality it offers(https://stackoverflow.com/questions/41553982/dbus-monitor-to-watch-bluetooth-activity/41577555)

@vpetersson
Copy link
Contributor

vpetersson commented Nov 22, 2021

Well, there are more ways. Those are just CLI tools for interacting with a BLE device. You can find out if a BLE device is connected on kernel level instead (such as looking in /proc or /sys for instance).

While I don't love the current approach (grep 0a12 /sys/bus/usb/devices/*/idVendor) is way too hackish, I don't want to replace it with any other tool unless we can programmatically use it (with for instance exit codes) rather than trying to prase stings.

@posterzh
Copy link
Contributor

posterzh commented Nov 22, 2021

@vpetersson I implemented getting the BLE devices and LTE devices programatically using dbus.
https://github.com/NebraLtd/hm-diag/pull/242/files#diff-1bc7190be6e1a8de2f5a4d659238a140f25dfff6cffa3587bc2e317b6d430709R57-R114

This draft implementation would fix both of #96 and #88
Also I confirm that it's possible to use all the features of nmcli cli using dbus.

To interact BLE and LTE devices with other than dbus, I played with several commands and they needs the diagnostics container to set network_mode to host and NET_ADMIN capability.
https://www.balena.io/docs/learn/develop/multicontainer/
image

The following commands works well when network_mode is set to host and have NET_ADMIN capability, without dbus enabled.

  • hcitool dev : check the BLE device
  • hciconfig -a : check the BLE device
  • ifconfig wlan0 : check the LTE device

The following commands doesn't work without dbus enabled.

  • bluetoothctl list
  • nmcli

@shawaj
Copy link
Member Author

shawaj commented Nov 22, 2021

@posterzh wlan0 is WiFi not LTE. LTE I believe would be wwan0 and would identify as a modem in NetworkManager / ModemManager

With regards to the other bits, I think dbus probably makes the most sense here as it's how we interface with Bluetooth and WiFi in hm-config container. This would also allow us to solve #226 in diagnostics in the future as well.

Not sure what @vpetersson and @marvinmarnold think?

@vpetersson re your comment on /sys or /proc - just for reference, for that we would need to enable the balena labels for bind mounting those pseudo filesystems into the container

@posterzh
Copy link
Contributor

posterzh commented Nov 22, 2021

@shawaj In the today's standup meeting, @vpetersson confirmed that interacting in a programmatic way using dbus makes more sense.

@shawaj
Copy link
Member Author

shawaj commented Nov 22, 2021

Sounds good to me 👍

@shawaj
Copy link
Member Author

shawaj commented Nov 26, 2021

Closed by #242

@shawaj shawaj closed this as completed Nov 26, 2021
@shawaj shawaj reopened this Nov 26, 2021
@shawaj
Copy link
Member Author

shawaj commented Nov 26, 2021

Reopening until merged to production

@posterzh
Copy link
Contributor

@shawaj Make sense. I am writing a PR in helium-miner-software repository.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants