Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/damienpontifex/azure-iot-sdk-rs
A rust library for connecting devices to Microsoft Azure IoT Hub
https://github.com/damienpontifex/azure-iot-sdk-rs
azure azure-iot http-client iot mqtt-client rust
Last synced: 2 days ago
JSON representation
A rust library for connecting devices to Microsoft Azure IoT Hub
- Host: GitHub
- URL: https://github.com/damienpontifex/azure-iot-sdk-rs
- Owner: damienpontifex
- License: mit
- Created: 2020-04-18T01:59:42.000Z (almost 5 years ago)
- Default Branch: main
- Last Pushed: 2025-02-02T06:52:47.000Z (18 days ago)
- Last Synced: 2025-02-02T07:24:51.327Z (18 days ago)
- Topics: azure, azure-iot, http-client, iot, mqtt-client, rust
- Language: Rust
- Homepage:
- Size: 184 KB
- Stars: 15
- Watchers: 3
- Forks: 11
- Open Issues: 20
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Azure IoT SDK for Rust
Self developed library to interact with [Azure IoT Hub using MQTT protocol](https://docs.microsoft.com/en-us/azure/iot-hub/iot-hub-mqtt-support)

[](https://docs.rs/azure_iot_sdk)
[](https://crates.io/crates/azure_iot_sdk)
[](https://crates.io/crates/azure_iot_sdk)
[](https://crates.io/crates/azure_iot_sdk)## Usage
```rust
use azure_iot_sdk::{client::IoTHubClient, message::Message};
use log::info;#[tokio::main]
async fn main() {
env_logger::from_env(env_logger::Env::default().default_filter_or("info")).init();let hostname = std::env::var("IOTHUB_HOSTNAME")
.expect("Set IoT Hub hostname in the IOTHUB_HOSTNAME environment variable");
let device_id = std::env::var("DEVICE_ID")
.expect("Set the device id in the DEVICE_ID environment variable");
let shared_access_key = std::env::var("SHARED_ACCESS_KEY")
.expect("Set the device shared access key in the SHARED_ACCESS_KEY environment variable");let token_source = DeviceKeyTokenSource::new(
&hostname,
&device_id,
&shared_access_key,
)
.unwrap();let mut client = IoTHubClient::new(&hostname, device_id, token_source.into()).await?;
info!("Initialized client");
let mut recv = client.get_receiver().await;
let receive_loop = async {
while let Some(msg) = recv.recv().await {
match msg {
MessageType::C2DMessage(msg) => info!("Received message {:?}", msg),
_ => {}
}
}
};let msg = Message::new(b"Hello, world!".to_vec());
let sender = client.send_message(msg);tokio::join!(receive_loop, sender);
}
```