|
| 1 | +--- |
| 2 | +title: "Bluetooth provisioning with viam-agent" |
| 3 | +linkTitle: "Bluetooth provisioning" |
| 4 | +weight: 70 |
| 5 | +type: "docs" |
| 6 | +description: "Learn how to use Bluetooth Low Energy (BLE) for machine provisioning as an alternative to WiFi hotspot provisioning." |
| 7 | +tags: ["fleet management", "viam-server", "viam-agent", "bluetooth", "provisioning"] |
| 8 | +images: ["/installation/thumbnails/install.png"] |
| 9 | +imageAlt: "Bluetooth provisioning" |
| 10 | +languages: [] |
| 11 | +viamresources: [] |
| 12 | +platformarea: ["fleet"] |
| 13 | +level: "Advanced" |
| 14 | +date: "2025-06-02" |
| 15 | +prev: "/manage/fleet/provision/end-user-setup/" |
| 16 | +# updated: "" # When the tutorial was last entirely checked |
| 17 | +# SMEs: James, Ale |
| 18 | +cost: "0" |
| 19 | +--- |
| 20 | + |
| 21 | +Bluetooth provisioning enables machine setup using Bluetooth Low Energy (BLE) as an alternative to WiFi hotspot provisioning. This method is particularly useful in environments with many WiFi networks, where hotspot provisioning may be less reliable, or when you want to avoid creating an open WiFi hotspot. |
| 22 | + |
| 23 | +## Overview |
| 24 | + |
| 25 | +When Bluetooth provisioning is enabled, `viam-agent` advertises a BLE service that mobile applications can connect to directly. This allows users to provision machines without needing to join a WiFi hotspot, providing a more streamlined setup experience on mobile devices. |
| 26 | + |
| 27 | +### Key Features |
| 28 | + |
| 29 | +- **Direct BLE connection**: Mobile apps connect directly to the machine via Bluetooth |
| 30 | +- **Encrypted communication**: All credential exchanges use RSA OAEP encryption |
| 31 | +- **Parallel operation**: Can work alongside WiFi hotspot provisioning |
| 32 | +- **Mobile-optimized**: Designed for optimal mobile app user experience |
| 33 | +- **Automatic adapter selection**: Automatically selects the first available Bluetooth adapter |
| 34 | + |
| 35 | +## How Bluetooth Provisioning Works |
| 36 | + |
| 37 | +1. **Service Advertisement**: When provisioning mode starts, `viam-agent` advertises a BLE service with a name beginning with `viam-setup-` |
| 38 | +1. **Mobile App Discovery**: Compatible mobile apps scan for and connect to the advertised BLE service |
| 39 | +1. **Secure Handshake**: The machine generates an RSA key pair and shares the public key with the mobile app |
| 40 | +1. **Credential Exchange**: The mobile app encrypts and sends WiFi credentials and/or machine credentials |
| 41 | +1. **Network Connection**: The machine attempts to connect using the provided credentials |
| 42 | +1. **Service Installation**: Once connected, `viam-agent` installs and starts `viam-server` |
| 43 | + |
| 44 | +## Configuration |
| 45 | + |
| 46 | +### Basic Configuration |
| 47 | + |
| 48 | +To enable Bluetooth provisioning, ensure `disable_bt_provisioning` is set to `false` (the default) in your `viam-defaults.json`: |
| 49 | + |
| 50 | +```json {class="line-numbers linkable-line-numbers"} |
| 51 | +{ |
| 52 | + "network_configuration": { |
| 53 | + "disable_bt_provisioning": false, |
| 54 | + "disable_wifi_provisioning": false |
| 55 | + } |
| 56 | +} |
| 57 | +``` |
| 58 | + |
| 59 | +### Advanced Configuration |
| 60 | + |
| 61 | +For machines with multiple Bluetooth adapters, specify which adapter to use: |
| 62 | + |
| 63 | +```json {class="line-numbers linkable-line-numbers"} |
| 64 | +{ |
| 65 | + "network_configuration": { |
| 66 | + "disable_bt_provisioning": false, |
| 67 | + "bluetooth_adapter_name": "hci0" |
| 68 | + } |
| 69 | +} |
| 70 | +``` |
| 71 | + |
| 72 | +### Bluetooth-Only Provisioning |
| 73 | + |
| 74 | +To use only Bluetooth provisioning and disable WiFi hotspot provisioning: |
| 75 | + |
| 76 | +```json {class="line-numbers linkable-line-numbers"} |
| 77 | +{ |
| 78 | + "network_configuration": { |
| 79 | + "disable_bt_provisioning": false, |
| 80 | + "disable_wifi_provisioning": true, |
| 81 | + "fragment_id": "your-fragment-id" |
| 82 | + } |
| 83 | +} |
| 84 | +``` |
| 85 | + |
| 86 | +{{< alert title="Note" color="note" >}} |
| 87 | +When using Bluetooth-only provisioning, you must provide a `fragment_id` for mobile app configuration. |
| 88 | +{{< /alert >}} |
| 89 | + |
| 90 | +## Security |
| 91 | + |
| 92 | +Bluetooth provisioning implements several security measures: |
| 93 | + |
| 94 | +### Encryption |
| 95 | + |
| 96 | +- **RSA OAEP Encryption**: All credential data is encrypted using RSA OAEP with SHA-256 |
| 97 | +- **2048-bit Keys**: Uses 2048-bit RSA keys for strong encryption |
| 98 | +- **Per-Session Keys**: New key pairs are generated for each provisioning session |
| 99 | +- **Public Key Exchange**: Public keys are shared using x509 PKIX encoding |
| 100 | + |
| 101 | +### Communication Protocol |
| 102 | + |
| 103 | +The BLE service uses predefined UUIDs for different characteristics: |
| 104 | + |
| 105 | +- **Service UUID**: Generated from namespace `74a942f4-0f45-43f4-88ca-f87021ae36ea` |
| 106 | +- **Write Characteristics**: For receiving encrypted credentials (SSID, PSK, machine credentials) |
| 107 | +- **Read Characteristics**: For sharing status, network lists, and public keys |
| 108 | +- **Encrypted Payloads**: All sensitive data is encrypted before transmission |
| 109 | + |
| 110 | +## Bluetooth Service Characteristics |
| 111 | + |
| 112 | +The Bluetooth service exposes several characteristics for different functions: |
| 113 | + |
| 114 | +### Write-Only Characteristics |
| 115 | + |
| 116 | +- **SSID**: Receives encrypted WiFi network name |
| 117 | +- **PSK**: Receives encrypted WiFi password |
| 118 | +- **Robot Part ID**: Receives encrypted machine part identifier |
| 119 | +- **Robot Part Secret**: Receives encrypted machine secret |
| 120 | +- **App Address**: Receives encrypted cloud app address |
| 121 | + |
| 122 | +### Read-Only Characteristics |
| 123 | + |
| 124 | +- **Status**: Provides machine configuration and connection status |
| 125 | +- **Networks**: Lists available WiFi networks with signal strength and security info |
| 126 | +- **Public Key**: Shares the RSA public key for encryption |
| 127 | +- **Errors**: Reports any provisioning errors |
| 128 | + |
| 129 | +## Mobile App Integration |
| 130 | + |
| 131 | +### Supported Platforms |
| 132 | + |
| 133 | +Bluetooth provisioning is designed for mobile applications using: |
| 134 | + |
| 135 | +- **Flutter SDK**: Full BLE provisioning support |
| 136 | +- **TypeScript SDK**: BLE provisioning capabilities |
| 137 | +- **Viam Mobile App**: Native Bluetooth provisioning support |
| 138 | + |
| 139 | +### App Development Considerations |
| 140 | + |
| 141 | +When developing mobile apps with Bluetooth provisioning: |
| 142 | + |
| 143 | +1. **BLE Permissions**: Ensure your app requests appropriate Bluetooth permissions |
| 144 | +1. **Service Discovery**: Scan for services with the `viam-setup-` prefix |
| 145 | +1. **Encryption Handling**: Implement RSA OAEP encryption for credential transmission |
| 146 | +1. **Error Handling**: Monitor the errors characteristic for provisioning feedback |
| 147 | +1. **Status Monitoring**: Check the status characteristic to track provisioning progress |
| 148 | + |
| 149 | +## Troubleshooting |
| 150 | + |
| 151 | +### Bluetooth Adapter Issues |
| 152 | + |
| 153 | +**Problem**: Bluetooth provisioning not starting |
| 154 | + |
| 155 | +**Solutions**: |
| 156 | +1. Check if Bluetooth is available: |
| 157 | + ```sh {class="command-line" data-prompt="$"} |
| 158 | + bluetoothctl list |
| 159 | + ``` |
| 160 | + |
| 161 | +1. Verify Bluetooth service status: |
| 162 | + ```sh {class="command-line" data-prompt="$"} |
| 163 | + sudo systemctl status bluetooth |
| 164 | + ``` |
| 165 | + |
| 166 | +1. For multiple adapters, specify the correct one: |
| 167 | + ```json |
| 168 | + { |
| 169 | + "network_configuration": { |
| 170 | + "bluetooth_adapter_name": "hci0" |
| 171 | + } |
| 172 | + } |
| 173 | + ``` |
| 174 | + |
| 175 | +### Mobile Device Connection Issues |
| 176 | + |
| 177 | +**Problem**: Mobile app cannot discover the machine |
| 178 | + |
| 179 | +**Solutions**: |
| 180 | +1. Ensure Bluetooth is enabled on the mobile device |
| 181 | +1. Check that the mobile app has Bluetooth permissions |
| 182 | +1. Verify the device supports Bluetooth Low Energy (BLE) |
| 183 | +1. Try restarting Bluetooth on the mobile device |
| 184 | + |
| 185 | +### Encryption Errors |
| 186 | + |
| 187 | +**Problem**: Credential transmission fails |
| 188 | + |
| 189 | +**Solutions**: |
| 190 | +1. Check `viam-agent` logs for encryption errors: |
| 191 | + ```sh {class="command-line" data-prompt="$"} |
| 192 | + sudo journalctl -u viam-agent -f |
| 193 | + ``` |
| 194 | + |
| 195 | +1. Ensure the mobile app is using the correct public key |
| 196 | +1. Verify RSA OAEP implementation in the mobile app |
| 197 | + |
| 198 | +### Configuration Issues |
| 199 | + |
| 200 | +**Problem**: Bluetooth provisioning not enabled |
| 201 | + |
| 202 | +**Solutions**: |
| 203 | +1. Verify `disable_bt_provisioning` is set to `false` |
| 204 | +1. Check that `disable_network_configuration` is not set to `true` |
| 205 | +1. Ensure the system has a working Bluetooth adapter |
| 206 | + |
| 207 | +## Testing and Development |
| 208 | + |
| 209 | +### CLI Testing Tool |
| 210 | + |
| 211 | +The `viam-agent` repository includes a CLI tool for testing Bluetooth provisioning: |
| 212 | + |
| 213 | +```sh {class="command-line" data-prompt="$"} |
| 214 | +# Clone the agent repository |
| 215 | +git clone https://github.com/viamrobotics/agent.git |
| 216 | +cd agent |
| 217 | + |
| 218 | +# Scan for Bluetooth devices |
| 219 | +go run ./cmd/provisioning-client/ --scan |
| 220 | + |
| 221 | +# Test Bluetooth provisioning |
| 222 | +go run ./cmd/provisioning-client/ --bluetooth --status |
| 223 | + |
| 224 | +# Set WiFi credentials via Bluetooth |
| 225 | +go run ./cmd/provisioning-client/ --bluetooth --ssid="MyNetwork" --psk="MyPassword" |
| 226 | + |
| 227 | +# Set machine credentials via Bluetooth |
| 228 | +go run ./cmd/provisioning-client/ --bluetooth --partID="part-id" --secret="secret" --appaddr="https://app.viam.com:443" |
| 229 | +``` |
| 230 | + |
| 231 | +### Development Environment |
| 232 | + |
| 233 | +For development and testing: |
| 234 | + |
| 235 | +1. **Filter Devices**: Use the `--filter` option to find specific devices: |
| 236 | + ```sh {class="command-line" data-prompt="$"} |
| 237 | + go run ./cmd/provisioning-client/ --scan --filter="viam-setup" |
| 238 | + ``` |
| 239 | + |
| 240 | +1. **Monitor Status**: Check provisioning status: |
| 241 | + ```sh {class="command-line" data-prompt="$"} |
| 242 | + go run ./cmd/provisioning-client/ --bluetooth --status |
| 243 | + ``` |
| 244 | + |
| 245 | +1. **List Networks**: View available WiFi networks: |
| 246 | + ```sh {class="command-line" data-prompt="$"} |
| 247 | + go run ./cmd/provisioning-client/ --bluetooth --networks |
| 248 | + ``` |
| 249 | + |
| 250 | +## Best Practices |
| 251 | + |
| 252 | +### Configuration |
| 253 | + |
| 254 | +- **Enable Both Methods**: Keep both Bluetooth and WiFi provisioning enabled for maximum compatibility |
| 255 | +- **Fragment Configuration**: Always provide a `fragment_id` when using mobile apps |
| 256 | +- **Adapter Selection**: Specify `bluetooth_adapter_name` for machines with multiple Bluetooth adapters |
| 257 | + |
| 258 | +### Security |
| 259 | + |
| 260 | +- **Key Management**: RSA keys are automatically generated per session - no manual key management required |
| 261 | +- **Credential Handling**: All sensitive data is encrypted before transmission |
| 262 | +- **Network Security**: Consider the security of the WiFi networks being configured |
| 263 | + |
| 264 | +### User Experience |
| 265 | + |
| 266 | +- **Clear Instructions**: Provide clear setup instructions for end users |
| 267 | +- **Fallback Options**: Ensure WiFi hotspot provisioning is available as a fallback |
| 268 | +- **Error Reporting**: Monitor the errors characteristic for user feedback |
| 269 | + |
| 270 | +## Limitations |
| 271 | + |
| 272 | +- **BLE Requirement**: Both the machine and mobile device must support Bluetooth Low Energy |
| 273 | +- **Mobile Focus**: Optimized for mobile app workflows rather than web browsers |
| 274 | +- **Linux Support**: Currently supported on Linux systems with Bluetooth adapters |
| 275 | +- **Range Limitation**: Bluetooth has a shorter range than WiFi hotspots |
| 276 | + |
| 277 | +## Next Steps |
| 278 | + |
| 279 | +- [Set up machine provisioning](/manage/fleet/provision/setup/) |
| 280 | +- [Configure viam-agent](/manage/reference/viam-agent/) |
| 281 | +- [End-user setup guide](/manage/fleet/provision/end-user-setup/) |
| 282 | +- [Mobile app development with Flutter SDK](https://flutter.viam.dev/) |
0 commit comments