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