Astarte Rust SDK based data stream test.
- Astarte Device Rust SDK
A Base64 url-encoded uuid should be used, you can use astartectl to generate one:
astartectl utils device-id generate-randomYou can configure the application either by using a direct MQTT connection to an Astarte instance or by connecting it through gRPC to an Astarte Message Hub instance (already configured and connected to Astarte).
The application can be configured by either using environment variables or a config.toml file.
If you want to use environment variables to set up the application, you can set the following:
ASTARTE_CONNECTION: which type of connection to Astarte must be usedASTARTE_REALM: name of the astarte realmASTARTE_DEVICE_ID: astarte device idASTARTE_CREDENTIALS_SECRET: astarte device credential secretASTARTE_PAIRING_TOKEN: token used to register a device and obtain acredentials_secretASTARTE_PAIRING_URL: address of the astarte broker to connect the device to AstarteASTARTE_STORE_DIRECTORY: path to the directory where to store data (e.g., in case of Astarte properties)ASTARTE_IGNORE_SSL_ERRORS: boolean stating if SSL errors should be ignored (default: false)ASTARTE_MSGHUB_ENDPOINT: endpoint of the Astarte Message Hub instanceASTARTE_MSGHUB_NODE_ID: UUID of the Node to connect to the Astarte Message Hub
Instead, if you want to use a configuration file, you must specify its location by using the
ASTARTE_CONFIG_PATH environment variable. The config.toml file must contain the following
information:
[astarte]
connection = "mqtt" # or "grpc"
store_directory = "/var/lib/stream-rust-test/"
# MQTT connection to Astarte
[astarte.mqtt]
realm = "REALM_NAME_HERE"
device_id = "DEVICE_ID_HERE"
pairing_url = "PAIRING_URL_HERE"
credentials_secret = "CREDENTIALS_SECRET_HERE"
# pairing_token = "PAIRING_TOKEN_HERE"
astarte_ignore_ssl = false
# gRPC connection to the Astarte Message Hub
[astarte.grpc]
endpoint = "http://[::1]:50051"
# node_id = "ASTARTE_MSGHUB_NODE_ID_HERE"NOTE: only one of the [astarte.mqtt] or [astarte.grpc] sections should be specified in the file.
A detailed description of the fields is depicted below:
connection: a field indicating which type of connection to Astarte should be used.store_directory: the directory specifying where persistent data will be saved.realm: the name of the Astarte realm.device_id: the id of the device you want to connect to Astarte.pairing_url: the URL of the Astarte Pairing endpoint (e.g.,https://<api url>/pairing.)credentials_secretorpairing_token: the identifiers used to authenticate the device through Astarte. If both are present, the credential secret will be used.astarte_ignore_ssl: a flag stating if SSL errors should be ignored when connecting to Astarte.endpoint: the endpoint where the Astarte Message Hub instance is listening for new connections.node_id: UUID of the Node to connect to the Astarte Message Hub (optional).
Build the application using following commands:
cargo build --releaseThen run the application either by running the run.sh script inside the scripts folder or with
the CLI:
./target/release/stream-rust-test [OPTIONS]The full list of options can be shown with the command:
./target/release/stream-rust-test -hOr you can use the --help option (instead of -h) to have a more detailed explanation of the
available options.
The following options can be set:
--device: set the device ID;--function: choose the data generation function (one betweensin,noisesin,randomspikessin,saw,rect,sinc,random,xand a default one);--interval: set the sending interval;--scale: set the scale of the generated result;
You can also set the stream options by using the following environment variables:
MATH_FUNCTIONINTERFACE_NAMEINTERVAL_BTW_SAMPLESSCALE
First, ensure you have Docker installed on your machine, then:
- Clone the repository containing the Stream Rust Test code
- Navigate to the root directory of the repository
- Run the build script to create the Docker image:
./scripts/docker/build.sh
To run the container with your configuration file:
- Ensure you have defined your astarte configuration file
config.toml - Run the Docker container, mounting the configuration file:
docker run -v /path/to/your/config.toml:/etc/stream-rust-test/ stream-rust-test:latest
Replace /path/to/your/config.toml with the actual path to your configuration file.
You can configure the application with environment variables by exporting them (e.g. configuring
them in the
docker-compose.yaml)
or via the --env-file CLI options:
docker run --env-file /path/to/your/.env stream-rust-test:latestConsult the --help for a full list of environment variable names and options.
If you are running a local astarte instance, such the one in
Astarte in 5 minutes,
you can either modify the docker-compose.yaml by adding the stream-rust-test container to it or
you can run it by using the --network="host" parameter, which is required to make localhost
work.
docker run --network="host" [ENV VARS] [MOUNT config.toml] stream-rust-test:latest