|
2 | 2 |
|
3 | 3 | import awscrt
|
4 | 4 | from awscrt import mqtt
|
| 5 | +from awsiot import mqtt_connection_builder |
5 | 6 | import awscrt.io
|
6 | 7 | import json
|
7 | 8 | from awscrt.exceptions import AwsCrtError
|
@@ -95,26 +96,18 @@ def __init__(
|
95 | 96 | socket_options.keep_alive_interval_secs = 0
|
96 | 97 | socket_options.keep_alive_max_probes = 0
|
97 | 98 |
|
98 |
| - client_bootstrap = awscrt.io.ClientBootstrap.get_or_create_static_default() |
99 |
| - |
100 |
| - tls_ctx = awscrt.io.ClientTlsContext(tls_ctx_options) |
101 |
| - mqtt_client = awscrt.mqtt.Client(client_bootstrap, tls_ctx) |
102 |
| - |
103 |
| - self.connection = awscrt.mqtt.Connection( |
104 |
| - client=mqtt_client, |
| 99 | + self.connection = mqtt_connection_builder.mtls_from_path( |
| 100 | + endpoint=endpoint, |
| 101 | + port=port, |
| 102 | + cert_filepath=cert_path, |
| 103 | + pri_key_filepath=key_path, |
| 104 | + ca_filepath=ca_cert_path, |
105 | 105 | on_connection_interrupted=self._on_connection_interrupted,
|
106 | 106 | on_connection_resumed=self._on_connection_resumed,
|
107 | 107 | client_id=client_id,
|
108 |
| - host_name=endpoint, |
109 |
| - port=port, |
110 |
| - clean_session=clean_session, |
111 |
| - reconnect_min_timeout_secs=5, |
112 |
| - reconnect_max_timeout_secs=60, |
113 |
| - keep_alive_secs=keep_alive_secs, |
114 |
| - ping_timeout_ms=3000, |
115 |
| - protocol_operation_timeout_ms=0, |
116 |
| - socket_options=socket_options, |
117 |
| - use_websockets=False, |
| 108 | + proxy_options=None, |
| 109 | + clean_session=False, |
| 110 | + keep_alive_secs=30, |
118 | 111 | on_connection_success=self._on_connection_success,
|
119 | 112 | on_connection_failure=self._on_connection_failure,
|
120 | 113 | on_connection_closed=self._on_connection_closed,
|
@@ -215,3 +208,16 @@ def send_message(
|
215 | 208 | use_logger.info(f'Sent {sys.getsizeof(payload)} bytes to "{topic}"')
|
216 | 209 |
|
217 | 210 | # self._disconnect()
|
| 211 | + |
| 212 | + |
| 213 | +if __name__ == "__main__": |
| 214 | + |
| 215 | + conn = IotCoreMQTTConnection( |
| 216 | + endpoint="a10mem0twl4qxt-ats.iot.eu-west-2.amazonaws.com", |
| 217 | + cert_path="C:/Users/lewcha/OneDrive - UKCEH/Documents/FDRI/projects/iot-device-simulator/src/iotswarm/__assets__/.certs/cosmos_soilmet-certificate.pem.crt", |
| 218 | + key_path="C:/Users/lewcha/OneDrive - UKCEH/Documents/FDRI/projects/iot-device-simulator/src/iotswarm/__assets__/.certs/cosmos_soilmet-private.pem.key", |
| 219 | + ca_cert_path="C:/Users/lewcha/OneDrive - UKCEH/Documents/FDRI/projects/iot-device-simulator/src/iotswarm/__assets__/.certs/AmazonRootCA1.pem", |
| 220 | + client_id="cosmos_soilmet", |
| 221 | + ) |
| 222 | + |
| 223 | + conn.send_message("hello there", "test/topic") |
0 commit comments