[−][src]Struct azure_iot_sdk::client::IoTHubClient
Client for communicating with IoT hub
Methods
impl IoTHubClient
[src]
pub async fn with_device_key(
hub: String,
device_id: String,
key: String
) -> Self
[src]
hub: String,
device_id: String,
key: String
) -> Self
Create a new IoT Hub device client using the device's primary key
Arguments
hub
- The IoT hub resource namedevice_id
- The registered device to connect askey
- The primary or secondary key for this device
Example
use azure_iot_sdk::client::IoTHubClient; #[tokio::main] async fn main() { let mut client = IoTHubClient::with_device_key( "iothubname.azure-devices.net".into(), "MyDeviceId".into(), "TheAccessKey".into()).await; }
pub async fn from_connection_string<'_>(connection_string: &'_ str) -> Self
[src]
Create a new IoT Hub device client using the device's connection string
Arguments
connection_string
- The connection string for this device and iot hub
Example
use azure_iot_sdk::client::IoTHubClient; #[tokio::main] async fn main() { let mut client = IoTHubClient::from_connection_string( "HostName=iothubname.azure-devices.net;DeviceId=MyDeviceId;SharedAccessKey=TheAccessKey").await; }
pub async fn new(hub_name: String, device_id: String, sas: String) -> Self
[src]
Create a new IoT Hub device client using a shared access signature
Arguments
hub_name
- The IoT hub resource namedevice_id
- The registered device to connect assas
- The shared access signature for this device to connect with
Example
use azure_iot_sdk::client::IoTHubClient; #[tokio::main] async fn main() { let mut client = IoTHubClient::new( "iothubname.azure-devices.net".into(), "MyDeviceId".into(), "SharedAccessSignature sr=iothubname.azure-devices.net%2Fdevices%2MyDeviceId&sig=vn0%2BgyIUKgaBhEU0ypyOhJ0gPK5fSY1TKdvcJ1HxhnQ%3D&se=1587123309".into()).await; }
pub async fn send_message<'_>(&'_ mut self, message: Message)
[src]
Send a device to cloud message for this device to the IoT Hub
#Example
use azure_iot_sdk::client::IoTHubClient; use azure_iot_sdk::message::Message; use tokio::time; #[tokio::main] async fn main() { let mut client = IoTHubClient::with_device_key( "iothubname.azure-devices.net".into(), "MyDeviceId".into(), "TheAccessKey".into()).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; } }
pub async fn on_message<'_, T>(&'_ mut self, handler: T) where
T: Fn(Message) + Send + 'static,
[src]
T: Fn(Message) + Send + 'static,
Define the cloud to device message handler
Example
use azure_iot_sdk::client::IoTHubClient; #[tokio::main] async fn main() { let mut client = IoTHubClient::with_device_key( "iothubname.azure-devices.net".into(), "MyDeviceId".into(), "TheAccessKey".into()).await; client .on_message(|msg| { println!("Received message {:?}", msg); }) .await; }
pub async fn on_direct_method<'_, T>(&'_ mut self, handler: T) where
T: Fn(String, Message) -> i32 + Send + 'static,
[src]
T: Fn(String, Message) -> i32 + Send + 'static,
Define the message handler for direct method invocation
Example
use azure_iot_sdk::client::IoTHubClient; #[tokio::main] async fn main() { let mut client = IoTHubClient::with_device_key( "iothubname.azure-devices.net".into(), "MyDeviceId".into(), "TheAccessKey".into()).await; client .on_direct_method(|method_name, msg| { println!("Received direct method {} {}", method_name, std::str::from_utf8(&msg.body).unwrap()); 0 }) .await; }
pub async fn on_twin_update<'_, T>(&'_ mut self, handler: T) where
T: Fn(Message) + Send + 'static,
[src]
T: Fn(Message) + Send + 'static,
Define the cloud to device message handler
Example
use azure_iot_sdk::client::IoTHubClient; #[tokio::main] async fn main() { let mut client = IoTHubClient::with_device_key( "iothubname.azure-devices.net".into(), "MyDeviceId".into(), "TheAccessKey".into()).await; client .on_twin_update(|msg| { println!("Received message {:?}", msg); }) .await; }
Trait Implementations
impl Clone for IoTHubClient
[src]
fn clone(&self) -> IoTHubClient
[src]
fn clone_from(&mut self, source: &Self)
1.0.0[src]
impl Debug for IoTHubClient
[src]
Auto Trait Implementations
impl !RefUnwindSafe for IoTHubClient
impl Send for IoTHubClient
impl Sync for IoTHubClient
impl Unpin for IoTHubClient
impl !UnwindSafe for IoTHubClient
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> Same<T> for T
type Output = T
Should always be Self
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
fn to_owned(&self) -> T
[src]
fn clone_into(&self, target: &mut T)
[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,