azure-iot-device package

Classes

Message

The Message object is used for telemetry (device-to-cloud) and commands (cloud-to-device) asynchronous messaging between the device and the IoT Hub service. It is transport-agnostic, meaning it works the same way over AMQP, MQTT and HTTP.

Client

IoT Hub device client used to connect a device with an Azure IoT hub.

Users of the SDK should call one of the factory methods, fromConnectionString or fromSharedAccessSignature to create an IoT Hub device client.

DeviceMethodRequest

Represents the data passed in from the service to the device when a device method is called from the cloud. An instance of this class is passed to the callback registered via onDeviceMethod(string, (request: DeviceMethodRequest, response: DeviceMethodResponse) => void).

DeviceMethodResponse

a DeviceMethodResponse object is provided to the user with each DeviceMethodRequest allowing the user to construct and send a well-formatted response back to the service for each device method call. An instance of this class is passed as the second parameter to the callback registered via onDeviceMethod(string, (request: DeviceMethodRequest, response: DeviceMethodResponse) => void).

IotEdgeAuthenticationProvider

Provides an AuthenticationProvider implementation that delegates token generation to iotedged. This implementation is meant to be used when using the module client with Azure IoT Edge.

This type inherits from SharedAccessKeyAuthenticationProvider and is functionally identical to that type except for the token generation part which it overrides by implementing the _sign method.

ModuleClient

IoT Hub device client used to connect a device with an Azure IoT hub.

Users of the SDK should call one of the factory methods, fromConnectionString or fromSharedAccessSignature to create an IoT Hub device client.

SharedAccessKeyAuthenticationProvider

Provides an AuthenticationProvider object that can be created simply with a connection string and is then used by the device client and transports to authenticate with the Azure IoT hub instance.

The SharedAccessKeyAuthenticationProvider object takes care of creating shared access signature tokens on a regular cadence and emits the newTokenAvailable event for the transports to renew their credentials with the Azure IoT hub instance and stay connected.

SharedAccessSignatureAuthenticationProvider

Provides an AuthenticationProvider object that can be created simply with a shared access signature and is then used by the device client and transports to authenticate with the Azure IoT hub instance.

The SharedAccessSignatureAuthenticationProvider object does not renew the shared access signature token automatically, so the user needs to feed non-expired shared access signature tokens to it using the updateSharedAccessSignature method. For each call to this method, the SharedAccessSignatureAuthenticationProvider will emit a newTokenAvailable event that transports will use to authenticate with the Azure IoT hub instance.

Twin

A Device Twin is document describing the state of a device that is stored by an Azure IoT hub and is available even if the device is offline. It is built around 3 sections:

  • Tags: key/value pairs only accessible from the service side
  • Desired Properties: updated by a service and received by the device
  • Reported Properties: updated by the device and received by the service.

Note that although it is a possibility, desired and reported properties do not have to match and that the logic to sync these two collections, if necessary, is left to the user of the SDK.

For more information see Understanding Device Twins.

X509AuthenticationProvider

Provides an AuthenticationProvider object that can be created simply with an X509 certificate and key and is then used by the device client and transports to authenticate with the Azure IoT hub instance.

Unlike the SharedAccessSignatureAuthenticationProvider and SharedAccessKeyAuthenticationProvider objects, the X509AuthenticationProvider does not emit a newTokenAvailable event since there are no token involved in X509 authentication. The transports will get the credentials using the getDeviceCredentials method.

Interfaces

AmqpTransportOptions

Options which are specific to the AMQP transport.

This is passed into setOptions as a property named http inside of an DeviceClientOptions object.

See

DeviceClientOptions

Options for the Client object. Passed into the setOptions function.

Example

 var options = {
   cert: myX509Certificate,
   key: myX509Key,
   http: {
     receivePolicy: {
       interval: 10
     }
   }
 }
 client.setOptions(options, callback);
DeviceTransport
HttpReceiverOptions

Options structure used to configure how often the HTTP receiver polls for messages. Each of these options is mutually exclusive, except for the drain boolean. Only one interval, at, cron or manualPolling shall be present in the options structure.

This is configured by calling setOptions with this as a property named receivePolicy inside of an HttpTransportOptions object which is inside of an DeviceClientOptions object.

See

HttpTransportOptions

Options structure for passing optional configuration parameters into the Http Transport.

This is passed into setOptions as a property named http inside of an DeviceClientOptions object.

See

MqttTransportOptions

Options which are specific to the MQTT transport

This is passed into setOptions as a property named mqtt inside of an DeviceClientOptions object.

TwinProperties

Contains the desired and reported properties for the Twin.

Type Aliases

BufferConvertible

Functions

getUserAgentString(NoErrorCallback<string>)
getUserAgentString()
getUserAgentString(string, NoErrorCallback<string>)
getUserAgentString(string)

Function Details

getUserAgentString(NoErrorCallback<string>)

function getUserAgentString(done: NoErrorCallback<string>)

Parameters

done

NoErrorCallback<string>

getUserAgentString()

function getUserAgentString(): Promise<string>

Returns

Promise<string>

getUserAgentString(string, NoErrorCallback<string>)

function getUserAgentString(productInfo: string, done: NoErrorCallback<string>)

Parameters

productInfo

string

done

NoErrorCallback<string>

getUserAgentString(string)

function getUserAgentString(productInfo: string): Promise<string>

Parameters

productInfo

string

Returns

Promise<string>