iot2tangle / Streams-ble-gateway

BLE Gateway to receive IoT data and send it to the Tangle
Apache License 2.0
3 stars 2 forks source link

Bluez and dbus dependency on Mac OS / Crossplatform Ideas #1

Open sascha1337 opened 3 years ago

sascha1337 commented 3 years ago

Here you are using blurz, inside dependencies, which has the dependency of dbus-1, not being included in Mac OS ( 10.14.6 )

....., output: Output { status: ExitStatus(ExitStatus(256)), stdout: "", stderr: "Package dbus-1 was not found in the pkg-config search path.\nPerhaps you should add the directory containing `dbus-1.pc\'\nto the PKG_CONFIG_PATH environment variable\nNo package \'dbus-1\' found\nPackage dbus-1 was not found in the pkg-config search path.\n.......

warning: build failed, waiting for other jobs to finish...
error: build failed

https://github.com/iot2tangle/Streams-ble-gateway/blob/4169b54adf320206ad5d1b974dffd553b5f55607/Cargo.lock#L217 https://github.com/iot2tangle/Streams-ble-gateway/blob/4169b54adf320206ad5d1b974dffd553b5f55607/Cargo.toml#L20

"Fix" of that issue was just running brew install dbus followed by brew services start dbus to avoid following error:

dbus[11416]: Dynamic session lookup supported but failed: launchd did not provide a socket path, verify that org.freedesktop.dbus-session.plist is loaded!
thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: D-Bus error

And even after that, there were further errors running the GW on mac - as i had predicted. Makes sense, because dbus and especially bluez for bluetooth connections is for Linux kernel BLE communication only. See here:

https://stackoverflow.com/a/63136987

❯ brew services start dbus
==> Successfully started `dbus` (label: org.freedesktop.dbus-session)
❯ cargo run --release --bin scan
    Finished release [optimized] target(s) in 0.47s
     Running `target/release/scan`
thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: D-Bus error: Failed to connect to socket /usr/local/var/run/dbus/system_bus_socket: No such file or directory (org.freedesktop.DBus.Error.FileNotFound)', bin/scan.rs:10:59

To scale and being able to run the Gateway crossplatform, we have multiple options.

Checking the crates for CoreBluetooth https://crates.io/keywords/CoreBluetooth gives us 3 options, with one being very active in development, worth a look at: https://crates.io/crates/btleplug

Quote:

btleplug is a Rust BLE library, support Windows 10, macOS, Linux, and possibly iOS. It is currently made up of parts of other abandoned projects with a goal of building a fully cross platform proof of concept.

Our goal is the bring in some of the outstanding PRs from other projects, expand the platform support, and possibly make the API surface more ergonomic for being a truly cross-platform library.

That btleplug library seems promising, having support for windows, android, mac os, linux, even iOS but has some limitations for each platforms especially async: image

Another options would by some python wrapper accessiong Mac OS BLE, parsing output of blueutil for mac os (https://github.com/toy/blueutil) or like noble library for node.js solved, connecting via XpcConnection to the native Mac OS bluetoothd daemon service.

https://github.com/noble/noble/blob/master/lib/mac/highsierra.js#L18

--- or creating platform specific repos / build configs ála make and ./configure.

Just giving some feedback and ideas to solve those issues, to be more flexible to more endusers. Maybe someone knows right away, which BLE functions are essential, and check that embedded image, if it would be an option trying to replace blurz with btleplug in some development branch.

sascha1337 commented 3 years ago

Looking at this repo, it is not usable as is, but i like the abstraction of a generic interface, so the high-level code does not need to care about the underlaying implementation. Thinking further, looking at the core lib for streams, we could also create some core library abstracted, to have one unified BLE lib working crossplatform.

https://github.com/iot2tangle/Streams-ble-gateway/blob/4169b54adf320206ad5d1b974dffd553b5f55607/Cargo.toml#L16