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-random
You 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_secret
ASTARTE_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 = "/tmp/stream-rust-test/store/"
# 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_secret
orpairing_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).
Since the application can be configured with a CLI, when running the application you can specify the
type of connection (mqtt
or grpc
) and the path to the config.toml
file with the --astarte_connection
(-c
) and
--astarte_config_path
options, respectively.
Build the application using following commands:
cargo build --release
Then 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 -h
Or 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
,x
and 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_FUNCTION
INTERFACE_NAME
INTERVAL_BTW_SAMPLES
SCALE