Command line
This page lists the commands that come with the Sensora server. Use them to load demo data, stream test readings, connect an agent, and prepare firmware.
You run every command inside the app container, from the folder where you cloned the repository:
docker compose -f deploy/docker-compose.yml exec app bun run <command>The containers must be running. Options come after the command name. A -- in front of the options is allowed and not needed.
| Command | What it does | Changes data |
|---|---|---|
migrate | Applies database migrations | Only the database schema |
seed | Loads the demo project | Yes. Without --if-empty it deletes existing data |
simulate | Streams simulated readings | Adds simulated devices and readings |
mcp | Starts the MCP server over stdio for an agent | Depends on what the agent calls |
firmware | Installs Sensora Agent firmware, and makes signing keys and signatures for remote updates | Only files |
loadtest | Sends load to an instance like a fleet of devices | Adds devices and readings |
This page is about the commands inside the container. To install, update and roll back a released version on a host, there is a separate sensora command. See Operations.
migrate
Applies the SQL files in the migrations folder that were not applied yet, in the order of their file names. Each file runs once. The table schema_migrations records which files ran. Migrations only go forward.
docker compose -f deploy/docker-compose.yml exec app bun run migrateAlready up to date.You do not normally run this yourself. The stack runs it every time it starts, before the server comes up. It has no options.
seed
Loads the demo project "north-field": 261 devices in sites A to D, each with 7 days of readings every 10 minutes, two integrations, device templates and dashboards. That is about 750,000 readings and about 300 MB of database. On a server the command takes about half a minute.
With --if-empty, the command only loads the demo when the instance has no devices. On an instance that already has devices it does nothing. This is safe to run:
docker compose -f deploy/docker-compose.yml exec app bun run seed --if-emptyStarting the stack with --profile demo runs exactly this, so it loads the demo into a new instance and never touches an instance that is in use. See Quickstart.
seed without --if-empty deletes your data
The plain command bun run seed resets the instance to the demo. It first deletes all devices, readings, events, inbox entries, templates, integrations and dashboards, and it renames the project to north-field. Run it only on an instance whose data you do not need.
docker compose -f deploy/docker-compose.yml exec app bun run seedThe last line of the output says how many devices and readings were loaded.
Nothing sends data for the demo devices after the seed. They turn Offline when their offline window passes. simulate does not change that, because it uses its own devices.
simulate
Sends simulated readings on a timer, through the same path as real readings. Rules run on them, the dashboard updates live, and each reading is stored and labelled as simulated.
The command uses devices that are marked as simulated. If there are fewer than you ask for, it creates new ones named sim-01, sim-02 and so on. It does not send readings for your other devices, and it does not delete the devices it created.
docker compose -f deploy/docker-compose.yml exec app bun run simulate -- --devices 5 --interval 2 --duration 30The command prints one line for each round, with the number of devices and of readings stored. The run ends with a line that starts with simulate done and gives the totals.
| Option | Default | Meaning |
|---|---|---|
-n, --devices N | 3 | Number of simulated devices to use. Missing ones are created |
-i, --interval S | 5 | Seconds between rounds of readings |
-d, --duration S | 60 | Total run time in seconds. 0 runs until you press Ctrl+C |
-t, --template U | none | The id of a template to attach to new simulated devices. Their readings then follow the template's properties |
-h, --help | Shows the options |
Without a template, each device sends a temperature and a humidity value.
To send one simulated reading for a single device, open the device page, open the More actions menu and select Send a simulated reading.
mcp
Starts the MCP server sensora-mcp over stdio. An MCP client starts this command for you. You do not run it by hand, except to test.
docker compose -f deploy/docker-compose.yml exec -T app bun run mcpThe -T option is required. The server reads JSON-RPC messages on standard input and writes answers on standard output. When it is ready, it prints one line on the error stream that starts with sensora-mcp ready and gives the number of tools, 35.
It needs no API key, and it has no options. See Connect an agent.
firmware
Has five subcommands. install and status are about the Sensora Agent firmware that the browser flasher puts on boards. keygen, sign and pubkey are about signing your own firmware for remote updates.
Run bun run firmware without a subcommand to see the help text.
firmware status
Prints which Sensora Agent release is installed.
docker compose -f deploy/docker-compose.yml exec app bun run firmware status{
"available": false,
"version": null,
"signed": false,
"chips": [],
"device_url": null
}available is false when no release is installed. The browser flasher then has nothing to flash. device_url is the value of PUBLIC_URL.
firmware install
Installs a Sensora Agent release into the folder FIRMWARE_DIR, which is /app/firmware in the container. The command checks every image against the size and the SHA-256 hash in the manifest of the release, and it checks the signature of the manifest. The release becomes active only if all checks pass.
docker compose -f deploy/docker-compose.yml exec app bun run firmware install --release <tag>| Option | Meaning |
|---|---|
--release TAG | Downloads sensora-agent.tar.gz of that release tag from GitHub. The signature of the release must verify |
--repo owner/name | With --release: the GitHub repository to download from. The default is sensoraiot/sensora-library |
--from DIR | Installs a local build instead, from a dist/<version> folder of sensora-library. The folder must be visible inside the container |
--allow-unsigned | Accepts a release that has no signature that can be verified. Meant for builds that you made yourself |
Pass exactly one of --release and --from.
Two things to know in version 0.1.27:
- The signature check needs a key that you set. This version has no built-in public key for Sensora Agent releases.
install --releaseis refused with "no firmware public key is configured to verify it (set FIRMWARE_PUBLIC_KEY)" unlessFIRMWARE_PUBLIC_KEYholds the key that the release was signed with. - The install folder is inside the container. It is not on a volume. The release is gone when the container is created again, for example after you change
deploy/.envor update Sensora. Run the install command again.
Flash a board over USB has the full steps, also for a build that you made yourself. Do not use the SENSORA_AGENT_RELEASE build setting. It does not work in this version.
firmware keygen
Creates an ed25519 key pair for signing your own firmware images, and prints the public key. Devices and Sensora only accept an update that is signed with this key.
Run this on your own computer, not in the container. A key that you create inside the container is lost when the container is created again. You need Bun and a clone of the repository:
cd web/apps/api
bun install
bun run firmware keygenThe command prints where it wrote the private key, for example /home/you/.config/sensora/ota-signing.pem, and then the public key:
public key: <base64 text>Keep the private key file secret and back it up. Devices only accept images that are signed with it.
| Option | Default | Meaning |
|---|---|---|
--out FILE | ~/.config/sensora/ota-signing.pem | Where to write the private key |
The command refuses to write the key inside a git checkout, and it refuses to overwrite an existing file. Add the printed public key on the Updates page under Signing keys, or to OTA_PUBLIC_KEYS. Your firmware needs the same public key to check an update. See Firmware updates.
firmware sign
Writes a signature file for one firmware image. You upload the image and the signature together on the Updates page.
bun run firmware sign app.bin --version 1.2.0 --board ESP32signed app.bin (... bytes, sha256 ...) as 1.2.0 for ESP32 with /home/you/.config/sensora/ota-signing.pem
signature: /path/to/app.bin.sig| Option | Default | Meaning |
|---|---|---|
IMAGE | required | The application image, a .bin file. Not a merged image |
--version V | required | The version of this firmware. Letters, digits, ., + and -, up to 32 characters |
--board B | required | The chip the image was built for: ESP32, ESP32-S2, ESP32-C3, ESP32-S3, ESP32-C2, ESP32-C6, ESP32-H2 or ESP32-P4 |
--key FILE | ~/.config/sensora/ota-signing.pem | The private key from keygen |
--out FILE | IMAGE.sig | Where to write the signature |
The signature covers the board, the version, the size and the SHA-256 hash of the image. The command refuses an image that was built for a different chip than --board.
firmware pubkey
Prints the public key that belongs to a private key.
bun run firmware pubkey| Option | Default | Meaning |
|---|---|---|
--key FILE | ~/.config/sensora/ota-signing.pem | The private key |
See Firmware updates for the whole flow.
loadtest
Sends readings to a running instance from the outside, the way a fleet does. HTTP devices post to /ingest with their own id and secret. MQTT devices each hold their own connection to the broker. Use it to see how your hardware copes before you connect a large fleet.
loadtest leaves devices behind
The command creates real devices named loadtest-0001, loadtest-0002 and so on, and for MQTT an integration named loadtest-mqtt. It does not remove them. Run it on a test instance.
docker compose -f deploy/docker-compose.yml exec app bun run loadtest -- --url http://localhost:3001 --devices 50 --interval 10 --duration 120Inside the container, the address of the server is http://localhost:3001 and the bundled broker is mqtt://broker:1883. The run ends with one line of JSON: the number of readings sent, accepted and failed, and the response times.
| Option | Default | Meaning |
|---|---|---|
-u, --url URL | required | The base address of the instance |
-k, --key KEY | none | An API key with the scope Write, for creating the devices. Leave it out on an open instance. On a locked instance the command fails without it |
-m, --mqtt URL | none | The broker that MQTT devices publish to. Required for mqtt and both. The first run with MQTT waits 35 seconds before it sends |
-n, --devices N | 50 | Number of devices |
-i, --interval S | 10 | Seconds between two readings of one device |
-d, --duration S | 120 | Run time in seconds |
-t, --transport T | http | http, mqtt or both. both uses half of the devices for each |
-s, --state FILE | .loadtest-devices.json | The file where the ids and secrets of the HTTP devices are kept, so that a second run uses the same devices. In the container the file is lost when the container is created again |
-h, --help | Shows the options |
The readings of one device are spread over the interval, so the load is even and not one burst. Keep --interval at 1 second or more for each device. The server allows one request a second for each device after a burst of 60. See rate limits.
Other scripts
The file web/apps/api/package.json also defines start, dev, typecheck and test. They are for people who work on the Sensora source code. start is what the container already runs. typecheck and test need development files that are not in the image.
