File tree Expand file tree Collapse file tree 2 files changed +21
-1
lines changed
crates/core/tedge/src/cli/mqtt Expand file tree Collapse file tree 2 files changed +21
-1
lines changed Original file line number Diff line number Diff line change @@ -30,6 +30,12 @@ pub enum TEdgeMqttCli {
30
30
/// Retain flag
31
31
#[ clap( short, long = "retain" ) ]
32
32
retain : bool ,
33
+ /// Repeat the message
34
+ #[ clap( long) ]
35
+ repeat : Option < u32 > ,
36
+ /// Pause between repeated messages (e.g., 60s, 1h)
37
+ #[ clap( long, default_value = "1s" ) ]
38
+ sleep : SecondsOrHumanTime ,
33
39
} ,
34
40
35
41
/// Subscribe a MQTT topic.
@@ -69,6 +75,8 @@ impl BuildCommand for TEdgeMqttCli {
69
75
message,
70
76
qos,
71
77
retain,
78
+ repeat,
79
+ sleep,
72
80
} => MqttPublishCommand {
73
81
host : config. mqtt . client . host . clone ( ) ,
74
82
port : config. mqtt . client . port . into ( ) ,
@@ -80,6 +88,8 @@ impl BuildCommand for TEdgeMqttCli {
80
88
ca_file : auth_config. ca_file . clone ( ) ,
81
89
ca_dir : auth_config. ca_dir ,
82
90
client_auth_config : auth_config. client ,
91
+ count : repeat. unwrap_or ( 1 ) ,
92
+ sleep : sleep. duration ( ) ,
83
93
}
84
94
. into_boxed ( ) ,
85
95
TEdgeMqttCli :: Sub {
Original file line number Diff line number Diff line change @@ -22,6 +22,8 @@ pub struct MqttPublishCommand {
22
22
pub ca_file : Option < Utf8PathBuf > ,
23
23
pub ca_dir : Option < Utf8PathBuf > ,
24
24
pub client_auth_config : Option < MqttAuthClientConfig > ,
25
+ pub count : u32 ,
26
+ pub sleep : std:: time:: Duration ,
25
27
}
26
28
27
29
#[ async_trait:: async_trait]
@@ -36,7 +38,15 @@ impl Command for MqttPublishCommand {
36
38
}
37
39
38
40
async fn execute ( & self , _: TEdgeConfig ) -> Result < ( ) , MaybeFancy < anyhow:: Error > > {
39
- Ok ( publish ( self ) . await ?)
41
+ let mut i = 0 ;
42
+ loop {
43
+ publish ( self ) . await ?;
44
+ i += 1 ;
45
+ if i == self . count {
46
+ return Ok ( ( ) ) ;
47
+ }
48
+ tokio:: time:: sleep ( self . sleep ) . await ;
49
+ }
40
50
}
41
51
}
42
52
You can’t perform that action at this time.
0 commit comments