Skip to content
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

Make property sample use MQTT #36

Merged
merged 5 commits into from
Jul 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .accepted_words.txt
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ ld
LD
microsoft
minimalistic
mosquitto
Mosquitto
mqtt
MQTT
opendigitaltwins
plugandplay
protobuf
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/notice-generation.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ jobs:
uses: Swatinem/rust-cache@v1
- name: Generate the Notice
run: |
git config --global user.email "[email protected]"
git config --global user.email "[email protected]"
git config --global user.name "Automated Notice Generation Pipeline"
./tools/notice_generation.sh
shell: bash
Expand Down
9 changes: 5 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,16 +33,17 @@ generic-json = "^0.7"
iref = "^2.0.3"
lazy_static = "1.4.0"
log = "^0.4"
paho-mqtt = "0.12"
parking_lot = "0.12.1"
prost = "0.11"
prost-types = "0.11"
regex = " 1.8.3"
regex = " 1.9.1"
serde = "1.0.160"
serde_derive = "1.0.163"
serde_json = "^1.0"
strum = "0.24"
strum_macros = "0.24"
tokio = "1.0"
strum = "0.25"
strum_macros = "0.25.1"
tokio = "1.29.1"
tonic = "0.9.2"
tonic-build = "0.9.2"
url = "2.3.1"
Expand Down
68 changes: 58 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,12 @@
- [DTDL Parser](#dtdl-parser)
- [Building](#building)
- [Running the Tests](#running-the-tests)
- [Running the Demo](#running-the-demo)
- [Running the Samples](#running-the-samples)
- [Property Sample](#property-sample)
- [Command Sample](#command-sample)
- [Mixed Sample](#mixed-sample)
- [Seat Massager Sample](#seat-massager-sample)
- [Using Chariott](#using-chariott)
- [Trademarks](#trademarks)

## <a name="introduction">Introduction</a>
Expand Down Expand Up @@ -57,6 +62,11 @@ You will need to install the Protobuf Compiler. This can be done by executing:

`sudo apt install -y protobuf-compiler`

### <a name="install-mqtt-broker">Install MQTT Broker</a>

If you plan to run any of the samples that use MQTT, then you will need to install a MQTT Broker, like [Mosquitto](https://github.com/eclipse/mosquitto).
Instructions for installing Mosquitto can be found [here](https://github.com/eclipse/mosquitto).

## <a name="cloning-the-repo">Cloning the Repo</a>

The repo has two submodules [opendigitaltwins-dtdl](https://github.com/Azure/opendigitaltwins-dtdl) and [iot-plugandplay-models](https://github.com/Azure/iot-plugandplay-models) that provide DTDL context files
Expand Down Expand Up @@ -93,34 +103,37 @@ After successfully building Ibeji, you can run all of the unit tests. To do this

Currently, we have no integration tests or end-to-end tests.

## <a name="running-the-demo">Running the Demo</a>
## <a name="running-the-samples">Running the Samples</a>

There are currently three demos: one that demonstrates the use of a property, one that demonstrates the use of a command and one that
demonstrates the mixed use of properties and commands.
There are currently four samples: one that demonstrates the use of a property, one that demonstrates the use of a command, one that
demonstrates the mixed use of properties and commands and one that demonstrates the use of get/set for a seat massager.

The demos use config files and we have provided a templated version of each config file. These templates can be found in:

- {repo-root-dir}/core/invehicle_digital_twin/template
- {repo-root-dir}/samples/common/template

The following instructions are for the demo for the use of a property.
Chariott may be used to discover the in-vehicle digital twin service. We will discuss how to enable this feature.

### <a name="property-sample">Property Sample</a>

The following instructions are for the demo for the use of a property. This sample uses a MQTT Broker; please make sure that it is running.
ashbeitz marked this conversation as resolved.
Show resolved Hide resolved

Steps:

1. The best way to run the demo is by using three windows: one running the In-Vehicle Digital Twin, one running the Provider and one running a Consumer.
1. The best way to run the demo is by using three windows: one running the In-Vehicle Digital Twin, one running the Digital Twin Provider and one running the Digital Twin Consumer.
Orientate the three windows so that they are lined up in a column. The top window can be used for the In-Vehicle Digital Twin.
The middle window can be used for the Provider. The bottom window can be used for a Consumer.<br>
1. In each window, change directory to the directory containing the build artifacts.
Make sure that you replace "{repo-root-dir}" with the repository root directory on the machine where you are running the demo.<br><br>
`cd {repo-root-dir}/target/debug`<br>
1. Create the three config files with the following contents, if they are not already there:<br><br>
---- consumer_settings.yaml ----<br>
`consumer_authority: "0.0.0.0:6010"`<br>
`invehicle_digital_twin_url: "http://0.0.0.0:5010"`<br><br>
---- invehicle_digital_twin_settings.yaml ----<br>
`invehicle_digital_twin_authority: "0.0.0.0:5010"`<br><br>
---- provider_settings.yaml ----<br>
`provider_authority: "0.0.0.0:4010"`<br>
`provider_authority: "0.0.0.0:1883"`<br>
`invehicle_digital_twin_url: "http://0.0.0.0:5010"`<br><br>
1. In the top window, run:<br><br>
`./in-vehicle-digital-twin`<br>
Expand All @@ -130,11 +143,13 @@ Make sure that you replace "{repo-root-dir}" with the repository root directory
`./property-consumer`<br>
1. Use control-c in each of the windows when you wish to stop the demo.

### <a name="command-sample">Command Sample</a>

The following instructions are for the demo for the use of a command.

Steps:

1. The best way to run the demo is by using three windows: one running the In-Vehicle Digital Twin, one running the Provider and one running a Consumer.
1. The best way to run the demo is by using three windows: one running the In-Vehicle Digital Twin, one running the Digital Twin Provider and one running the Digital Twin Consumer.
Orientate the three windows so that they are lined up in a column. The top window can be used for the In-Vehicle Digital Twin.
The middle window can be used for the Provider. The bottom window can be used for a Consumer.<br>
1. In each window, change directory to the directory containing the build artifacts.
Expand All @@ -157,11 +172,13 @@ Make sure that you replace "{repo-root-dir}" with the repository root directory
`./command-consumer`<br>
1. Use control-c in each of the windows when you wish to stop the demo.

### <a name="mixed-sample">Mixed Sample</a>

The following instructions are for the demo for the mixed use of commands and properties.

Steps:

1. The best way to run the demo is by using three windows: one running the In-Vehicle Digital Twin, one running the Provider and one running a Consumer.
1. The best way to run the demo is by using three windows: one running the In-Vehicle Digital Twin, one running the Digital Twin Provider and one running the Digital Twin Consumer.
Orientate the three windows so that they are lined up in a column. The top window can be used for the In-Vehicle Digital Twin.
The middle window can be used for the Provider. The bottom window can be used for a Consumer.<br>
1. In each window, change directory to the directory containing the build artifacts.
Expand All @@ -184,6 +201,37 @@ Make sure that you replace "{repo-root-dir}" with the repository root directory
`./mixed-consumer`<br>
1. Use control-c in each of the windows when you wish to stop the demo.

### <a name="seat-massager-sample">Seat Massager Sample</a>

The following instructions are for the demo for a seat massager.

Steps:

1. The best way to run the demo is by using three windows: one running the In-Vehicle Digital Twin, one running the Digital Twin Provider and one running the Digital Twin Consumer.
Orientate the three windows so that they are lined up in a column. The top window can be used for the In-Vehicle Digital Twin.
The middle window can be used for the Provider. The bottom window can be used for a Consumer.<br>
1. In each window, change directory to the directory containing the build artifacts.
Make sure that you replace "{repo-root-dir}" with the repository root directory on the machine where you are running the demo.<br><br>
`cd {repo-root-dir}/target/debug`<br>
1. Create the three config files with the following contents, if they are not already there:<br><br>
---- consumer_settings.yaml ----<br>
`consumer_authority: "0.0.0.0:6010"`<br>
`invehicle_digital_twin_url: "http://0.0.0.0:5010"`<br><br>
---- invehicle_digital_twin_settings.yaml ----<br>
`invehicle_digital_twin_authority: "0.0.0.0:5010"`<br><br>
---- provider_settings.yaml ----<br>
`provider_authority: "0.0.0.0:4010"`<br>
`invehicle_digital_twin_url: "http://0.0.0.0:5010"`<br><br>
1. In the top window, run:<br><br>
`./in-vehicle-digital-twin`<br>
1. In the middle window, run:<br><br>
`./seat-massager-provider`<br>
1. In the bottom window, run:<br><br>
`./seat-massager-consumer`<br>
1. Use control-c in each of the windows when you wish to stop the demo.

### <a name="using-chariott">Using Chariott</a>

If you want the consumers and providers for each demo to use Chariott to discover the URL for the In-Vehicle Digital Twin Service, rather than
having it statically provided in their respective config file, then do the following before starting each demo:

Expand Down
2 changes: 2 additions & 0 deletions devops/cg/about.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
accepted = [
"MIT",
"Apache-2.0",
"EPL-1.0",
"EPL-2.0",
"Unicode-DFS-2016",
"BSD-2-Clause",
"BSD-3-Clause",
Expand Down
4 changes: 3 additions & 1 deletion samples/command/consumer/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,9 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
)
.await?;

let consumer_authority = settings.consumer_authority;
let consumer_authority = settings
.consumer_authority
.expect("consumer_authority must be specified in the config file");

// Setup the HTTP server.
let addr: SocketAddr = consumer_authority.parse()?;
Expand Down
1 change: 1 addition & 0 deletions samples/common/src/constants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ pub mod digital_twin_operation {
// Supported digital twin protocols.
pub mod digital_twin_protocol {
pub const GRPC: &str = "grpc";
pub const MQTT: &str = "mqtt";
}

pub mod chariott {
Expand Down
2 changes: 1 addition & 1 deletion samples/common/src/consumer_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const CONFIG_FILENAME: &str = "consumer_settings";

#[derive(Debug, Deserialize)]
pub struct Settings {
pub consumer_authority: String,
pub consumer_authority: Option<String>,
pub chariott_url: Option<String>,
pub invehicle_digital_twin_url: Option<String>,
}
Expand Down
4 changes: 3 additions & 1 deletion samples/mixed/consumer/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,9 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
)
.await?;

let consumer_authority = settings.consumer_authority;
let consumer_authority = settings
.consumer_authority
.expect("consumer_authority must be specified in the config file");

let consumer_uri = format!("http://{consumer_authority}"); // Devskim: ignore DS137138

Expand Down
3 changes: 2 additions & 1 deletion samples/property/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,15 @@ async-std = { workspace = true, features = ["attributes"] }
digital-twin-model = { path = "../../digital-twin-model" }
env_logger= { workspace = true }
log = { workspace = true }
paho-mqtt = { workspace = true }
parking_lot = { workspace = true }
prost = { workspace = true }
samples-common = { path = "../common" }
samples-protobuf-data-access = { path = "../protobuf_data_access" }
serde = { workspace = true }
serde_derive = { workspace = true }
serde_json = { workspace = true }
tokio = { workspace = true, features = ["macros", "rt-multi-thread"] }
tokio = { workspace = true, features = ["macros", "rt-multi-thread", "signal"] }
tonic = { workspace = true }
url = { workspace = true }
uuid = { workspace = true, features = ["v4", "fast-rng", "macro-diagnostics"] }
Expand Down
63 changes: 0 additions & 63 deletions samples/property/consumer/src/consumer_impl.rs

This file was deleted.

Loading