Expand description
Azure IoT device client for writing iot device code in rust
§Feature flags
SDK client uses feature flags to configure capabilities of the client sdk. By default all features are enabled.
Device to cloud messaging is always available.
c2d-messages
: Enables cloud to device messagingtwin-properties
: Enables device twin property updatesdirect-methods
: Enables listening for direct method invocations
§Disabling capabilities
If not all features are required, disable the default features and add only desired.
azure_iot_sdk = { version = "0.3.0", features = [], default-features = false }
§Examples
A simple client
use tokio::time;
use azure_iot_sdk::{IoTHubClient, DeviceKeyTokenSource, Message};
#[tokio::main]
async fn main() -> azure_iot_sdk::Result<()> {
let iothub_hostname = "iothubname.azure-devices.net";
let device_id = "MyDeviceId";
let token_source = DeviceKeyTokenSource::new(
iothub_hostname,
device_id,
"TheAccessKey",
).unwrap();
let mut client =
IoTHubClient::new(iothub_hostname, device_id.into(), token_source).await?;
let mut interval = time::interval(time::Duration::from_secs(1));
let mut count: u32 = 0;
loop {
interval.tick().await;
let msg = Message::builder()
.set_body(format!("Message #{}", count).as_bytes().to_vec())
.set_message_id(format!("{}-t", count))
.build();
client.send_message(msg).await?;
count += 1;
}
Ok(())
}
Re-exports§
Modules§
- client
- The IoT Hub client
- message
- Message types for communicating with the IoT Hub
- provision
- Provision support using Azure device provisioning service
- token
- transport
- Transport types
Constants§
- SDK_
VERSION - IoT SDK package version
Type Aliases§
- Result
- Convenience type alias for
std::result::Result<T, Box<dyn std::error::Error>>