Struct Client

Source
pub struct Client { /* private fields */ }
Expand description

Fundamentum IoT Async Client

Implementations§

Source§

impl Client

Source

pub async fn new(settings: ClientSettings) -> Result<Self, Error>

Create new FundamentumIoTAsyncClient. Input argument should be the FundamentumIoTSettings. Returns a tuple where the first element is the FundamentumIoTAsyncClient, and the second element is a new tuple with the eventloop and incoming event sender. This tuple should be sent as an argument to the async_event_loop_listener.

§Errors

If the creation failed then the result returns an error FundamentumIoTError

Source

pub async fn run(&self) -> Result<(), Error>

Run the client’s background task.

This task continuously polls the underlying even loop which ensures messages are exchanged between this client and the broker.

Nothing will be exchanged until this task is run.

§Errors

Returns an error::Error if a fatal MQTT connection error occurs that cannot be retried or recovered from. The underlying ConnectionError is considered fatal if it matches one of the following MQTT connection refusal codes:

  • ProtocolError
  • UnsupportedProtocolVersion
  • ClientIdentifierNotValid
  • BadUserNamePassword
  • NotAuthorized
  • Banned
  • BadAuthenticationMethod
  • UseAnotherServer
  • ServerMoved

In these cases, the client will terminate with an error. For all other connection errors (such as temporary network issues), the client will attempt to reconnect automatically (backoff).

Any error returned by this function indicates that the client can no longer function and requires user intervention.

Source

pub async fn subscribe<S: Into<String> + Send>( &self, topic: S, qos: QoS, ) -> Result<(), ClientError>

Subscribe to a topic

§Errors

Returns ClientError if the request failed

Source

pub async fn subscribe_config(&self, qos: QoS) -> Result<(), ClientError>

Subscribe to device’s config channel

§Reference
  • registries/{REGISTRY_ID}/devices/{DEVICE_SN}/config
§Errors

Returns ClientError if the request failed

Source

pub async fn subscribe_portforward(&self, qos: QoS) -> Result<(), ClientError>

Subscribe to device’s port forward channel

§Reference
  • registries/{REGISTRY_ID}/devices/{DEVICE_SN}/portforward/tx
§Errors

Returns ClientError if the request failed

Source

pub async fn subscribe_commands(&self, qos: QoS) -> Result<(), ClientError>

Subscribe to device’s commands channel

§Reference
  • registries/{REGISTRY_ID}/devices/{DEVICE_SN}/commands
§Errors

Returns ClientError if the request failed

Source

pub async fn subscribe_actions(&self, qos: QoS) -> Result<(), ClientError>

Subscribe to device’s actions channel

§Reference
  • registries/{REGISTRY_ID}/devices/{DEVICE_SN}/actions
§Errors

Returns ClientError if the request failed

Source

pub async fn publish<S, V>( &self, topic: S, qos: QoS, payload: V, ) -> Result<(), ClientError>
where S: Into<String> + Send, V: Into<Bytes> + Send,

Publish to topic.

§Errors

Returns ClientError if the request failed

Source

pub async fn publish_with_properties<S, V>( &self, topic: S, qos: QoS, payload: V, publish_properties: Option<PublishProperties>, ) -> Result<(), ClientError>
where S: Into<String> + Send, V: Into<Bytes> + Send,

Publish to topic with properties.

§Errors

Returns ClientError if the request failed

Source

pub async fn publish_portforward<V>( &self, qos: QoS, payload: V, headers: HashMap<String, String>, ) -> Result<(), ClientError>
where V: Into<Bytes> + Send,

Publish port forward

§Reference
  • registries/{REGISTRY_ID}/devices/{DEVICE_SN}/pfwd/rx
§Errors

Returns ClientError if the request failed

Source

pub async fn publish_action_response( &self, qos: QoS, id: u64, response: ActionResponse, ) -> Result<(), ClientError>

Publish action response

§Reference
  • registries/{REGISTRY_ID}/devices/{DEVICE_SN}/actions/{ACTION_ID}/response
§Errors

Returns ClientError if the request failed

Source

pub async fn publish_events<S, V>( &self, sub_topic: Option<S>, qos: QoS, payload: V, ) -> Result<(), ClientError>
where S: Into<String> + Send, V: Into<Bytes> + Send,

Publish event

§Reference
  • registries/{REGISTRY_ID}/devices/{DEVICE_SN}/events[/sub_topic]
§Errors

Returns ClientError if the request failed

Source

pub async fn publish_heartbeat( &self, qos: QoS, params: &HeartBeat, ) -> Result<(), ClientError>

Publish heartbeat

§Params
  • qos: mqtt’s qos
  • uptime: number of second since boot
§Reference
  • registries/{REGISTRY_ID}/devices/{DEVICE_SN}/heartbeat
§Errors

Returns ClientError if the request failed

§Panics

This function should never panic because the string is controled by rust types

Source

pub async fn publish_states( &self, qos: QoS, params: &StatesEvent, ) -> Result<(), ClientError>

Publish states

§Reference
  • registries/{REGISTRY_ID}/devices/{DEVICE_SN}/states
§Errors

Returns ClientError if the request failed

§Panics

This function should never panic because the string is controled by rust types

Source

pub async fn publish_update_command( &self, cmdid: u64, qos: QoS, params: &DeviceCommandUpdate, ) -> Result<(), ClientError>

Publish Device Command Update

The command update the current status of a receive command. The device_command_id comes from the command receive by the client.

§Reference
  • registries/{REGISTRY_ID}/devices/{DEVICE_SN}/commands/{DEVICE_COMMAND_ID}
§Errors

Returns ClientError if the request failed

§Panics

This function should never panic because the string is controled by rust types

Source

pub fn get_receiver(&self) -> Receiver<Message>

Get a receiver of the incoming messages. Send this to any function that wants to read the incoming messages from IoT Core.

Note that it is very important that your retrieve your receiver prior to any subscribe_ of interest. Otherwise, you most likely won’t receive messages sent to you in between this call and prior subscriptions.

This is of particular importance for messages returned as a result to your subscription.

Source

pub fn get_client(self) -> AsyncClient

If you want to use the Rumqttc AsyncClient and EventLoop manually, this method can be used to get the AsyncClient.

Source

pub fn status_stream(&self) -> ClientStatusStream

Monitor our client’s statuses over time.

The returned ClientStatusStream is a futures::Stream of ClientStatus that can also provide the most recent status through its current method.

§Returns

The streamable monitor instance.

Trait Implementations§

Source§

impl Clone for Client

Source§

fn clone(&self) -> Client

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more

Auto Trait Implementations§

§

impl Freeze for Client

§

impl !RefUnwindSafe for Client

§

impl Send for Client

§

impl Sync for Client

§

impl Unpin for Client

§

impl !UnwindSafe for Client

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more