aws_iot_device_sdk_rust/lib.rs
1//! aws-iot-core-sdk-rust aims to be a well-functioning and easy to use AWS IoT device SDK.
2//! At its core it uses the pure Rust MQTT client rumqttc. The name is chosen to match its C, C++, Python and JS counterparts.
3//! * Use this to easily connect your IoT devices to AWS IoT Core.
4//! * Publish and subscribe to any topic you want.
5//! * Implement the AWSEventHandler trait for your struct.
6//!
7//! The crate re-exports Mqtt311s Quality of Service enum. These are used when subscribing and
8//! publish. The variants are:
9//! * AtMostOnce (0)
10//! * AtLeastOnce (1)
11//! * ExactlyOnce (2)
12//!
13//! ## Publish and subscribe
14//! ```no_run
15//!#[tokio::main]
16//!async fn main() -> Result<(), Box<dyn std::error::Error>> {
17//! let aws_settings = aws_iot_device_sdk_rust::AWSIoTSettings::new(
18//! "clientid".to_owned(),
19//! "AmazonRootCA1.pem".to_owned(),
20//! "cert.crt".to_owned(),
21//! "key.pem".to_owned(),
22//! "endpoint.amazonaws.com".to_owned(),
23//! None
24//! );
25//!
26//! let (iot_core_client, eventloop_stuff) = aws_iot_device_sdk_rust::AWSIoTAsyncClient::new(aws_settings).await?;
27//!
28//! iot_core_client.subscribe("test".to_string(), rumqttc::QoS::AtMostOnce).await.unwrap();
29//! iot_core_client.publish("topic".to_string(), rumqttc::QoS::AtMostOnce, "hey").await.unwrap();
30//!
31//! let mut receiver1 = iot_core_client.get_receiver().await;
32//! let mut receiver2 = iot_core_client.get_receiver().await;
33//!
34//! let recv1_thread = tokio::spawn(async move {
35//! loop {
36//! match receiver1.recv().await {
37//! Ok(event) => {
38//! match event {
39//! rumqttc::Packet::Publish(p) => println!("Received message {:?} on topic: {}", p.payload, p.topic),
40//! _ => println!("Got event on receiver1: {:?}", event),
41//! }
42//!
43//! },
44//! Err(_) => (),
45//! }
46//! }
47//! });
48//!
49//! let recv2_thread = tokio::spawn(async move {
50//! loop {
51//! match receiver2.recv().await {
52//! Ok(event) => println!("Got event on receiver2: {:?}", event),
53//! Err(_) => (),
54//! }
55//! }
56//! });
57//!
58//! let listen_thread = tokio::spawn(async move {
59//! aws_iot_device_sdk_rust::async_client::async_event_loop_listener(eventloop_stuff).await.unwrap();
60//! });
61//!
62//! tokio::join!(
63//! recv1_thread,
64//! recv2_thread,
65//! listen_thread);
66//! Ok(())
67//!}
68//!
69//!```
70
71#[cfg(feature = "async")]
72pub mod async_client;
73pub mod error;
74pub mod settings;
75#[cfg(feature = "sync")]
76pub mod sync_client;
77
78#[cfg(feature = "async")]
79pub use self::async_client::{async_event_loop_listener, AWSIoTAsyncClient};
80#[cfg(feature = "sync")]
81pub use self::sync_client::AWSIoTClient;
82pub use self::{error::AWSIoTError, settings::AWSIoTSettings};
83pub use rumqttc::{EventLoop, Packet, Publish, QoS};