Previous
Reuse machine configuration
You can install viam-agent
as part of your manufacturing process and provision machines with a pre-defined configuration as they come online.
When the end user sets the machine up, they provide network access and viam-agent
installs viam-server
and your latest software.
If you’re looking for a full tutorial, see Monitor Air Quality with a Fleet of Sensors.
To prepare a device, you will follow these steps:
viam-agent
with the preinstall
script on the SD card providing the defaults file.Once a customer receives your machine, they will plug the machine in and turn it on.
The next steps depend on the provisioning method:
viam-agent
starts Bluetooth Low Energy (BLE) and accepts connections.viam-agent
starts a WiFi hotspot.viam-agent
starts Bluetooth Low Energy (BLE) and accepts connections.The following instructions will preinstall viam-agent
into an image.
Only use the following method for offline pre-installs with images. For live systems, follow the instructions on a machine’s setup tab to install viam-server
with viam-agent
.
Create a fragment
If you do not yet have a fragment, follow the steps to Create a fragment and make a note of the fragment ID.
Create the defaults file
If you would like to use a captive web portal, skip this and the next step.
Create a defaults file called
You must at least specify a fragment_id
.
{
"network_configuration": {
"manufacturer": "<NAME>", # your company name
"model": "<NAME>", # the machine's model
"fragment_id": "<ID>", # the fragment id, required for mobile app
"hotspot_interface": "<INTERFACE>", # the interface to use for hotspot/provisioning/wifi management
"hotspot_prefix": "<PREFIX>", # machine creates a hotspot during setup with this prefix in the name
"disable_captive_portal_redirect": false, # set to true if using a mobile app
"hotspot_password": "<PASSWORD>", # password for the hotspot
"disable_bt_provisioning": false, # set to true to disable Bluetooth provisioning
"disable_wifi_provisioning": false, # set to true to disable WiFi hotspot provisioning
"bluetooth_trust_all": false, # set to true to accept all Bluetooth pairing requests (which is only needed for bluetooth tethering) without requiring an unlock command from a mobile app.
"turn_on_hotspot_if_wifi_has_no_internet": false, # set to true if networks without internet should not be accepted.
"offline_before_starting_hotspot_minutes": "3m30s",
"user_idle_minutes": "2m30s",
"retry_connection_timeout_minutes": "15m"
}
}
{
"network_configuration": {
"manufacturer": "Skywalker",
"model": "C-3PO",
"fragment_id": "2567c87d-7aef-41bc-b82c-d363f9874663",
"hotspot_interface": "wlan0",
"hotspot_prefix": "skywalker-setup",
"disable_captive_portal_redirect": false,
"hotspot_password": "skywalker123",
"disable_bt_provisioning": false,
"disable_wifi_provisioning": false,
"bluetooth_trust_all": false,
"turn_on_hotspot_if_wifi_has_no_internet": false,
"offline_before_starting_hotspot_minutes": "3m30s",
"user_idle_minutes": "2m30s",
"retry_connection_timeout_minutes": "15m"
}
}
This file configures some basic metadata, specifies a fragment to use to configure the machine, and provides the WiFi hotspot network name and password to use on startup.
It also configures timeouts to control how long viam-agent
waits for a valid local WiFi network to come online before creating its hotspot network, and how long to keep the hotspot active before terminating it.
Configure Networks
If a machine connects to a network during setup and you know in advance which WiFi a machine will connect to, this step allows you to add credentials for it.
If you do not know the network in advance, skip this step. In this case the end user will have to provide network details later in the process.
If you know in advance that the machine should be able to connect to multiple networks, we recommend that you add WiFi settings in the operating system (for example, directly in NetworkManager).
If that is not possible, you can add networks with the additional_networks
field.
viam-agent
will then try to connect to each specified network in order of priority
from highest to lowest.
The following configuration defines the connection information and credentials for two WiFi networks named fallbackNetOne
and fallbackNetTwo
:
{
"network_configuration": {
"manufacturer": "Skywalker",
"model": "C-3PO",
"fragment_id": "2567c87d-7aef-41bc-b82c-d363f9874663",
"hotspot_interface": "wlan0",
"hotspot_prefix": "skywalker-setup",
"disable_captive_portal_redirect": false,
"hotspot_password": "skywalker123",
"disable_bt_provisioning": false,
"disable_wifi_provisioning": false,
"turn_on_hotspot_if_wifi_has_no_internet": false,
"offline_before_starting_hotspot_minutes": "3m30s",
"user_idle_minutes": "2m30s",
"retry_connection_timeout_minutes": "15m",
"turn_on_hotspot_if_wifi_has_no_internet": true
},
"additional_networks": {
"testNet1": {
"priority": 30,
"psk": "myFirstPassword",
"ssid": "fallbackNetOne",
"type": "wifi"
},
"testNet2": {
"priority": 10,
"psk": "mySecondPassword",
"ssid": "fallbackNetTwo",
"type": "wifi"
}
}
}
Name | Type | Description |
---|---|---|
type | string | The type of the network. Options: "wifi" |
ssid | string | The network’s SSID. |
psk | string | The network password/pre-shared key. |
priority | int | Priority to choose the network with. Values between -999 and 999. Default: 0 . |
Create a machine in advance
If you are using a mobile app for provisioning, skip this step.
If you provision devices using a captive web portal, you can create a machine in advance. You can either provide its machine cloud credentials to the preinstall script you will run in the next steps, or prvide them using the captive web portal.
You can get the machine cloud credentials by clicking the copy icon next to Machine cloud credentials in the part status dropdown to the right of your machine’s name on the top of the page.
Paste the machine cloud credentials into a file on your hard drive called
Flash an operating system to the SD card of the single-board computer
If you are flashing a Raspberry Pi using the Raspberry Pi Imager, flash a 64-bit image to your SD card and customize at least the hostname when prompted by the Raspberry Pi Imager.
When you customize the hostname or other settings, the Raspberry Pi Imager creates firstrun.sh
which is required to set up provisioning.
Provisioning is supported and tested on Ubuntu 22.04, Debian 11 (Bullseye), and 12 (Bookworm) but should work on most distros using NetworkManager v1.30 (or newer) as well.
For Bullseye, the installation of viam-agent
changes the network configuration to use NetworkManager.
Mount the SD card
Still using the computer used for flashing the SD card, eject and reinsert the card to make sure it’s mounted with the newly written operating system.
Download the preinstall script
Run the following commands to download the preinstall script and make the script executable:
wget https://storage.googleapis.com/packages.viam.com/apps/viam-agent/preinstall.sh
chmod 755 preinstall.sh
Please note this script works only under POSIX (macOS and Linux) at the moment.
Run the preinstall script
Run the preinstall script. It will attempt to auto-detect a mounted root filesystem (or for Raspberry Pi, bootfs) and also automatically determine the architecture.
sudo ./preinstall.sh
Follow the instructions.
If you created a
Troubleshooting:
Set up more devices
Unless you provided a machine cloud credentials file (
You can create your own custom mobile provisioning app using the Flutter SDK or the TypeScript SDK. Alternatively you can use the Viam mobile app.
If you are building your own app to provide provisioning functionality you have three options for provisioning. You can support any number of these options.
Provisioning method | Description | Package |
---|---|---|
Bluetooth with WiFi | Ask the user to connect to the machine over Bluetooth. The user then provides network credentials for an internet-connected WiFi network, through which machine setup can then occur. Recommended, if available. | Example |
WiFi | Ask the user to connect to the machine’s temporary WiFi hotspot. The user then provides network credentials for an internet-connected WiFi network, through which machine setup can then occur. Slower than Bluetooth with WiFi but faster than Bluetooth tethering. | Example |
Bluetooth tethering | Ask the user to connect to the machine over Bluetooth. The user shares their mobile device’s internet with the machine over Bluetooth. Slowest provisioning method. | Example |
The Viam mobile app allows end users to create a new machine in the app, and viam-agent
will then install viam-server
and run it with the configuration provided by the fragment_id
in the defaults file.
If you choose to use the Viam mobile app, you must provide a fragment for provisioning.
If you are not using Flutter or TypeScript and would like to use provisioning, please contact us.
If you want to change the WiFi network or the network credentials on a device that is already setup, you can enter provisioning again using the force provisioning mode.
If you can manually SSH
into a machine you can follow these steps:
Add the ViamShellDanger fragment.
The ViamShellDanger
fragment contains the latest version of the shell service, which you must add to your machine before you can use the viam machines part shell
command.
Open a shell on your machine:
viam machines part shell --part <PART-ID>
On the machine, create an empty file at
touch /opt/viam/etc/force_provisioning_mode
The machine will immediately enter provisioning mode until the machine receives the new credentials or the retry_connection_timeout_minutes
limit, by default 10 minutes, expires.
If you provide a provisioning app, instead program functionality that adds an empty file at
You cannot re-run the preinstall.sh
script.
Once a device is set up for provisioning and has a
Once a machine has completed the provisioning flow, you cannot re-run the final setup steps without first manually removing the machine cloud credentials file (
Some systems can’t scan for WiFi networks while in hotspot mode, meaning they won’t automatically detect networks coming online or into range until the retry_connection_timeout_minutes
expires.
The retry_connection_timeout_minutes
causes your device to exit hotspot mode, at which point your device will be able to detect newly available networks.
If your device does not connect to your network, adjust the retry_connection_timeout_minutes
value in the defaults file.
Check if other devices on the network can connect to the internet without problems. If other devices are fine, try restarting your device and check for other logs.
If you need to test the GRPC components of the provisioning service, there is a CLI client available.
Get the code from the agent
repo and run go run ./cmd/provisioning-client/
for info.
Was this page helpful?
Glad to hear it! If you have any other feedback please let us know:
We're sorry about that. To help us improve, please tell us what we can do better:
Thank you!