viam-micro-server Development Setup
viam-micro-server
is the lightweight version of viam-server
which can run on resource-limited embedded systems (ESP32) that cannot run the fully-featured viam-server
.
This page provides instructions for you to customize viam-micro-server
and create modules.
Looking to install viam-micro-server?
If you only want to install and use viam-micro-server
, see Install viam-micro-server
instead.
Follow these steps to install and build viam-micro-server
on your ESP32 for development:
- Install the required software
- Set up your development environment with Viam’s Canon CLI utility (recommended) or manually
- Install
viam-micro-server
Software requirements
viam-micro-server
is written in Rust.
To be able to develop viam-micro-server
on macOS and Linux systems, you must install the following software on your development machine:
Install dependencies:
sudo apt-get install git libssl-dev dfu-util libusb-1.0-0 libudev-dev
If you haven’t already, install Homebrew:
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
Then, install
dfu-util
:brew install dfu-util
Install
Rust
andcargo
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
Once completed open a new tab on your terminal or run
. "$HOME/.cargo/env"
.See the Rust Installation guide for more information and other installation methods.
Install
cargo-generate
withcargo
Run the following command to install
cargo-generate
:cargo install cargo-generate
Install
espflash
Run the following command to install
espflash
:cargo install espflash
Set up your development environment
Canon is a CLI utility for managing a Docker-based canonical environment.
- Install Docker Engine. Canon requires a working installation of Docker Engine.
- If you are running Docker Engine on Linux, make sure that you go through the post installation steps to run Docker automatically on startup.
Run
go version
to confirm your system has Go 1.19 or later installed.Install canon:
go install github.com/viamrobotics/canon@latest
Add the go binary folder to your
PATH
by running:export PATH=$PATH:$(go env GOPATH)/bin
Install canon:
brew install viamrobotics/brews/canon
To set up the Docker development environment for ESP32 manually, complete the following instructions:
Tip
You only need to follow these steps if you are not using Canon to build viam-micro-server
.
If you have completed your set up with Canon, skip this section and continue to install viam-micro-server
.
- Install additional build dependencies:
sudo apt-get install git wget flex bison gperf python3 python3-pip python3-venv cmake ninja-build ccache libffi-dev libssl-dev dfu-util libusb-1.0-0
brew install cmake ninja dfu-util
Install and activate the ESP-IDF
Clone the ESP-IDF, the development framework for Espressif SoCs (System-on-Chips) supported on Windows, Linux and macOS:
mkdir -p ~/esp cd ~/esp git clone --depth 1 -b v4.4.8 --single-branch --recurse-submodules --shallow-submodules https://github.com/espressif/esp-idf
Then, install the required tools for ESP-IDF:
cd ~/esp/esp-idf ./install.sh esp32
To activate ESP-IDF, run the following command to source (
.
) the activation scriptexport.sh
:. $HOME/esp/esp-idf/export.sh
Tip
To avoid conflicts with other toolchains, adding this command to your .bashrc
or .zshrc
is not recommended.
Instead, save this command to run in any future terminal session where you need to activate the ESP-IDF development framework.
Install the following tools with
cargo
:cargo install espup cargo install cargo-espflash cargo install ldproxy
Download and install the ESP-RS toolchain:
espup install -s -f ~/esp/export-rs.sh -v 1.75.0
Activate the ESP Rust toolchain, run the following command to source (
.
) the activation scriptexport-rs.sh
:. $HOME/esp/export-rs.sh
Tip
To avoid conflicts with other toolchains, adding this command to your .bashrc or .zshrc is not recommended. Instead, save this command to run in any future terminal session where you need to activate the ESP-IDF development framework.
Install viam-micro-server
Create a new machine
Navigate to the Viam app and add a new machine in your desired location.
Click on the name of the machine to go to the machine’s page.
Start Docker on your development machine. If you haven’t already, complete Docker’s Linux post installation steps to set up Docker to run whenever your system boots up.
Generate a new project from this template to create a new
viam-micro-server
project to upload to your ESP32 by running:cargo generate --git https://github.com/viamrobotics/micro-rdk.git
Select
templates/project
when prompted. Give the project a name of your choice. Selectesp32
for MCU. If you wish to configure anesp32-camera
or afake
camera as a component of your machine, select true for include camera module and traits.You will be prompted to paste your machine’s
viam-server
robot JSON configuration into the terminal, which is the same thing as its machine cloud credentials.To obtain this:
- Navigate to your new machine’s page on the Viam app and select the CONFIGURE tab.
- Select the part status dropdown to the right of your machine’s name on the top of the page:
- Click the copy icon underneath Machine cloud credentials.
viam-micro-server
needs this JSON, which contains your machine part secret key and cloud app address, to connect to the Viam app. - Paste the machine cloud credentials into your terminal when prompted.
Caution
Do not share your API key or machine address publicly. Sharing this information could compromise your system security by allowing unauthorized access to your machine, or to the computer running your machine.
Upload
viam-micro-server
to your ESP32Now, flash the project to your ESP32 and it will connect to the Viam app from which you can then remotely control it:
cd <your-path-to/your-project-directory> canon bash -lc "make build-esp32-bin" make flash-esp32-bin
Make sure you have run
. ~/dev/esp/export-rs.sh
and. ~/dev/esp/esp-idf/export.sh
before running the following command:make upload
When prompted, select the serial port that your ESP32 is connected to through a data cable.
If successful, you will retain a serial connection to the board until you press
Ctrl-C
. To manage this connection, consider running it within a dedicated terminal session, or undertmux
orscreen
. While the serial connection is live, you can also restart the currently flashed image withCtrl-R
.Navigate to your new machine’s page on the Viam app. If successful, Live should be displayed underneath Last online.
Troubleshooting
Error: Failed to open serial port
If you run into the error Failed to open serial port
when flashing your ESP32 with Linux, make sure the user is added to the group dialout
with sudo gpasswd -a $USER dialout
.
Error: espflash::timeout
If you get the following error while connecting to your ESP32:
`Error: espflash::timeout
× Error while connecting to device
╰─▶ Timeout while running command
Run the following command:
espflash flash --erase-parts nvs --partition-table partitions.csv target/xtensa-esp32-espidf/release/esp32-camera --baud 115200 && sleep 2 && espflash monitor
Try the connection command again. The baud rate on your device may not have been fast enough to connect. If successful, the Viam app will show that your machine part’s status is Live.
Error: viam.json
not found
If you get the error viam.json not found
try the following to manually add your machine cloud credentials as a file in your project:
- Navigate to your machine’s page on the Viam app and select the CONFIGURE tab.
- Select the part status dropdown to the right of your machine’s name on the top of the page:
- Click the copy icon underneath Machine cloud credentials.
viam-micro-server
needs this JSON, which contains your machine part secret key and cloud app address, to connect to the Viam app. - Navigate to the directory of the project you just created.
- Create a new
viam.json file and paste theviam-server
machine cloud credentials in. - Save the file.
Error: failed to run custom build command for esp32-explorer (/host)
This may occur for various reasons such as your machine cloud credentials, WiFi SSID, or password not being populated.
Check that your machine cloud credentials are provided in your project directory as
Error: invalid value 460800
for --before <BEFORE>
Change "-b"
to "-B
in the "-B"
is the Baudrate config.
Run the following commands to flash
espflash write-bin 0x0 target/esp32-server.bin -B 460800 && sleep 2 && espflash monitor
You can find additional assistance in the Troubleshooting section.
You can also ask questions in the Community Discord and we will be happy to help.
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!