Skip to content

Commit

Permalink
refactor(config): update astarte device config
Browse files Browse the repository at this point in the history
Now the configuration information to connect a device to Astarte are
provided inside a `astarte-device-DEVICE_ID_HERE-conf` directory, in
a `config.toml` file. Instead, all the information necessary to generate
samples to be sent to Astarte are provided via CLI or environment
variables.
Also the README have been update to explain how to configure the
application and build/run it.

Signed-off-by: Riccardo Gallo <[email protected]>
  • Loading branch information
rgallor committed Sep 9, 2024
1 parent 316d90d commit 0fcd3ec
Show file tree
Hide file tree
Showing 7 changed files with 221 additions and 63 deletions.
4 changes: 4 additions & 0 deletions .reuse/dep5
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,7 @@ License: Apache-2.0
Files: interfaces/*
Copyright: 2024 SECO Mind Srl
License: Apache-2.0

Files: astarte-device-*-conf/*
Copyright: 2024 SECO Mind Srl
License: Apache-2.0
55 changes: 55 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,10 @@ description = "Astarte Rust SDK based data stream test."
astarte-device-sdk = "0.8.2"
clap = { version = "=4.4.18", features = ["derive", "env", "string"] }
color-eyre = "0.6.3"
toml = "0.8.12"
tokio = { version = "1.37.0", features = ["rt-multi-thread", "sync", "macros", "signal"] }
tokio-stream = "0.1.15"
tracing = "0.1.37"
tracing-subscriber = { version = "0.3.0", features = ["env-filter"]}
rand = "0.8.5"
serde = { version = "1.0.207", features = ["derive"] }
55 changes: 54 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,60 @@ Copyright 2024 SECO Mind Srl
SPDX-License-Identifier: Apache-2.0
-->

# stream-rust-test
# Astarte Stream Rust Test

[![ci](https://github.com/astarte-platform/stream-rust-test/actions/workflows/ci.yaml/badge.svg)](https://github.com/astarte-platform/stream-rust-test/actions/workflows/ci.yaml)
[![codecov](https://codecov.io/gh/astarte-platform/stream-rust-test/graph/badge.svg?token=wW2Hsm5edX)](https://codecov.io/gh/astarte-platform/stream-rust-test)

Astarte Rust SDK based data stream test.

Requirements
============

* Astarte Device Rust SDK

Getting started
===============

## Choosing a Device ID

A Base64 url-encoded uuid should be used, you can use [astartectl](https://github.com/astarte-platform/astartectl#installation) to generate one:

```bash
astartectl utils device-id generate-random
```

## Configuring the application

Create a configuration directory `astarte-device-DEVICE_ID_HERE-conf` with a `config.json` file inside it containing:
- `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. It should be something like `https://<api url>/pairing`.
- `credentials_secret` or `pairing_token`: the identifiers used to authenticate the device through Astarte. If both are
present, the credential secret will be used.
- `store_directory`: the directory specifying where persistent data will be saved.
- `interfaces_directory`: the directory where the astarte interfaces used by the device are saved.

## Build and run

Build the application using following commands:
```sh
cargo build --release
```

Then run the application either by running the `run.sh` script inside the `scripts` folder or with the CLI:
```sh
./target/release/stream-rust-test [OPTIONS]
```

The full list of options can be shown with the command:
```sh
cargo run -- -h
```

Several options are available:

- `--device` allows to set the device ID;
- `--function` allows to choose the data generation function (one between `sin`, `noisesin`, `randomspikessin`, `saw`, `rect`, `sinc`, `random`, `x` and a default one);
- `--interval` allows to set the sending interval;
- `--scale` allows to scale the generated result;
7 changes: 7 additions & 0 deletions astarte-device-DEVICE_ID_HERE-conf/config.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
realm = "REALM_HERE"
device_id = "DEVICE_ID_HERE"
pairing_url = "PAIRING_URL_HERE"
credentials_secret = "CREDENTIALS_SECRET_HERE"
astarte_ignore_ssl = false
interfaces_directory = "INTERFACES_DIRECTORY_HERE"
store_directory = "STORE_DIRECTORY_HERE"
7 changes: 0 additions & 7 deletions scripts/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,6 @@ set -eEuo pipefail
export RUST_LOG="debug"

# Set application environment variables
export REALM=""
export DEVICE_ID=""
export CREDENTIALS_SECRET=""
#export PAIRING_TOKEN=""
export PAIRING_URL="http://api.astarte.localhost/pairing"
export STORE_DIR="/tmp/stream-rust-test/store"
export IGNORE_SSL_ERRORS="true"
export MATH_FUNCTION="sin"
export INTERVAL_BTW_SAMPLES=500
export SCALE=3
Expand Down
Loading

0 comments on commit 0fcd3ec

Please sign in to comment.