/// Connects the device to Google cloud IoT framework
///
/// Connecting the device to Google cloud authenticating the device. This is internal method and needs to be
/// called prior the expiration period as otherwise the connection will drop.
Connects the device to Google cloud IoT framework
Connecting the device to Google cloud authenticating the device. This is internal method and needs to be
called prior the expiration period as otherwise the connection will drop.
Connects the device to Google cloud IoT framework Connecting the device to Google cloud authenticating the device . This is internal method and needs to be called prior the expiration period as otherwise the connection will drop .
async fn connect(
    client_id: &str,
    project_id: &str,
    algorithm: &Algorithm,
    expiration: &Duration,
    keep_alive: u16,
    key: &EncodingKey,
    ca_cert: &[u8],
) -> Result<Client, GcpIoTError> {
    let jwt_password = GcpMqtt::create_token(key, project_id, algorithm, expiration)?;
    let client = retry(ExponentialBackoff::default(), || async {
        info!("Creating client");
        //let mut client = Client::with_tls("mqtt.googleapis.com", 8883, ca_cert).await.map_err(GcpMqtt::err_mapper)?;
        let mqtt_init = MqttInit {
            address: "mqtt.googleapis.com".to_string(),
            port: 8883,
            ..Default::default()
        };
        let mut client = mqtt_init
            .with_tls(ca_cert)
            .await
            .map_err(GcpMqtt::err_mapper)?;
        client
            .connect(
                keep_alive,
                &client_id,
                Some("unused"),
                Some(&jwt_password[..]),
                false,
            )
            .await
            .map_err(GcpMqtt::err_mapper)?;
        Ok(client)
    })
    .await?;
    Ok(client)
}
async fn connect ( client_id : & str , project_id : & str , algorithm : & Algorithm , expiration : & Duration , keep_alive : u16 , key : & EncodingKey , ca_cert : & [ u8 ] , ) -> Result < Client , GcpIoTError > { let jwt_password = GcpMqtt :: create_token ( key , project_id , algorithm , expiration ) ? ; let client = retry ( ExponentialBackoff :: default ( ) , | | async { info ! ( " " ) ; //let mut client = Client::with_tls("mqtt.googleapis.com", 8883, ca_cert).await.map_err(GcpMqtt::err_mapper)?; let mqtt_init = MqttInit { address : " " . to_string ( ) , port : 8883 , .. Default :: default ( ) } ; let mut client = mqtt_init . with_tls ( ca_cert ) . await . map_err ( GcpMqtt :: err_mapper ) ? ; client . connect ( keep_alive , & client_id , Some ( " " ) , Some ( & jwt_password [ .. ] ) , false , ) . await . map_err ( GcpMqtt :: err_mapper ) ? ; Ok ( client ) } ) . await ? ; Ok ( client ) }
Connects the device to Google cloud IoT framework
Connecting the device to Google cloud authenticating the device.
Connects the device to Google cloud IoT framework Connecting the device to Google cloud authenticating the device .
client_id
&str
project_id
&str
algorithm
&Algorithm
expiration
&Duration
keep_alive
u16
key
&EncodingKey
ca_cert
&[u8]