-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implementatation of the stream functionality #12
base: master
Are you sure you want to change the base?
Conversation
The interface allows generic sensors to stream samples data in double format. The interface is the same as the one defined in the stream-qt5-test astarte-platform repository Signed-off-by: Riccardo Gallo <[email protected]>
Introduce: - `color_eyre` to have a structured report handler - `tracing_subscriber` to collect scoped, structured and async-aware log data Signed-off-by: Riccardo Gallo <[email protected]>
Welcome to Codecov 🎉Once you merge this PR into your default branch, you're all set! Codecov will compare coverage reports and display results in all future pull requests. Thanks for integrating Codecov - We've got you covered ☂️ |
0ca718d
to
5830171
Compare
0fcd3ec
to
a6f84a6
Compare
a6f84a6
to
498dd70
Compare
d775c12
to
7c6b1b5
Compare
835921f
to
04d4e6a
Compare
04d4e6a
to
34ba2a2
Compare
use tracing::{debug, error, info}; | ||
|
||
/// Stream Rust test node identifier | ||
const STREAM_RUST_TEST_NODE_UUID: uuid::Uuid = uuid::uuid!("d72a6187-7cf1-44cc-87e8-e991936166dc"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't this be overridable? So you can test multiple connections to the message hub
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As a first implementation, we decided to embed the UUID, consequently having only once connection to the message hub. However, I think this can be changed (either in this PR or in a new one) if we want. What do you think @harlem88?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep, you can change it in a new PR.
src/math.rs
Outdated
} | ||
|
||
fn random_spikes_sin(value: f64) -> f64 { | ||
if value.sin() + rand::random::<f64>() / f64::MAX * 0.1 + rand::random::<f64>() / f64::MAX * 0.1 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pls explain
confused crab noises
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In rust the range for float [0,1)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep, the division by f64::MAX can be avoided
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Btw, if I understood correctly from the stream-qt5-test code, the random_spike_sin function is a spike (spike(x) = 1 if 0<=x<1, 0 otherwise) computed on the value of a noise sine (which is sin(x) + rand())
src/math.rs
Outdated
} | ||
|
||
fn noise_sin(value: f64) -> f64 { | ||
value.sin() + rand::random::<f64>() / f64::MAX * 0.2 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same as above
{ | ||
100.0 | ||
} else { | ||
0.0 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it's better to document this function since it's not clear from the name what it does.
From it, I would expect the sin(value) would be return, but I think the function actually returns spikes with PI frequency
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also I don't think the function is actually correct, looking at the original code:
} else if (m_function == QStringLiteral("randomspikessin")) {
value = sin(x) + (((double) qrand()) / ((double) RAND_MAX) * 0.1) + ((((double) qrand()) / ((double) RAND_MAX)) > 0.999 ? 100 : 0);
I would check the other functions like |
Yes, for this one I used the original definition of the normalized sinc function, which differs from the implementation in the stream-qt5-test |
This required also the introduction of some environment variables and structures to handle the generation of the samples to be sent to Astarte. For simplicity, the math functions are the same as the ones used in the stream-qt5-test repository. Signed-off-by: Riccardo Gallo <[email protected]>
Use clap to start the application, also taking into account possible environment variables set by the user. Signed-off-by: Riccardo Gallo <[email protected]>
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]>
Signed-off-by: Riccardo Gallo <[email protected]>
Provide the Atsarte configuration via environment variables or config.toml file, prioritizing env vars Signed-off-by: Riccardo Gallo <[email protected]>
Signed-off-by: Riccardo Gallo <[email protected]>
Signed-off-by: Riccardo Gallo <[email protected]>
Signed-off-by: Riccardo Gallo <[email protected]>
Give more flexibility to choose the mqtt or grpc Astarte connection configuration by using the CLI, environment variables and a config.toml file Signed-off-by: Riccardo Gallo <[email protected]>
Signed-off-by: Riccardo Gallo <[email protected]>
Signed-off-by: Riccardo Gallo <[email protected]>
Signed-off-by: Riccardo Gallo <[email protected]>
Signed-off-by: Riccardo Gallo <[email protected]>
34ba2a2
to
ba6c64d
Compare
This pull request introduces a Rust application that initiates an Astarte device, establishes an MQTT connection to a running Astarte instance, and sends data generated from a set of predefined mathematical functions.
Key Features:
config.toml
file, which contains the necessary information to connect the device to the Astarte instance.This work is inspired by and builds upon what has been done in the stream-qt5-test repository.
Closes #3