Hi Blynk Community,
I’m new to Blynk and ran into a problem. I’m using multiple Argon Particle boards with the Blynk app.
What I’ve Tried:
I’ve added the Auth tokens of each device in an array, along with their respective device IDs in another array, as shown below. The issue is that when I add a new device, I have to update both arrays, which can be cumbersome when flashing code.
Relevant Code Snippet:
#define BLYNK_TEMPLATE_ID "TMPxxxxxx"
#define BLYNK_TEMPLATE_NAME "Device"
const char* authTokens[] = {
"yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy",
"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
// "TOKEN_3"
};
const char* deviceIDs[] = {
"aaaaaaaaaaaaaaaaaaaaaaaa", // device 1
"bbbbbbbbbbbbbbbbbbbbbbbb", // device 2
// "DEVICE_ID_3"
};
int authTokenIndex = -1;
String myID = System.deviceID();
void blynkBegin() {
for (int i = 0; i < sizeof(deviceIDs) / sizeof(deviceIDs[0]); i++) {
if (myID == deviceIDs[i]) {
authTokenIndex = i;
break;
}
}
if (authTokenIndex >= 0) {
Blynk.begin(authTokens[authTokenIndex]);
} else {
Particle.publish("Error", "Device ID not found");
}
}
void setup() {
Serial.begin(115200);
blynkBegin();
// setup
}
void loop() {
Blynk.run();
// loop
}
Any advice would be greatly appreciated! Thanks!