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 Bluetooth on all platforms #33

Draft
wants to merge 21 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
dc4459c
Added the possibility of building the project on Mac devices and conn…
RamonBeast May 5, 2024
ab4abf5
Added initial support for BT on Mac
RamonBeast May 7, 2024
54d4fec
Migrating the framework to Bleak
RamonBeast May 7, 2024
a0f83f9
Small refactoring of webserver and show-spectrum to make them work wi…
RamonBeast May 8, 2024
34930a4
Updated bleak version and fixed a mistake in bluetooth.py
RamonBeast May 8, 2024
4e01a8f
Readme update
RamonBeast May 8, 2024
f5dd43f
Expanded the README with a list of supported OS and instructions
RamonBeast May 9, 2024
d934d6a
Spelling corrections
RamonBeast May 9, 2024
4f866a5
Remove ununsed import
RamonBeast May 9, 2024
e7cfb4a
Fixed ruff errors
RamonBeast May 11, 2024
a541d48
Refactored the main library code to be used in both synchronous and a…
RamonBeast May 11, 2024
0a62fc0
Format fixes
RamonBeast May 11, 2024
def8bea
Merge remote-tracking branch 'upstream/master'
RamonBeast May 12, 2024
810082c
Cosmetics
RamonBeast May 12, 2024
e5fccc5
Fixed a wrong function that was calling itself rather than its async-…
RamonBeast May 12, 2024
4ecb619
Added simple error display to webserver app and added handling of exc…
RamonBeast May 12, 2024
8b2af55
Added an async version of the basic.py script to show how to use the …
RamonBeast May 12, 2024
6815f89
Reformatted with Ruff
RamonBeast May 12, 2024
4ed0e05
Fixed a library function that was calling the wrong async version of …
RamonBeast May 14, 2024
e5bdec5
Removed unused imports
RamonBeast May 14, 2024
be227ff
Defaulted tests to USB rathern than Bluetooth
RamonBeast May 14, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ __pycache__/
*.py[cod]
*.egg-info/
.mypy_cache/
.venv/
dist/
74 changes: 69 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

[Описание на русском языке](README_ru.md)

This is a library to work with the radiation detector and spectrometer [RadiaCode-101](https://scan-electronics.com/dosimeters/radiacode/radiacode-101).
This is a library to work with the radiation detector and spectrometer [RadiaCode](https://scan-electronics.com/dosimeters/radiacode/radiacode-101) (101, 102, 103).

***The project is still under development and not stable. Thus, the API might change in the future.***

Expand Down Expand Up @@ -33,10 +33,74 @@ $ python3 -m radiacode-examples.narodmon --bluetooth-mac 52:43:01:02:03:04
- install and run:
```
$ poetry install
$ poetry run python3 radiacode-examples/basic.py --bluetooth-mac 52:43:01:02:03:04 # or without --bluetooth-mac for USB connection

$ poetry run python radiacode-examples/find-radiacode.py # To find your Radiacode over Bluetooth and discover its MAC address or UUID

$ poetry run python radiacode-examples/basic.py --help # To see all options

$ poetry run python radiacode-examples/basic.py --bluetooth-mac 52:43:01:02:03:04 # or without --bluetooth-mac for USB connection

$ poetry run python radiacode-examples/basic.py --bluetooth-uuid 1EDA584E-652C-2011-1211-B213EFADEED0 # on Mac for bluetooth connection
```

### Examples
To install the dependencies required to run the examples: ```poetry install -E examples```

### Supported OS

| OS | Bluetooth | USB | Notes |
| :--- | :---: | :---: | :--- |
| Mac OS (Silicon/Intel) | :white_check_mark: | :white_check_mark: | BT only with UUID, Mac OS does not expose MAC addresses |
| Linux | :white_check_mark: | :white_check_mark: | USB requires ```libusb```|
| Windows | :white_check_mark: | :white_check_mark: | USB required ```libusb``` |
| Windows (WSL) | :x: | :question: | WSL does not provide direct access to hardware|

### Windows
Make sure ```libusb``` is installed:
- Download the [latest stable](https://github.com/libusb/libusb/releases) version
- Use [7-Zip](https://www.7-zip.org/download.html) to unpack it
- Pick the most recent ```libusb-1.0.dll``` file (for a *Windows 10/11 64-bit* installation, it should be in: ```libusb-1.x.xx\VS2022\MS64\dll```)
- Copy the ```.dll``` in your ```C:\Windows\System32``` folder
- Run scripts as usual

### Mac Silicon/Intel
Make sure ```libusb``` is installed on your system, if you use [Homebrew](https://brew.sh/) you can run:
- ```brew install libusb```

*Note:* Mac OS does not expose Bluetooth MAC addresses anymore. In order to connect to your device via Bluetooth you will need to supply either its ```serial number``` (or part of it) or its ```UUID```.

- **Serial number**: you can obtain it directly from the device, navigate to the **Info** menu, it should be in the form of: ```RC-10x-xxxxxx```
- **UUID**: the UUID depends on both devices and it will change if you try to connect to the *Radiacode* from another computer (in this case, you will just need to rediscover)

Discovering the UUID of your *Radiacode* is quite easy:
- Make sure the *Radiacode* is **disconnected** from other devices (such as your phone, so kill the *Radiacode app* and its background tasks)
- Run: ```poetry run python radiacode-examples/find-radiacode.py```

The script will return UUIDs for all available Radiacodes.

### Linux
Make sure ```libusb``` is installed on your system. For *Debian/Ubuntu/Raspberry PI*:
- ```sudo apt install libusb```

You might have to tweak your ```udev``` configuration. On ```Debian/Ubuntu/Raspberry PI```:
- ```sudo nano /etc/udev/rules.d/99-com.rules```

Then add anywhere the following lines:

```
# Radiacode
SUBSYSTEM=="usb", ATTRS{idVendor}=="0483", ATTRS{idProduct}=="f123", MODE="0666"
```

## MacOS
The library used to communicate over Bluetooh (```bluepy```) is [not supported](https://github.com/IanHarvey/bluepy/issues/44) on MacOS. Only the USB connection is available on Apple devices. A ```USB Serial Number```, obtainable from the ```Device Info``` menu on the device itself, can be specified if more than one Radiacode is connected via USB at the same time.
Simply unplug and replug the Radiacode and run the scripts as per usual.

#### Bluetooth
To enable Bluetooth on a *Raspberry Pi*:
- ```sudo apt install bluetooth pi-bluetooth bluez blueman```

On *Debian/Ubuntu* you should have all necessary packages by default, otherwise just try:
- ```sudo apt install bluetooth bluez```

## UUID and MAC Address
On `Windows` and `Linux` both `UUID` and `MAC addresses` can be used interchangeably, the library is flexible enough that it will try to establish a connection even if you supply a `UUID` where a `MAC address` is expected (e.g.: if you provide a `MAC address` while specifying `--bluetooth-uuid`). You will receive a warning anyway.

Make sure ```libusb``` is installed on your system, if you use ```Brew``` you can run: ```brew install libusb```
Loading
Loading