@@ -398,7 +398,17 @@ bool pointperfectProvisionDevice()
398
398
399
399
strcpy (settings.pointPerfectClientID , (const char *)((*jsonZtp)[" clientId" ]));
400
400
strcpy (settings.pointPerfectBrokerHost , (const char *)((*jsonZtp)[" brokerHost" ]));
401
- strcpy (settings.pointPerfectLBandTopic , (const char *)((*jsonZtp)[" subscriptions" ][0 ][" path" ]));
401
+
402
+ // Note: from the ZTP documentation:
403
+ // ["subscriptions"][0] will contain the key distribution topic
404
+ // But, assuming the key distribution topic is always ["subscriptions"][0] is potentially brittle
405
+ // It is safer to check the "description" contains "key distribution topic"
406
+ int subscription =
407
+ findZtpJSONEntry (" subscriptions" , " description" , " key distribution topic" , jsonZtp);
408
+ if (subscription >= 0 )
409
+ strncpy (settings.pointPerfectLBandTopic ,
410
+ (const char *)((*jsonZtp)[" subscriptions" ][subscription][" path" ]),
411
+ sizeof (settings.pointPerfectLBandTopic ));
402
412
403
413
strcpy (settings.pointPerfectCurrentKey ,
404
414
(const char *)((*jsonZtp)[" dynamickeys" ][" current" ][" value" ]));
@@ -451,6 +461,26 @@ bool pointperfectProvisionDevice()
451
461
#endif // COMPILE_WIFI
452
462
}
453
463
464
+ // Find thing3 in (*jsonZtp)[thing1][n][thing2]. Return n on success. Return -1 on error / not found.
465
+ int findZtpJSONEntry (const char *thing1, const char *thing2, const char *thing3, DynamicJsonDocument *jsonZtp)
466
+ {
467
+ if (!jsonZtp)
468
+ return (-1 );
469
+
470
+ int i = (*jsonZtp)[thing1].size ();
471
+
472
+ if (i == 0 )
473
+ return (-1 );
474
+
475
+ for (int j = 0 ; j < i; j++)
476
+ if (strstr ((const char *)(*jsonZtp)[thing1][j][thing2], thing3) != nullptr )
477
+ {
478
+ return j;
479
+ }
480
+
481
+ return (-1 );
482
+ }
483
+
454
484
// Check certificate and privatekey for valid formatting
455
485
// Return false if improperly formatted
456
486
bool checkCertificates ()
@@ -618,8 +648,6 @@ bool pointperfectUpdateKeys()
618
648
// Successful connection
619
649
systemPrintln (" MQTT connected" );
620
650
621
- // Originally the provisioning process reported the '/pp/key/Lb' channel which fails to respond with
622
- // keys. Looks like they fixed it to /pp/ubx/0236/Lb.
623
651
mqttClient.subscribe (settings.pointPerfectLBandTopic );
624
652
}
625
653
else
0 commit comments