qaul / qaul.net

Internet Independent Wireless Mesh Communication App
https://qaul.net
GNU Affero General Public License v3.0
515 stars 62 forks source link

BLE Module for Linux with BlueR #314

Open MathJud opened 2 years ago

MathJud commented 2 years ago

Create a BLE (Bluetooth Low Energy) module in rust which compatible to the two existing modules for Android & iOS.

Existing android BLE module: https://github.com/qaul/qaul.net/tree/main/qaul_ui/android/blemodule

It shall do the following things:

The module is independent and will communicate via protobuf to the controlling backend library libqaul.

BlueR is the official Bluetooth low energy repository for for rust. https://github.com/bluez/bluer

Prototypes with partial functionality already exist.

6d7a commented 1 year ago

I'd be interested to have a shot at this issue. To give me little headstart, could you point out at what point the BLE module is started from the flutter app? And regarding the existing prototypes, what branches should I have a look at? Thanks.

MathJud commented 1 year ago

@6d7a great!

I'm here for questions and discussions!

There are a few points about compatibility:

1) The communication via the protobuf sys messages between libqaul and the blemodules. This is the common API for all system dependent modules.

The module can be found here: rust/libqaul/src/connections/ble

The protobuf communication between libqaul and the blemodule is defined in this protobuf file: rust/libqaul/src/connections/ble/ble.proto.

This protobuf file creates the following rust source code: rust/libqaul/src/connections/ble/qaul.sys.ble.rs

The communication principle is relatively simple, libqaul sends a 'request' message and the module responds with the correlating 'response'.

The program flow is the following:

a) At program startup the blemodule is loaded and libqaul sends a BleInfoRequest

2) The already existing modules for Android and iOS that are being integrated at the moment.

We have a custom writable GATT service to send direct messages to a device:

General

At the moment we are fixing some last issues of the Android module on the branch ble-startup-fixing

We will document the exact behaviour of it for that it can be used as a reference.

The BLE communcation shall be enhanced over the next months. It has been implemented this way for the biggest compatibility (compatible with bluetooth 4 devices). There are more specific BLE-modes in Bluetooth 5 that can increase range and bandwith and have the possibility to broadcast bigger amount of data to all devices nearby.

To have a linux version for developing and testing would be very helpful.

I hope this was helpful and gave you a first overview. Don't hesitate to contact me with any questions.

6d7a commented 1 year ago

@MathJud, great! Thanks for the explanation. I'll give it a go and push some WIP PRs along the way. I still haven't wrapped my head around the RPC call chain, so just to recap (using Android):

  1. The android app is started (The app at qaul.net/qaul_ui/android/app, right? Is qaul.net/android/app used?)
  2. The android app loads libqaul and blemodule AARs
  3. The app sets up message channels between the UI and libqaul here
  4. And this is where I'm stuck right now, because I see that there are JNI methods to set up channels for sys communication between the blemodule and libqaul here, but I don't see that they are called anywhere. I'm assuming that the UI component acts as a proxy in the communication between libqaul and the blemodule.

Thanks again for the help

MathJud commented 1 year ago

@Kevin

Thanks again for this helpful PR!

The interconnection between libqaul's BLE connectivity-module and the Android BLE module is done in the branch ble-startup-fixing-rebased-06022023 and will be merged to main as soon as all remaining small problems are ironed out.

It is referenced to this PR #533

I rebased your branch on the ble-startup-fixing-rebased-06022023 branch and called it linux_ble pushed it to the qaul repo: https://github.com/qaul/qaul.net/tree/linux_ble

And created the following PR from it: #539


I change the following things:

TODO:

The BLE module should send it's messages to libqaul.

Please don't hesitate to interact on it!