forked from damienpontifex/azure-iot-sdk-rs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdevice-provisioning-service.rs
33 lines (26 loc) · 1.11 KB
/
device-provisioning-service.rs
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
use azure_iot_sdk::{IoTHubClient, Message};
use log::info;
#[tokio::main]
async fn main() -> azure_iot_sdk::Result<()> {
env_logger::Builder::from_env(env_logger::Env::default().default_filter_or("info")).init();
let scope_id = std::env::var("DPS_SCOPE_ID").expect(
"Set the device provisioning service scope id in the DPS_SCOPE_ID environment variable",
);
let registration_id = std::env::var("DPS_REGISTRATION_ID").expect("Set the device provisioning service registration id in the DPS_REGISTRATION_ID environment variable");
let device_key = std::env::var("DPS_DEVICE_KEY").expect(
"Set the device provisioning service device key in the DPS_DEVICE_KEY environment variable",
);
let mut client =
IoTHubClient::from_provision_service(&scope_id, registration_id, &device_key, 5)
.await
.unwrap();
info!("Initialized client {:?}", client);
for _ in 0..5 {
let msg = Message::new(b"Hello, world!".to_vec());
client
.send_message(msg)
.await
.expect("Failed to send message");
}
Ok(())
}