Code to run a BLE-SOCKS bridge. See READMEs for socks-forwarder (rust proxy) and phone_proxy (flutter proxy) in their respective directories.
Also see documentation for the socks-forwarder module that interfaces with the socks-forwarder systemd service, and the flutter-ble library leveraged by phone_proxy.
- SBC running a Debian-based OS with an aarch64 architecture
- The SBC must have a bluetooth adapter that supports bluetooth version 5.0 or higher
- A config for a Viam machine must be stored in
/etc/viam.json. Specifically, theidfield is read by the SOCKS forwarder as the BLE characteristic that will be advertised and discoverable from nearby devices. - If developing on the
socks-forwarder, rust should also be installed.
- An iPhone or Android mobile device connected via USB to a separate computer
- A working mobile development setup
- A working flutter installation
- A working XCode installation if using an iPhone
- flutter doctor should show no iOS issues and flutter devices should show an iPhone connected over USB
- A working Android Studio installation if using an Android
- flutter doctor should show no Android issues and flutter devices should show an Android connected over USB
- Ensure your SBC has an internet connection While the system will eventually work without it; the initial provisioning of the device requires an internet connection for now
- Check bluetoothctl version on the SBC
- Run bluetoothctl version on the SBC; verify that it shows version 5.79 or greater
- If the command hangs or does not show any version, ensure any hciattach commands have been run for custom, external bluetooth adapters
- If the displayed version is < 5.79, run this script to install the latest version of bluez, bluetoothctl, and the bluetooth systemd service
- Run bluetoothctl version on the SBC; verify that it shows version 5.79 or greater
- Configure a Viam machine on app.viam.com. If developing on the
socks-forwarder, it will make sense to run theviam-serverseparately, but otherwise you can install theviam-agentto handle the management of theviam-server.- Add this fragment to your machine. On downloading and running the module, the
viam-serverwill install and start thesocks-forwardersystemd service. - Optional: Create an
/etc/advertised_ble_name.txtfile on the SBC with a name for the BLE device (on the first line) if desired. This is the name that will appear in pairing requests and mobile device bluetooth discovery menus. The name defaults to “Viam SOCKS forwarder” if none is specified in/etc/advertised_ble_name.txt.
- Add this fragment to your machine. On downloading and running the module, the
- Ensure
socks-forwarderis running.- If developing on the
socks-forwarder, make sure the systemd service is not running.sudo systemctl stop socks-forwarderorsudo systemctl disable socks-forwarder- Start the
socks-forwarderby runningcargo runin thesocks-forwarderdirectory
- Otherwise, run
sudo systemctl status socks-forwarder- The service should be “enabled” and “active”; those states mean that the service is running and will start up whenever the SBC starts up, respectively
- You should see the log
In healthy and idle state. Waiting for proxy device name to be writtenas the most recent log from the service.
- If developing on the
- Run this sample flutter app on a nearby mobile device (example of flutter logic to later be run in a user mobile app) from your separate computer
- Ensure mobile device is connected via USB to your computer and visible through flutter devices
- Run flutter doctor and look for iOS or Android issues if device is not visible
- Clone the repository if you have not already
git clone [email protected]:viam-labs/ble-managed.git
- Modify machineToManage in phone_proxy/lib/main.dart to be the part ID of the Viam machine (available under “Connect” -> “Connection Details” on app.viam.com)
- From the customer’s app, this part ID could be found via a QR Code or some other physical marking on the pre-provisioned device
- Enter the phone_proxy directory
cd phone_proxy
- Run the sample flutter app
- flutter run
- Accept pairing request from the SBC when prompted (name of device should be the same as what’s in
/etc/advertised_ble_name.txton the SBC) - You should see a “'BLE-SOCKS bridge established and ready to handle traffic” message in flutter/xcode logs (iPhone) or flutter/gradle logs (Android)
- The same log is output from the socks-forwarder systemd service if you would like to confirm establishment from the other side
- Ensure mobile device is connected via USB to your computer and visible through flutter devices