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 55} from '@aws-sdk/client-iot'
66import { GetParameterCommand , SSMClient } from '@aws-sdk/client-ssm'
77import chalk from 'chalk'
8+ import { randomUUID } from 'node:crypto'
89import { STACK_NAME } from '../../cdk/stacks/stackConfig.js'
910import {
1011 updateSettings ,
@@ -22,6 +23,8 @@ export const createFakeNrfCloudHealthCheckDevice = ({
2223} ) : CommandDefinition => ( {
2324 command : 'create-fake-nrfcloud-health-check-device' ,
2425 action : async ( ) => {
26+ const deviceId = `health-check-${ randomUUID ( ) } `
27+
2528 const fakeTenantParameter = `/${ STACK_NAME } /fakeTenant`
2629 const tenantId = (
2730 await ssm . send (
@@ -62,7 +65,7 @@ export const createFakeNrfCloudHealthCheckDevice = ({
6265 const settings : Settings = {
6366 healthCheckClientCert : credentials . certificatePem ,
6467 healthCheckPrivateKey : pk ,
65- healthCheckClientId : 'health-check' ,
68+ healthCheckClientId : deviceId ,
6669 healthCheckModel : 'PCA20035+solar' ,
6770 healthCheckFingerPrint : '29a.ch3ckr' ,
6871 }
Original file line number Diff line number Diff line change 11import { SSMClient } from '@aws-sdk/client-ssm'
22import type { Environment } from 'aws-cdk-lib'
33import chalk from 'chalk'
4+ import { randomUUID } from 'node:crypto'
45import { readFile } from 'node:fs/promises'
56import path from 'node:path'
67import { apiClient } from '../../nrfcloud/apiClient.js'
@@ -44,7 +45,7 @@ export const createHealthCheckDevice = ({
4445 chalk . blue ( caCertificates . certificate ) ,
4546 )
4647
47- const deviceId = `health-check`
48+ const deviceId = `health-check- ${ randomUUID ( ) } `
4849 console . log ( chalk . yellow ( 'Device ID:' ) , chalk . blue ( deviceId ) )
4950
5051 // Device private key
@@ -114,7 +115,7 @@ export const createHealthCheckDevice = ({
114115 path . join ( deviceCertificates . privateKey ) ,
115116 'utf-8' ,
116117 ) ,
117- healthCheckClientId : 'health-check' ,
118+ healthCheckClientId : deviceId ,
118119 healthCheckModel : 'PCA20035+solar' ,
119120 healthCheckFingerPrint : '29a.ch3ckr' ,
120121 }
Original file line number Diff line number Diff line change @@ -91,22 +91,26 @@ const publishDeviceMessage =
9191 key : devicePrivateKey ,
9292 cert : deviceCert ,
9393 ca : amazonRootCA1 ,
94+ connectTimeout : 5000 ,
9495 } )
9596
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` )
103113 } )
104- } )
105-
106- mqttClient . on ( 'error' , ( error ) => {
107- log . error ( `mqtt error` , { error } )
108- reject ( error )
109- } )
110114
111115 await promise
112116 }
You can’t perform that action at this time.
0 commit comments