Skip to content

Commit 4e4d650

Browse files
committed
Fix device ID and token selection
1 parent c1afa45 commit 4e4d650

File tree

2 files changed

+28
-19
lines changed

2 files changed

+28
-19
lines changed

Firmware/RTK_Surveyor/System.ino

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,7 @@ void startBluetooth()
1414

1515
sprintf(deviceName, "%s %s-%02X%02X", platformPrefix, stateName, unitMACAddress[4], unitMACAddress[5]); //Base mode
1616

17-
//if (SerialBT.begin(deviceName, false, settings.sppRxQueueSize, settings.sppTxQueueSize) == false) //localName, isMaster, rxBufferSize, txBufferSize
18-
if (SerialBT.begin(deviceName, false) == false) //localName, isMaster
17+
if (SerialBT.begin(deviceName, false, settings.sppRxQueueSize, settings.sppTxQueueSize) == false) //localName, isMaster, rxBufferSize, txBufferSize
1918
{
2019
Serial.println(F("An error occurred initializing Bluetooth"));
2120

Firmware/RTK_Surveyor/menuPP.ino

Lines changed: 27 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ void menuPointPerfect()
1010
Serial.println();
1111
Serial.println(F("Menu: PointPerfect Corrections"));
1212

13-
char hardwareID[11];
14-
sprintf(hardwareID, "%02X%02X%02X%02X%02X", unitMACAddress[0], unitMACAddress[1], unitMACAddress[2], unitMACAddress[3], unitMACAddress[4]); //Get ready for JSON
13+
char hardwareID[13];
14+
sprintf(hardwareID, "%02X%02X%02X%02X%02X%02X", unitMACAddress[0], unitMACAddress[1], unitMACAddress[2], unitMACAddress[3], unitMACAddress[4], unitMACAddress[5]); //Get ready for JSON
1515
Serial.printf("Device ID: %s\n\r", hardwareID);
1616

1717
Serial.print("Days until keys expire: ");
@@ -37,7 +37,7 @@ void menuPointPerfect()
3737
if (settings.autoKeyRenewal == true) Serial.println(F("Enabled"));
3838
else Serial.println(F("Disabled"));
3939

40-
if (strlen(settings.pointPerfectClientID) == 0 || strlen(settings.pointPerfectLBandTopic) == 0)
40+
if (strlen(settings.pointPerfectCurrentKey) == 0 || strlen(settings.pointPerfectLBandTopic) == 0)
4141
Serial.println(F("5) Provision Device"));
4242
else
4343
Serial.println(F("5) Update Keys"));
@@ -90,7 +90,7 @@ void menuPointPerfect()
9090
//Check if we have certificates
9191
char fileName[80];
9292
sprintf(fileName, "/%s_%s_%d.txt", platformFilePrefix, "certificate", profileNumber);
93-
if(LittleFS.exists(fileName) == false)
93+
if (LittleFS.exists(fileName) == false)
9494
{
9595
provisionDevice(); //Connect to ThingStream API and get keys
9696
}
@@ -274,30 +274,40 @@ bool provisionDevice()
274274
WiFiClientSecure client;
275275
client.setCACert(AWS_PUBLIC_CERT);
276276

277+
char hardwareID[13];
278+
sprintf(hardwareID, "%02X%02X%02X%02X%02X%02X", unitMACAddress[0], unitMACAddress[1], unitMACAddress[2], unitMACAddress[3], unitMACAddress[4], unitMACAddress[5]); //Get ready for JSON
279+
277280
#ifdef WHITELISTED_ID
278-
//Override device ID with testing ID
279-
for (int x = 0 ; x < 5 ; x++)
280-
unitMACAddress[x] = whitelistID[x];
281+
//Override ID with testing ID
282+
sprintf(hardwareID, "%02X%02X%02X%02X%02X%02X", whitelistID[0], whitelistID[1], whitelistID[2], whitelistID[3], whitelistID[4], whitelistID[5]);
281283
#endif
282284

283-
char hardwareID[11];
284-
sprintf(hardwareID, "%02X%02X%02X%02X%02X", unitMACAddress[0], unitMACAddress[1], unitMACAddress[2], unitMACAddress[3], unitMACAddress[4]); //Get ready for JSON
285-
286285
char givenName[50];
287286
sprintf(givenName, "SparkFun RTK %s v%d.%d - %s", platformPrefix, FIRMWARE_VERSION_MAJOR, FIRMWARE_VERSION_MINOR, hardwareID); //Get ready for JSON
288287

289288
StaticJsonDocument<256> pointPerfectAPIPost;
290289

291-
//Convert uint8_t array into string with dashes in spots
292-
//We must assume u-blox will not change the position of their dashes or length of their token
290+
//Determine if we use the SparkFun token or custom token
293291
char tokenString[37] = "\0";
294-
for (int x = 0 ; x < sizeof(pointPerfectTokenArray) ; x++)
292+
if (strlen(settings.pointPerfectDeviceProfileToken) == 0)
295293
{
296-
char temp[3];
297-
sprintf(temp, "%02x", pointPerfectTokenArray[x]);
298-
strcat(tokenString, temp);
299-
if (x == 3 || x == 5 || x == 7 || x == 9) strcat(tokenString, "-");
294+
//Convert uint8_t array into string with dashes in spots
295+
//We must assume u-blox will not change the position of their dashes or length of their token
296+
for (int x = 0 ; x < sizeof(pointPerfectTokenArray) ; x++)
297+
{
298+
char temp[3];
299+
sprintf(temp, "%02x", pointPerfectTokenArray[x]);
300+
strcat(tokenString, temp);
301+
if (x == 3 || x == 5 || x == 7 || x == 9) strcat(tokenString, "-");
302+
}
300303
}
304+
else
305+
{
306+
//Use the user's custom token
307+
strcpy(tokenString, settings.pointPerfectDeviceProfileToken);
308+
Serial.printf("Using custom token: %s\n\r", tokenString);
309+
}
310+
301311
pointPerfectAPIPost["token"] = tokenString;
302312
pointPerfectAPIPost["givenName"] = givenName;
303313
pointPerfectAPIPost["hardwareId"] = hardwareID;

0 commit comments

Comments
 (0)