Skip to content

feat: tedge connect to c8y mqtt service endpoint #3707

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

Open
wants to merge 12 commits into
base: main
Choose a base branch
from
Open
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
1 change: 1 addition & 0 deletions crates/common/tedge_config/src/tedge_toml/models/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ use strum::Display;

pub const HTTPS_PORT: u16 = 443;
pub const MQTT_TLS_PORT: u16 = 8883;
pub const MQTT_SVC_TLS_PORT: u16 = 9883;

pub use self::apt_config::*;
pub use self::auto::*;
Expand Down
37 changes: 37 additions & 0 deletions crates/common/tedge_config/src/tedge_toml/tedge_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ use super::models::SoftwareManagementApiFlag;
use super::models::TemplatesSet;
use super::models::TopicPrefix;
use super::models::HTTPS_PORT;
use super::models::MQTT_SVC_TLS_PORT;
use super::models::MQTT_TLS_PORT;
use super::tedge_config_location::TEdgeConfigLocation;
use crate::models::AbsolutePath;
Expand Down Expand Up @@ -226,6 +227,10 @@ define_tedge_config! {
#[tedge_config(reader(private))]
url: ConnectUrl,

/// Cumulocity tenant ID
#[tedge_config(example = "t12345678")]
tenant_id: String,

/// The path where Cumulocity root certificate(s) are stored
#[tedge_config(note = "The value can be a directory path as well as the path of the certificate file.")]
#[tedge_config(example = "/etc/tedge/c8y-trusted-root-certificates.pem", default(function = "default_root_cert_path"))]
Expand Down Expand Up @@ -433,6 +438,28 @@ define_tedge_config! {
#[tedge_config(example = "60m", default(from_str = "60m"))]
interval: SecondsOrHumanTime,
},

mqtt_service: {
/// Wheather to connect to the MQTT service endpoint or not
#[tedge_config(example = "true", default(value = false))]
enabled: bool,

/// MQTT service endpoint for the Cumulocity tenant, with optional port.
#[tedge_config(example = "mqtt.your-tenant.cumulocity.com:9883")]
#[tedge_config(default(from_optional_key = "c8y.mqtt"))]
url: HostPort<MQTT_SVC_TLS_PORT>,

/// The topic prefix that will be used for the Cumulocity MQTT service endpoint connection.
/// For instance, if set to "c8y-mqtt", then messages published to `c8y-mqtt/xyz`
/// will be forwarded to the MQTT service endpoint on the `xyz` topic
#[tedge_config(example = "c8y-mqtt", default(function = "c8y_mqtt_service_topic_prefix"))]
topic_prefix: TopicPrefix,

/// Set of MQTT topics the bridge should subscribe to on the Cumulocity MQTT service endpoint
#[tedge_config(example = "incoming/topic,another/topic,test/topic")]
#[tedge_config(default(value = "$demo/$error"))]
topics: TemplatesSet,
}
},

#[tedge_config(deprecated_name = "azure")] // for 0.1.0 compatibility
Expand Down Expand Up @@ -1114,6 +1141,16 @@ fn c8y_topic_prefix() -> TopicPrefix {
TopicPrefix::try_new("c8y").unwrap()
}

fn c8y_mqtt_service_topic_prefix() -> TopicPrefix {
TopicPrefix::try_new("c8y-mqtt").unwrap()
}

impl From<HostPort<MQTT_TLS_PORT>> for HostPort<MQTT_SVC_TLS_PORT> {
fn from(value: HostPort<MQTT_TLS_PORT>) -> Self {
HostPort::try_from(value.host().to_string()).expect("Source hostname must have been valid")
}
}

fn az_topic_prefix() -> TopicPrefix {
TopicPrefix::try_new("az").unwrap()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ impl_append_remove_for_single_value!(
ConnectUrl,
HostPort<HTTPS_PORT>,
HostPort<MQTT_TLS_PORT>,
HostPort<MQTT_SVC_TLS_PORT>,
bool,
IpAddr,
u16,
Expand Down
Loading
Loading