Skip to content

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:

bash
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.

CommandWhat it doesChanges data
migrateApplies database migrationsOnly the database schema
seedLoads the demo projectYes. Without --if-empty it deletes existing data
simulateStreams simulated readingsAdds simulated devices and readings
mcpStarts the MCP server over stdio for an agentDepends on what the agent calls
firmwareInstalls Sensora Agent firmware, and makes signing keys and signatures for remote updatesOnly files
loadtestSends load to an instance like a fleet of devicesAdds 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.

bash
docker compose -f deploy/docker-compose.yml exec app bun run migrate
text
Already 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:

bash
docker compose -f deploy/docker-compose.yml exec app bun run seed --if-empty

Starting 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.

bash
docker compose -f deploy/docker-compose.yml exec app bun run seed

The 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.

bash
docker compose -f deploy/docker-compose.yml exec app bun run simulate -- --devices 5 --interval 2 --duration 30

The 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.

OptionDefaultMeaning
-n, --devices N3Number of simulated devices to use. Missing ones are created
-i, --interval S5Seconds between rounds of readings
-d, --duration S60Total run time in seconds. 0 runs until you press Ctrl+C
-t, --template UnoneThe id of a template to attach to new simulated devices. Their readings then follow the template's properties
-h, --helpShows 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.

bash
docker compose -f deploy/docker-compose.yml exec -T app bun run mcp

The -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.

bash
docker compose -f deploy/docker-compose.yml exec app bun run firmware status
json
{
  "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.

bash
docker compose -f deploy/docker-compose.yml exec app bun run firmware install --release <tag>
OptionMeaning
--release TAGDownloads sensora-agent.tar.gz of that release tag from GitHub. The signature of the release must verify
--repo owner/nameWith --release: the GitHub repository to download from. The default is sensoraiot/sensora-library
--from DIRInstalls a local build instead, from a dist/<version> folder of sensora-library. The folder must be visible inside the container
--allow-unsignedAccepts 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 --release is refused with "no firmware public key is configured to verify it (set FIRMWARE_PUBLIC_KEY)" unless FIRMWARE_PUBLIC_KEY holds 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/.env or 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:

bash
cd web/apps/api
bun install
bun run firmware keygen

The command prints where it wrote the private key, for example /home/you/.config/sensora/ota-signing.pem, and then the public key:

text
public key: <base64 text>

Keep the private key file secret and back it up. Devices only accept images that are signed with it.

OptionDefaultMeaning
--out FILE~/.config/sensora/ota-signing.pemWhere 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.

bash
bun run firmware sign app.bin --version 1.2.0 --board ESP32
text
signed app.bin (... bytes, sha256 ...) as 1.2.0 for ESP32 with /home/you/.config/sensora/ota-signing.pem
signature: /path/to/app.bin.sig
OptionDefaultMeaning
IMAGErequiredThe application image, a .bin file. Not a merged image
--version VrequiredThe version of this firmware. Letters, digits, ., + and -, up to 32 characters
--board BrequiredThe 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.pemThe private key from keygen
--out FILEIMAGE.sigWhere 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.

bash
bun run firmware pubkey
OptionDefaultMeaning
--key FILE~/.config/sensora/ota-signing.pemThe 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.

bash
docker compose -f deploy/docker-compose.yml exec app bun run loadtest -- --url http://localhost:3001 --devices 50 --interval 10 --duration 120

Inside 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.

OptionDefaultMeaning
-u, --url URLrequiredThe base address of the instance
-k, --key KEYnoneAn 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 URLnoneThe broker that MQTT devices publish to. Required for mqtt and both. The first run with MQTT waits 35 seconds before it sends
-n, --devices N50Number of devices
-i, --interval S10Seconds between two readings of one device
-d, --duration S120Run time in seconds
-t, --transport Thttphttp, mqtt or both. both uses half of the devices for each
-s, --state FILE.loadtest-devices.jsonThe 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, --helpShows 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.

Sensora is open source under the Apache 2.0 license.