This repository contains a small Viam module that exposes calibration files
stored on the robot filesystem. The service implements the Generic service API
and accepts two do_command calls:
| Command | Payload | Description |
|---|---|---|
list_passes |
{ "command": "list_passes" } |
Returns all pass folders and files. |
get_file |
{ "command": "get_file", "pass_id": "...", "filename": "..." } |
Returns one file (base64 encoded). |
get_base_dir |
{ "command": "get_base_dir" } |
Returns the absolute path the service watches. |
The repository also includes static assets (index.html, style.css,
main.ts) that you can bundle into a separate Viam application if you want a
hosted UI. They are not required for the module itself.
opencv-webapp/
├── opencv_webapp/
│ ├── __init__.py
│ └── webapp.py # Generic service implementation
├── example-config.json # Sample robot configuration snippet
├── index.html / style.css / main.ts # Optional frontend assets
├── meta.json # Module manifest (build + entrypoint)
├── requirements.txt # Python dependencies
├── run.sh # Entrypoint used by viam-server
└── Makefile # Helper targets for packaging
The module vendors its Python dependencies into a local lib/ directory during
build. The Makefile hides the details:
make build # installs deps into lib/ and creates module.tar.gz
make clean # removes lib/ and the tarballmeta.json references these targets so viam module reload --cloud-build
works out of the box.
-
Push this repository to a git host the Viam builder can access.
-
In the Viam console, add a Module → Local entry pointing to this repo.
-
Add a Generic service resource:
{ "name": "webapp", "type": "generic", "namespace": "viam", "model": "viam:opencv-webapp:webapp", "attributes": { "assets_dir": "./module-data/calibration-passes" } }Change
assets_dirif your passes live elsewhere. -
After deployment, the service responds to
do_commandfrom any Viam SDK client (including the optional frontend in this repo).
# Create some fake data
mkdir -p module-data/calibration-passes/test-pass
echo "example" > module-data/calibration-passes/test-pass/data.txt
touch module-data/calibration-passes/test-pass/.complete
# Invoke service locally
python3 -m venv .venv
source .venv/bin/activate
pip install -r requirements.txt
python - <<'PY'
from opencv_webapp.webapp import WebApp
import asyncio
async def main():
svc = WebApp("./module-data/calibration-passes")
print(await svc.do_command({"command": "list_passes"}))
asyncio.run(main())
PYindex.html, style.css, and main.ts can be bundled (for example with
esbuild or Vite) and hosted via Viam Applications.
The frontend now discovers credentials automatically:
- When deployed through Viam Applications, the runtime injects
window.__VIAM_WEB_APP__; the script reads the machine host, service name, and any referenced secrets from there. - For local development, edit the JSON block inside
index.html’s<script id="viam-web-app-config">…</script>tag. Replace the placeholder host/API key with your real values before building. - Ensure the
serviceNamematches the Generic service name configured on your machine (for examplewebapporcalibration-service).
Apache-2.0