azure-iot-device package

Classes

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, DoubleValueCallback<DeviceMethodRequest, DeviceMethodResponse>).

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, DoubleValueCallback<DeviceMethodRequest, DeviceMethodResponse>).

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.

@fires Twin#properties.desired[.path]

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

DeviceMethodExchange
MethodParams
MethodResult
AmqpTransportOptions

Options which are specific to the AMQP transport. This is passed into <xref:Client.setOptions> as a property named http inside of an <xref:DeviceClientOptions> object.

DeviceClientOptions

Options for the Client object. Passed into the <xref:Client.setOptions> function.

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 <xref:Client.setOptions> with this as a property named receivePolicy inside of an <xref:HttpTransportOptions> object which is inside of an <xref:DeviceClientOptions> object.

HttpTransportOptions

Options structure for passing optional configuration parameters into the Http Transport. This is passed into <xref:Client.setOptions> as a property named http inside of an <xref:DeviceClientOptions> object.

MqttTransportOptions

Options which are specific to the MQTT transport This is passed into <xref:Client.setOptions> as a property named mqtt inside of an <xref:DeviceClientOptions> object.

BlobUpload
DeviceTransport
TwinProperties

Contains the desired and reported properties for the Twin.

Type Aliases

MethodCallback
TransportCtor

Functions

createWithSharedAccessKey(string, string, string)

Creates a valid connection string for a device using symmetric key authentication.

createWithX509Certificate(string, string)

Creates a valid connection string for a device using x509 certificate authentication.

parse(string)

Parses a string in the format of a Shared Access Signature token and returns a <xref:SharedAccessSignature>.

createDeviceMethodExchange(DeviceMethodRequest, DeviceMethodResponse)
create(string, string, string, string | number)

Creates a shared access signature token to authenticate a device connection with an Azure IoT hub.

parse(string)

Parses a string in the format of a Shared Access Signature token and returns a <xref:SharedAccessSignature>.

getUserAgentString(NoErrorCallback<string>)

Function Details

createWithSharedAccessKey(string, string, string)

Creates a valid connection string for a device using symmetric key authentication.

function createWithSharedAccessKey(hostName: string, deviceId: string, symmetricKey: string)

Parameters

hostName
string

Hostname of the Azure IoT hub.

deviceId
string

Unique device identifier.

symmetricKey
string

Symmetric key used to generate the <xref:SharedAccessSignature> that authenticate the connection.

Returns

string

createWithX509Certificate(string, string)

Creates a valid connection string for a device using x509 certificate authentication.

function createWithX509Certificate(hostName: string, deviceId: string)

Parameters

hostName
string

Hostname of the Azure IoT hub.

deviceId
string

Unique device identifier.

Returns

string

parse(string)

Parses a string in the format of a Shared Access Signature token and returns a <xref:SharedAccessSignature>.

function parse(source: string)

Parameters

source
string

A shared access signature string.

Returns

SharedAccessSignature

createDeviceMethodExchange(DeviceMethodRequest, DeviceMethodResponse)

function createDeviceMethodExchange(request: DeviceMethodRequest, response: DeviceMethodResponse)

Parameters

Returns

create(string, string, string, string | number)

Creates a shared access signature token to authenticate a device connection with an Azure IoT hub.

function create(host: string, deviceId: string, key: string, expiry: string | number)

Parameters

host
string

Hostname of the Azure IoT hub.

deviceId
string

Unique device identifier as it exists in the device registry.

key
string

Symmetric key to use to create shared access signature tokens.

expiry
string | number

Expiry time for the token that will be created.

Returns

SharedAccessSignature

parse(string)

Parses a string in the format of a Shared Access Signature token and returns a <xref:SharedAccessSignature>.

function parse(source: string)

Parameters

source
string

A shared access signature string.

Returns

SharedAccessSignature

getUserAgentString(NoErrorCallback<string>)

function getUserAgentString(done?: NoErrorCallback<string>)

Parameters

done
NoErrorCallback<string>

Returns

Promise<string> | void