File tree Expand file tree Collapse file tree 3 files changed +24
-16
lines changed Expand file tree Collapse file tree 3 files changed +24
-16
lines changed Original file line number Diff line number Diff line change 5
5
} from '@aws-sdk/client-iot'
6
6
import { GetParameterCommand , SSMClient } from '@aws-sdk/client-ssm'
7
7
import chalk from 'chalk'
8
+ import { randomUUID } from 'node:crypto'
8
9
import { STACK_NAME } from '../../cdk/stacks/stackConfig.js'
9
10
import {
10
11
updateSettings ,
@@ -22,6 +23,8 @@ export const createFakeNrfCloudHealthCheckDevice = ({
22
23
} ) : CommandDefinition => ( {
23
24
command : 'create-fake-nrfcloud-health-check-device' ,
24
25
action : async ( ) => {
26
+ const deviceId = `health-check-${ randomUUID ( ) } `
27
+
25
28
const fakeTenantParameter = `/${ STACK_NAME } /fakeTenant`
26
29
const tenantId = (
27
30
await ssm . send (
@@ -62,7 +65,7 @@ export const createFakeNrfCloudHealthCheckDevice = ({
62
65
const settings : Settings = {
63
66
healthCheckClientCert : credentials . certificatePem ,
64
67
healthCheckPrivateKey : pk ,
65
- healthCheckClientId : 'health-check' ,
68
+ healthCheckClientId : deviceId ,
66
69
healthCheckModel : 'PCA20035+solar' ,
67
70
healthCheckFingerPrint : '29a.ch3ckr' ,
68
71
}
Original file line number Diff line number Diff line change 1
1
import { SSMClient } from '@aws-sdk/client-ssm'
2
2
import type { Environment } from 'aws-cdk-lib'
3
3
import chalk from 'chalk'
4
+ import { randomUUID } from 'node:crypto'
4
5
import { readFile } from 'node:fs/promises'
5
6
import path from 'node:path'
6
7
import { apiClient } from '../../nrfcloud/apiClient.js'
@@ -44,7 +45,7 @@ export const createHealthCheckDevice = ({
44
45
chalk . blue ( caCertificates . certificate ) ,
45
46
)
46
47
47
- const deviceId = `health-check`
48
+ const deviceId = `health-check- ${ randomUUID ( ) } `
48
49
console . log ( chalk . yellow ( 'Device ID:' ) , chalk . blue ( deviceId ) )
49
50
50
51
// Device private key
@@ -114,7 +115,7 @@ export const createHealthCheckDevice = ({
114
115
path . join ( deviceCertificates . privateKey ) ,
115
116
'utf-8' ,
116
117
) ,
117
- healthCheckClientId : 'health-check' ,
118
+ healthCheckClientId : deviceId ,
118
119
healthCheckModel : 'PCA20035+solar' ,
119
120
healthCheckFingerPrint : '29a.ch3ckr' ,
120
121
}
Original file line number Diff line number Diff line change @@ -91,22 +91,26 @@ const publishDeviceMessage =
91
91
key : devicePrivateKey ,
92
92
cert : deviceCert ,
93
93
ca : amazonRootCA1 ,
94
+ connectTimeout : 5000 ,
94
95
} )
95
96
96
- mqttClient . on ( 'connect' , ( ) => {
97
- const topic = `${ nrfCloudSettings . mqttTopicPrefix } m/d/${ deviceId } /d2c`
98
- log . debug ( 'mqtt publish' , { mqttMessage : message , topic } )
99
- mqttClient . publish ( topic , JSON . stringify ( message ) , ( error ) => {
100
- if ( error ) return reject ( error )
101
- mqttClient . end ( )
102
- return resolve ( )
97
+ mqttClient
98
+ . on ( 'connect' , ( ) => {
99
+ const topic = `${ nrfCloudSettings . mqttTopicPrefix } m/d/${ deviceId } /d2c`
100
+ log . debug ( 'mqtt publish' , { mqttMessage : message , topic } )
101
+ mqttClient . publish ( topic , JSON . stringify ( message ) , ( error ) => {
102
+ if ( error !== undefined ) return reject ( error )
103
+ mqttClient . end ( )
104
+ return resolve ( )
105
+ } )
106
+ } )
107
+ . on ( 'error' , ( error ) => {
108
+ log . error ( `mqtt error` , { error } )
109
+ reject ( error )
110
+ } )
111
+ . on ( 'reconnect' , ( ) => {
112
+ log . debug ( `mqtt reconnect` )
103
113
} )
104
- } )
105
-
106
- mqttClient . on ( 'error' , ( error ) => {
107
- log . error ( `mqtt error` , { error } )
108
- reject ( error )
109
- } )
110
114
111
115
await promise
112
116
}
You can’t perform that action at this time.
0 commit comments