
Security News
Deno 2.2 Improves Dependency Management and Expands Node.js Compatibility
Deno 2.2 enhances Node.js compatibility, improves dependency management, adds OpenTelemetry support, and expands linting and task automation for developers.
azure-iot-digitaltwins-device
Advanced tools
PREVIEW - WILL LIKELY HAVE BREAKING CHANGES
Use the Azure IoT Digital Twins Device SDK to:
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.
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-preview
npm install azure-iot-device@pnp-preview
npm install azure-iot-device-mqtt@pnp-preview
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 = require('azure-iot-digitaltwins-device').DigitalTwinClient;
const DeviceClient = require('azure-iot-device').Client;
const Mqtt = require('azure-iot-device-mqtt').Mqtt;
const EnvironmentalSensor = require('./environmentalinterface').EnvironmentalSensor;
const propertyUpdateHandler = (interfaceInstance, propertyName, reportedValue, desiredValue, version) => {
console.log('Received an update for ' + propertyName + ': ' + JSON.stringify(desiredValue));
interfaceInstance[propertyName].report(desiredValue, {
code: 200,
description: 'helpful descriptive text',
version: version
})
.then(() => console.log('updated the property'))
.catch(() => console.log('failed to update the property'));
};
const commandHandler = (request, response) => {
console.log('received command: ' + request.commandName + ' for interfaceInstance: ' + request.interfaceInstanceName);
response.acknowledge(200, 'helpful response text')
.then(() => console.log('acknowledgement succeeded.'))
.catch(() => console.log('acknowledgement failed'));
};
const environmentalSensor = new EnvironmentalSensor('environmentalSensor', propertyUpdateHandler, commandHandler);
const deviceClient = DeviceClient.fromConnectionString(process.argv[2], Mqtt);
const capabilityModel = 'urn:azureiot:samplemodel:1';
async function main() {
const digitalTwinClient = new DigitalTwinClient(capabilityModel, deviceClient);
digitalTwinClient.addInterfaceInstance(environmentalSensor);
await digitalTwinClient.register();
await environmentalSensor.temp.send(65.5);
await environmentalSensor.humid.send(12.2);
console.log('Done sending telemetry.');
};
main();
FAQs
Azure IoT Digital Twin Device Client
The npm package azure-iot-digitaltwins-device receives a total of 1 weekly downloads. As such, azure-iot-digitaltwins-device popularity was classified as not popular.
We found that azure-iot-digitaltwins-device demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 3 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Deno 2.2 enhances Node.js compatibility, improves dependency management, adds OpenTelemetry support, and expands linting and task automation for developers.
Security News
React's CRA deprecation announcement sparked community criticism over framework recommendations, leading to quick updates acknowledging build tools like Vite as valid alternatives.
Security News
Ransomware payment rates hit an all-time low in 2024 as law enforcement crackdowns, stronger defenses, and shifting policies make attacks riskier and less profitable.