@@ -41,6 +41,65 @@ def main(ctx: click.Context, log_config: Path):
41
41
main .add_command (test )
42
42
43
43
44
+ @main .command ()
45
+ @click .pass_context
46
+ @click .argument (
47
+ "client-id" ,
48
+ type = click .STRING ,
49
+ )
50
+ @click .argument ("topic" , type = click .STRING )
51
+ @click .argument ("message" , type = click .STRING )
52
+ @click .option (
53
+ "--endpoint" ,
54
+ type = click .STRING ,
55
+ required = True ,
56
+ envvar = "IOT_SWARM_MQTT_ENDPOINT" ,
57
+ help = "Endpoint of the MQTT receiving host." ,
58
+ )
59
+ @click .option (
60
+ "--cert-path" ,
61
+ type = click .Path (exists = True ),
62
+ required = True ,
63
+ envvar = "IOT_SWARM_MQTT_CERT_PATH" ,
64
+ help = "Path to public key certificate for the device. Must match key assigned to the `--client-id` in the cloud provider." ,
65
+ )
66
+ @click .option (
67
+ "--key-path" ,
68
+ type = click .Path (exists = True ),
69
+ required = True ,
70
+ envvar = "IOT_SWARM_MQTT_KEY_PATH" ,
71
+ help = "Path to the private key that pairs with the `--cert-path`." ,
72
+ )
73
+ @click .option (
74
+ "--ca-cert-path" ,
75
+ type = click .Path (exists = True ),
76
+ required = True ,
77
+ envvar = "IOT_SWARM_MQTT_CA_CERT_PATH" ,
78
+ help = "Path to the root Certificate Authority (CA) for the MQTT host." ,
79
+ )
80
+ def test_mqtt (
81
+ ctx : click .Context ,
82
+ message ,
83
+ topic ,
84
+ client_id : str ,
85
+ endpoint : str ,
86
+ cert_path : str ,
87
+ key_path : str ,
88
+ ca_cert_path : str ,
89
+ ):
90
+ """Tests that a basic message can be sent via mqtt."""
91
+
92
+ connection = IotCoreMQTTConnection (
93
+ endpoint = endpoint ,
94
+ cert_path = cert_path ,
95
+ key_path = key_path ,
96
+ ca_cert_path = ca_cert_path ,
97
+ client_id = client_id ,
98
+ )
99
+
100
+ connection .send_message (message , topic )
101
+
102
+
44
103
@main .group ()
45
104
@click .pass_context
46
105
@click .option (
0 commit comments