Skip to content
This repository has been archived by the owner on Feb 17, 2021. It is now read-only.

Commit

Permalink
feat(iot): connect
Browse files Browse the repository at this point in the history
  • Loading branch information
coderbyheart committed Nov 29, 2019
1 parent 955f288 commit a3c6005
Showing 1 changed file with 22 additions and 1 deletion.
23 changes: 22 additions & 1 deletion cli/commands/connect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,28 @@ export const connectCommand = ({

await fs.writeFile(deviceFiles.registration, JSON.stringify(registration, null, 2), 'utf-8')
} finally {
console.log(`FIXME: Connect to ${iotHub}`)

console.log(chalk.magenta(`Connecting to`), chalk.yellow(`${iotHub}`))

const client = connect({
host: iotHub,
port: 8883,
key: deviceKey,
cert: deviceCert,
rejectUnauthorized: true,
clientId: deviceId,
protocol: 'mqtts',
username: `${iotHub}/${deviceId}/?api-version=2018-06-30`,
version: 4,
})

client.on('connect', () => {
console.log(chalk.green('Connected:'), chalk.blueBright(deviceId))
})

client.on('error', err => {
console.error(chalk.red(err.message))
})
}
},
help: 'Connect to the IoT Hub',
Expand Down

0 comments on commit a3c6005

Please sign in to comment.