Created
April 21, 2020 06:15
-
-
Save ridomin/77aa86fe8a7d36389700ea653a8f2362 to your computer and use it in GitHub Desktop.
create-aziothub-device.js
This file contains hidden or 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
'use strict'; | |
const iothub = require('azure-iothub') | |
const registry = iothub.Registry.fromConnectionString(process.env.IOTHUB_CONNECTION_STRING) | |
const device = {deviceId: 'ppr-bb-' + new Date().getTime(), status: 'enabled'} | |
registry.create(device, (err) => { | |
if (err) throw(err) | |
console.log(`Device ${device.deviceId} created`) | |
registry.get(device.deviceId, (err, devInfo) => { | |
if (err) throw(err) | |
const connectionString = `HostName=${registry._restApiClient._config.host};` + | |
`DeviceId=${devInfo.deviceId};` + | |
`SharedAccessKey=${devInfo.authentication.SymmetricKey.primaryKey}` | |
console.log(connectionString) | |
}) | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment