@@ -90,6 +90,10 @@ export default class BoardConfiguration {
9090 partialMessage = '' ;
9191 this . daemon . writeSerial ( board . port , 'y\n' ) ;
9292 }
93+ if ( partialMessage . indexOf ( 'Please enter the thing id:' ) !== - 1 ) {
94+ partialMessage = '' ;
95+ this . daemon . writeSerial ( board . port , `${ board . deviceId } \n` ) ;
96+ }
9397
9498 const begin = partialMessage . indexOf ( '-----BEGIN CERTIFICATE REQUEST-----' ) ;
9599 const end = partialMessage . indexOf ( '-----END CERTIFICATE REQUEST-----' ) ;
@@ -121,13 +125,13 @@ export default class BoardConfiguration {
121125 const notBefore = new Date ( compressedCert . not_before ) ;
122126 const notAfter = new Date ( compressedCert . not_after ) ;
123127 // eslint-disable-next-line prefer-template
124- const answers = board . deviceId + '\n' +
125- notBefore . getUTCFullYear ( ) + '\n' +
128+ const answers = notBefore . getUTCFullYear ( ) + '\n' +
126129 ( notBefore . getUTCMonth ( ) + 1 ) + '\n' +
127130 notBefore . getUTCDate ( ) + '\n' +
128131 notBefore . getUTCHours ( ) + '\n' +
129132 ( notAfter . getUTCFullYear ( ) - notBefore . getUTCFullYear ( ) ) + '\n' +
130133 compressedCert . serial + '\n' +
134+ compressedCert . authority_key_identifier + '\n' +
131135 compressedCert . signature + '\n' ;
132136 this . daemon . writeSerial ( board . port , answers ) ;
133137 } ) ;
@@ -168,7 +172,7 @@ export default class BoardConfiguration {
168172 * @param {Object } board contains the board data
169173 * @param {function } createDeviceCb used to create the device associated to the user
170174 */
171- configure ( compiledSketch , board , createDeviceCb ) {
175+ configure ( compiledSketch , board , createDeviceCb , generateCertificateCb ) {
172176 this . daemon . initUpload ( ) ;
173177 this . configuring . next ( { status : this . CONFIGURE_IN_PROGRESS , msg : 'Uploading provisioning sketch...' } ) ;
174178 if ( ! this . daemon . channelOpen . getValue ( ) ) {
@@ -196,7 +200,7 @@ export default class BoardConfiguration {
196200 this . daemon . uploadingDone . subscribe ( ( ) => {
197201 this . configuring . next ( {
198202 status : this . CONFIGURE_IN_PROGRESS ,
199- msg : 'Provisioning sketch uploaded successfully. Opening serial monitor ...'
203+ msg : 'Provisioning sketch uploaded successfully. Creating device ...'
200204 } ) ;
201205 this . daemon . serialMonitorOpened . pipe ( takeUntil ( this . daemon . serialMonitorOpened . pipe ( filter ( open => open ) ) ) )
202206 . subscribe ( ( ) => {
@@ -208,14 +212,14 @@ export default class BoardConfiguration {
208212 . then ( csr => {
209213 this . configuring . next ( {
210214 status : this . CONFIGURE_IN_PROGRESS ,
211- msg : 'CSR generated. Creating device ...'
215+ msg : 'CSR generated. Generating certificate ...'
212216 } ) ;
213- return createDeviceCb ( csr ) ;
217+ return generateCertificateCb ( csr ) ;
214218 } )
215219 . then ( data => {
216220 this . configuring . next ( {
217221 status : this . CONFIGURE_IN_PROGRESS ,
218- msg : 'Device created . Storing certificate...'
222+ msg : 'Certificate generated . Storing certificate...'
219223 } ) ;
220224 return this . storeCertificate ( data . compressed , board ) ;
221225 } )
@@ -234,7 +238,15 @@ export default class BoardConfiguration {
234238 err : error . toString ( )
235239 } ) ;
236240 } ) ;
237- this . daemon . openSerialMonitor ( board . port , BAUDRATE ) ;
241+ createDeviceCb ( )
242+ . then ( data => {
243+ this . configuring . next ( {
244+ status : this . CONFIGURE_IN_PROGRESS ,
245+ msg : 'Device created. Opening serial monitor...'
246+ } ) ;
247+ board . deviceId = data . id ; // eslint-disable-line no-param-reassign
248+ this . daemon . openSerialMonitor ( board . port , BAUDRATE ) ;
249+ } ) ;
238250 } ) ;
239251
240252 this . daemon . uploadingError . subscribe ( upload => {
0 commit comments