Welcome to the Particle community.
You could maintain 3 separate codebases, or you could include all tokens and names in the firmware and have the device pick its name and token from a table at run time.
The table could be represented using an array of structs:
#define BLYNK_DEVICES 3
struct Blynk {
char device_id[25];
char auth_token[33];
char blynk_name[21];
};
struct Blynk blynk_data[BLYNK_DEVICES] = {
{"0123456701xxxxxxxxxxxxxx", "9876543201xxxxxxxxxxxxxxxxxxxxxx", "device1"},
{"0123456702xxxxxxxxxxxxxx", "9876543202xxxxxxxxxxxxxxxxxxxxxx", "device2"},
{"0123456703xxxxxxxxxxxxxx", "9876543203xxxxxxxxxxxxxxxxxxxxxx", "device3"},
};
To retrieve the auth_token and blynk_name given a device_id, you could use the following:
char* auth_token = NULL;
char* blynk_name = NULL;
int get_blynk_data(const char* device_id) {
for (int i = 0; i < BLYNK_DEVICES; ++i) {
if (strcmp(blynk_data[i].device_id, device_id) == 0) {
auth_token = blynk_data[i].auth_token;
blynk_name = blynk_data[i].blynk_name;
return 0;
}
}
return 1;
}
Within your firmware you can use System.deviceID() to get the deviceID of the device. During early run time in the setup() function, you can pass the deviceID to get_blynk_data() to have the auth_token and blynk_name global variables set:
void setup() {
if (get_blynk_data(System.deviceID().c_str()) == 0) {
Serial.printf("Blynk Auth Token: %s, Blynk Name: %s\n", auth_token, blynk_name);
} else {
Serial.println("Failed to get blynk data!");
}
}
Afterwards, you can use auth_token and blynk_name anywhere in your application to refer to the data associated with the device currently running the firmware.
I don’t have a Particle device with me at the moment to test this on, but this approach should work.