@@ -35,6 +35,7 @@ use tedge_config::tedge_toml::mapper_config::C8yMapperSpecificConfig;
3535use tedge_config:: tedge_toml:: MqttAuthConfigCloudBroker ;
3636use tedge_config:: tedge_toml:: ProfileName ;
3737use tedge_config:: TEdgeConfig ;
38+ use tracing:: debug;
3839
3940const CONNECTION_ERROR_CONTEXT : & str = "Connection error while creating device in Cumulocity" ;
4041
@@ -86,7 +87,11 @@ pub async fn create_device_with_direct_connection(
8687
8788 loop {
8889 match eventloop. poll ( ) . await {
89- Ok ( Event :: Incoming ( Packet :: ConnAck ( _) ) ) => {
90+ Ok ( Event :: Incoming ( Packet :: ConnAck ( connack) ) ) => {
91+ debug ! (
92+ "Received ConnAck ({:?}), session_present={:?}" ,
93+ connack. code, connack. session_present
94+ ) ;
9095 // Connection established, publish device creation message
9196 publish_device_create_message (
9297 & mut client,
@@ -95,13 +100,18 @@ pub async fn create_device_with_direct_connection(
95100 )
96101 . await ?;
97102 }
98- Ok ( Event :: Incoming ( Packet :: PubComp ( _) ) ) => {
103+ Ok ( Event :: Incoming ( Packet :: PubAck ( _) ) ) => {
104+ debug ! ( "Received PubAck" ) ;
99105 // Device creation message acknowledged by the cloud
100106 return Ok ( ( ) ) ;
101107 }
102108 Ok ( Event :: Incoming ( Incoming :: Disconnect ) ) => {
109+ debug ! ( "Received Disconnect" ) ;
103110 bail ! ( "Unexpectedly disconnected from Cumulocity while attempting to create device" )
104111 }
112+ Ok ( Event :: Incoming ( Incoming :: PingResp ) ) => {
113+ debug ! ( "Received PingResp" ) ;
114+ }
105115 Ok ( Event :: Outgoing ( Outgoing :: PingReq ) ) => {
106116 // No acknowledgment received for device creation message even after 5s (keep alive interval)
107117 bail ! ( "Timed-out waiting for device creation acknowledgment from Cumulocity" )
@@ -277,12 +287,16 @@ async fn publish_device_create_message(
277287) -> Result < ( ) , ConnectError > {
278288 use c8y_api:: smartrest:: message_ids:: DEVICE_CREATION ;
279289 const DEVICE_CREATE_PUBLISH_TOPIC : & str = "s/us" ;
290+ let payload = format ! ( "{DEVICE_CREATION},{device_id},{device_type}" ) ;
291+ debug ! (
292+ "Registering device in Cumulocity. topic={DEVICE_CREATE_PUBLISH_TOPIC}, payload={payload}"
293+ ) ;
280294 client
281295 . publish (
282296 DEVICE_CREATE_PUBLISH_TOPIC ,
283- QoS :: ExactlyOnce ,
297+ QoS :: AtLeastOnce ,
284298 false ,
285- format ! ( "{DEVICE_CREATION},{},{}" , device_id , device_type ) . as_bytes ( ) ,
299+ payload . as_bytes ( ) ,
286300 )
287301 . await ?;
288302 Ok ( ( ) )
0 commit comments