Skip to content

Node parameters

Sometimes you may want to run multiple instances of the same node with different input parameters. For example, a camera node might point to /dev/video0 on your system while another one points to /dev/video1. Parameters allow you to run multiple instances of the same node with different input settings.

In a new folder, initialize a new node:

  1. Initialize the node:

    Terminal window
    peppy node init --toolchain uv hello_world_param
  2. Navigate into the directory:

    Terminal window
    cd hello_world_param

Then modify the peppy.json5 configuration to look like this:

peppy.json5
{
schema_version: 1,
manifest: {
name: "hello_world_param",
tag: "0.1.0",
language: "python",
},
process: {
add_cmd: [
"uv",
"sync"
],
start_cmd: [
"uv",
"run",
"hello_world_param"
]
},
parameters: {
name: "string",
},
interfaces: {
exposes: {
topics: [
{
name: "message_stream",
qos_profile: "sensor_data",
message_format: {
message: "string"
},
}
],
}
}
}

With the new parameter key.

Now let’s try to create a new snapshot of our node in the node stack:

Terminal window
peppy node add .

You’ll get an error similar to this one:

Error: Fingerprint verification failed: Node config fingerprint mismatch: expected 9a58e1936c52c83d47d31621108e32bb78d2197c2d1989f0001e945a754e29a8, got ca1b1d51711a782db3152a723c6cdc255191c2a1721c7a19088e878fc9879c39.
The config may have been modified after code generation. Run `node sync` to update the peppygen lib on your node.

This error occurs because any changes to peppy.json5 need to be synced with the generated interfaces first. This safeguard guarantees that peppy.json5 always stays in sync with the node’s actual behavior. To update the interfaces, run:

Terminal window
peppy node sync

This ensures that peppy node add . will succeed on the next run. Before doing that, let’s modify the source code first.

Now that we’ve synchronized our project, the new parameter can be used in the main file by modifying it like this:

src/hello_world_param/__main__.py
import asyncio
from peppygen import NodeBuilder, NodeRunner
from peppygen.parameters import Parameters
from peppygen.exposed_topics import message_stream
async def emit_hello_world_loop(node_runner: NodeRunner, name: str):
counter = 0
while True:
counter += 1
message = f"hello {name} count {counter}"
print(message, flush=True)
await message_stream.emit(node_runner, message)
await asyncio.sleep(3)
async def setup(params: Parameters, node_runner: NodeRunner) -> list[asyncio.Task]:
return [asyncio.create_task(emit_hello_world_loop(node_runner, params.name))]
def main():
NodeBuilder().run(setup)
if __name__ == "__main__":
main()

Next, add the node to the stack:

Terminal window
peppy node add .

To verify the node was added, inspect the stack:

Terminal window
peppy stack list