Azure IoT Digital Twins Device SDK
PREVIEW - WILL LIKELY HAVE BREAKING CHANGES
Features
Use the Azure IoT Digital Twins Device SDK to:
- Register multiple interfaces that a device implements.
- Send Telemetry data to Azure IoT Hub.
- Report property changes to Azure IoT Hub.
- Receive changes to writable properties.
- Handle synchronous and asynchronous commands from IoTHub.
Prerequisites
You need to install the Node.js JavaScript runtime environment to run the Azure IoT JavaScript client SDK on your platform. To check if Node.js supports your platform (OS), verify that an install package is available on the Node.js download page.
npm is a command-line package manager that is installed with Node.js is installed, and will be used to install Azure IoT node.js client side SDK.
Installation
To get the latest version you need to install this package as well as the device client and the MQTT transport that support the digital twin client:
npm install azure-iot-digitaltwins-device@pnp-previewnpm install azure-iot-device@pnp-previewnpm install azure-iot-device-mqtt@pnp-preview
Getting started
You can use the code below to send telemetry to IoT Hub.
Note that for this sample to work, you will need to setup your IoT hub and provision your device and get its credentials. In the code, replace '[IoT Hub device connection string]' with the device credentials created in the IoT Hub.
const DigitalTwinClient = DigitalTwinClient;const DeviceClient = Client;const Mqtt = Mqtt; const EnvironmentalSensor = EnvironmentalSensor; const propertyUpdateHandler = { console; interfaceInstancepropertyName ;}; const commandHandler = { console; response ;}; const environmentalSensor = 'environmentalSensor' propertyUpdateHandler commandHandler; const deviceClient = DeviceClient; const capabilityModel = 'urn:azureiot:samplemodel:1'; { const digitalTwinClient = capabilityModel deviceClient; digitalTwinClient; await digitalTwinClient; await environmentalSensortemp; await environmentalSensorhumid; console;}; ;