Crates.io | aws-iot-device-sdk-rust |
lib.rs | aws-iot-device-sdk-rust |
version | |
source | src |
created_at | 2019-12-25 13:34:00.369962 |
updated_at | 2024-12-12 14:04:45.387694 |
description | An easy to use SDK for connecting to AWS IoT Core. |
homepage | |
repository | https://github.com/arnstein/aws-iot-device-sdk-rust |
max_upload_size | |
id | 192325 |
Cargo.toml error: | TOML parse error at line 27, column 1 | 27 | autolib = false | ^^^^^^^ unknown field `autolib`, expected one of `name`, `version`, `edition`, `authors`, `description`, `readme`, `license`, `repository`, `homepage`, `documentation`, `build`, `resolver`, `links`, `default-run`, `default_dash_run`, `rust-version`, `rust_dash_version`, `rust_version`, `license-file`, `license_dash_file`, `license_file`, `licenseFile`, `license_capital_file`, `forced-target`, `forced_dash_target`, `autobins`, `autotests`, `autoexamples`, `autobenches`, `publish`, `metadata`, `keywords`, `categories`, `exclude`, `include` |
size | 0 |
The AWS IoT Device SDK for Rust allows developers to write Rust to use their devices to access the AWS IoT platform through MQTT. This is my first crate, and project, in Rust, and as I am still learning it will hopefully get a lot better with time. I have recently done a revamp of this crate, as I hadn't had time to update it in a while. Current functionality is:
connect
listen to incoming events
subscribe to topic
publish to topic
#[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(())
}
Example:
#[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, _)) = client::AWSIoTAsyncClient::new(aws_settings).await?;
let client = iot_core_client.get_client();
}