Created
September 22, 2017 18:52
-
-
Save vspedr/e4c6932bee6a19ab868bc1c272edd287 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// based on: https://docs.microsoft.com/en-us/azure/iot-hub/iot-hub-node-node-getstarted#create-a-device-identity | |
const iothub = require('azure-iothub'); | |
const connectionString = '{iothub connection string}'; | |
const registry = iothub.Registry.fromConnectionString(connectionString); | |
const device = { | |
deviceId: 'myFirstNodeDevice' | |
}; | |
registry.create(device, function(err, deviceInfo, res) { | |
if (err) { | |
registry.get(device.deviceId, printDeviceInfo); | |
} | |
if (deviceInfo) { | |
printDeviceInfo(err, deviceInfo, res); | |
} | |
}); | |
const printDeviceInfo = (err, deviceInfo, res) => { | |
if (err) console.error(err); | |
if (deviceInfo) { | |
console.log('Device ID: ' + deviceInfo.deviceId); | |
console.log('Device key: ' + deviceInfo.authentication.symmetricKey.primaryKey); | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment