/// Creates new Google cloud MQTT instance
///
/// Used for setting up MQTT for Google cloud with all necessary parameters.
///
Creates new Google cloud MQTT instance
Used for setting up MQTT for Google cloud with all necessary parameters.
Creates new Google cloud MQTT instance Used for setting up MQTT for Google cloud with all necessary parameters .
pub async fn new(
        algorithm: Algorithm,
        expiration: Duration,
        project_id: String,
        cloud_region: String,
        registry: String,
        device_id: String,
        keep_alive: u16,
        cert: Vec<u8>,
        ca_cert: &[u8],
    ) -> Result<Self, GcpIoTError> {
        let key = EncodingKey::from_ec_pem(&cert)
            .map_err(|source| GcpIoTError::JsonWebTokenError { source })?;
        // Creating the standard topics to Gcp MQTT. Client topics are added separately
        let topic_prefix = format!("/devices/{}/", device_id);
        let gcp_subscription = vec![
            (topic_prefix.to_owned() + "config", Qos::AtLeastOnce),
            (topic_prefix.to_owned() + "commands/#", Qos::AtLeastOnce),
        ];
        let client_id = format!(
            "projects/{}/locations/{}/registries/{}/devices/{}",
            project_id, cloud_region, registry, device_id
        );
        info!(
            "Project ID:{} Region:{} Registry:{} Device ID:{}, token expiration:{:?} Keep-alive:{}",
            project_id, cloud_region, registry, device_id, expiration, keep_alive
        );
        let mut client = connect(
            &client_id,
            &project_id,
            &algorithm,
            &expiration,
            keep_alive,
            &key,
            ca_cert,
        )
        .await?;
        debug!("MQTTInit done");
        let mut subs = client.subscribe(&gcp_subscription).await?;
        let (config, _) = subs.remove(0)?;
        let (command, _) = subs.remove(0)?;
        info!("GcpMqtt creation succeeded");
        Ok(Self {
            algorithm,
            expiration,
            project_id,
            device_id,
            client_id,
            cert,
            ca_cert: ca_cert.to_vec(),
            config,
            command,
            client,
            key,
            keep_alive,
            topic_prefix,
        })
    }
pub async fn new ( algorithm : Algorithm , expiration : Duration , project_id : String , cloud_region : String , registry : String , device_id : String , keep_alive : u16 , cert : Vec < u8 > , ca_cert : & [ u8 ] , ) -> Result < Self , GcpIoTError > { let key = EncodingKey :: from_ec_pem ( & cert ) . map_err ( | source | GcpIoTError :: JsonWebTokenError { source } ) ? ; // Creating the standard topics to Gcp MQTT. Client topics are added separately let topic_prefix = format ! ( " " device_id ) ; let gcp_subscription = vec ! [ ( topic_prefix to_owned ( ) " " Qos AtLeastOnce ) ( topic_prefix to_owned ( ) " " Qos AtLeastOnce ) ] ; let client_id = format ! ( " " project_id cloud_region registry device_id ) ; info ! ( " " project_id cloud_region registry device_id expiration keep_alive ) ; let mut client = connect ( & client_id , & project_id , & algorithm , & expiration , keep_alive , & key , ca_cert , ) . await ? ; debug ! ( " " ) ; let mut subs = client . subscribe ( & gcp_subscription ) . await ? ; let ( config , _ ) = subs . remove ( 0 ) ? ; let ( command , _ ) = subs . remove ( 0 ) ? ; info ! ( " " ) ; Ok ( Self { algorithm , expiration , project_id , device_id , client_id , cert , ca_cert : ca_cert . to_vec ( ) , config , command , client , key , keep_alive , topic_prefix , } ) }
Creates new Google cloud MQTT instance
Used for setting up MQTT for Google cloud with all necessary parameters.
Creates new Google cloud MQTT instance Used for setting up MQTT for Google cloud with all necessary parameters .
algorithm
Algorithm
expiration
Duration
project_id
String
cloud_region
String
registry
String
device_id
String
keep_alive
u16
cert
Vec<u8>
ca_cert
&[u8]