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

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
coderbyheart committed Jun 30, 2020
1 parent 0276007 commit a18d3fa
Show file tree
Hide file tree
Showing 3 changed files with 124 additions and 69 deletions.
27 changes: 18 additions & 9 deletions cli/device/connect.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { promises as fs } from 'fs'
import { thingShadow } from 'aws-iot-device-sdk'
import { mqtt, io, iot } from 'aws-crt'
import { deviceFileLocations } from '../jitp/deviceFileLocations'
import * as chalk from 'chalk'
import { uiServer, WebSocketConnection } from '@bifravst/device-ui-server'
Expand All @@ -14,6 +14,8 @@ const defaultConfig = {
acct: 1, // Accelerometer threshold: minimal absolute value for and accelerometer reading to be considered movement.
} as const

io.enable_logging(io.LogLevel.DEBUG)

/**
* Connect to the AWS IoT broker using a generated device certificate
*/
Expand Down Expand Up @@ -96,14 +98,21 @@ export const connect = async ({
console.timeLog(note)
}, 5000)

const connection = new thingShadow({
privateKey: deviceFiles.key,
clientCert: deviceFiles.certWithCA,
caCert,
clientId: deviceId,
host: endpoint,
region: endpoint.split('.')[2],
})
const config_builder = iot.AwsIotMqttConnectionConfigBuilder.new_mtls_builder_from_path(
deviceFiles.certWithCA,
deviceFiles.key,
)
.with_certificate_authority_from_path(undefined, caCert)
.with_clean_session(true)
.with_client_id(deviceId)
.with_endpoint(endpoint)

const config = config_builder.build()
const client = new mqtt.MqttClient(new io.ClientBootstrap())
const connection = client.new_connection(config)
await connection.connect()

// FIXME: Implement shadow, see https://github.com/aws/aws-iot-device-sdk-python-v2/blob/master/samples/shadow.py

let wsConnection: WebSocketConnection

Expand Down
163 changes: 105 additions & 58 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
"@bifravst/device-ui-server": "^1.3.2",
"@bifravst/random-words": "^4.2.0",
"ajv": "^6.12.2",
"aws-iot-device-sdk": "^2.2.6",
"aws-iot-device-sdk-v2": "^1.2.1",
"aws-sdk": "^2.707.0",
"backoff": "^2.5.0",
"chalk": "^4.1.0",
Expand Down Expand Up @@ -62,7 +62,6 @@
"@bifravst/package-layered-lambdas": "^3.10.0",
"@commitlint/cli": "^9.0.1",
"@commitlint/config-angular": "^9.0.1",
"@types/aws-iot-device-sdk": "^2.2.2",
"@types/aws-lambda": "^8.10.57",
"@types/aws-sdk": "^2.7.0",
"@types/backoff": "^2.5.1",
Expand Down

0 comments on commit a18d3fa

Please sign in to comment.