Skip to content

Commit d8df5b8

Browse files
authored
Add NIOTS and AWS sections to README (#11)
* Add NIOTS and AWS sections to README
1 parent 4860150 commit d8df5b8

File tree

1 file changed

+38
-2
lines changed

1 file changed

+38
-2
lines changed

README.md

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,11 +67,47 @@ let client = MQTTClient(
6767
port: 8884,
6868
identifier: "MySSLClient",
6969
eventLoopGroupProvider: .createNew,
70-
configuration: .init(useSSL: true, tlsConfiguration: tlsConfiguration),
70+
configuration: .init(useSSL: true, tlsConfiguration: .niossl(tlsConfiguration)),
7171
)
7272
```
73-
Currently trustRoots and client certificates are not fully while using NIO Transport Services and therefore not supported on iOS.
7473

7574
## WebSockets
7675

7776
MQTT also supports Web Socket connections. Set `Configuration.useWebSockets` to `true` and set the URL path in `Configuration.webSocketsURLPath` to enable these.
77+
78+
## NIO Transport Services
79+
80+
On macOS and iOS you can use the NIO Transport Services library (NIOTS) and Apple's `Network.framework` for communication with the MQTT broker. If you don't provide an `eventLoopGroup` or a `TLSConfigurationType` then this is the default for both platforms. If you do provide either of these then the library will base it's decision on whether to use NIOTS or NIOSSL on what you provide. Provide a `MultiThreadedEventLoopGroup` or `NIOSSL.TLSConfiguration` and the client will use NIOSSL. Provide a `NIOTSEventLoopGroup` or `TSTLSConfiguration` and the client will use NIOTS. If you provide a `MultiThreadedEventLoopGroup` and a `TSTLSConfiguration` then the client will throw an error. If you are running on iOS you should always choose NIOTS.
81+
82+
## AWS IoT
83+
84+
The MQTT client can be used to connect to AWS IoT brokers. You can use both a WebSocket connection authenticated using AWS Signature V4 and a standard connection using a X.509 client certificate. If you are using a X.509 certificate make sure you update the attached role to allow your client id to connect and which topics you can subscribe, publish to.
85+
86+
If you are using an AWS Signature V4 authenticated WebSocket connection you can use the V4 signer from [SotoCore](https://github.com/soto-project/soto) to sign your initial request as follows
87+
```swift
88+
import SotoSignerV4
89+
90+
let host = "MY_AWS_IOT_ENDPOINT"
91+
let port = 443
92+
let headers = HTTPHeaders([("host", host)])
93+
let signer = AWSSigner(
94+
credentials: StaticCredential(accessKeyId: "MYACCESSKEY", secretAccessKey: "MYSECRETKEY"),
95+
name: "iotdata",
96+
region: "eu-west-1"
97+
)
98+
let signedURL = signer.signURL(
99+
url: URL(string: "https://\(host):\(port)/mqtt")!,
100+
method: .GET,
101+
headers: headers,
102+
body: .none,
103+
expires: .minutes(30)
104+
)
105+
let requestURI = "/mqtt?\(signedURL.query!)"
106+
let client = MQTTClient(
107+
host: host,
108+
port: port,
109+
eventLoopGroupProvider: .createNew,
110+
configuration: .init(useSSL: true, useWebSockets: true, webSocketURLPath: requestUri)
111+
)
112+
```
113+
You can find out more about connecting to AWS brokers [here](https://docs.aws.amazon.com/iot/latest/developerguide/protocols.html)

0 commit comments

Comments
 (0)