Here's an interim solution stemming from Shannon's suggestion to get the MAC (which should be unique for each MKR1010). Here is a sketch (DisplayMAC.ino) to get the MAC:
#include <ArduinoIoTCloud.h>
void setup() {
Serial.begin(9600);
}
void loop() {
byte mac[5];
WiFi.macAddress(mac);
for (int i = 0; i < 5; i++) {
Serial.print("0x");
Serial.print(mac[i], HEX);
if (i < 4) {
Serial.print(", ");
} else {
Serial.println("");
}
}
delay(5000);
}
In a separate file (iot_things.h), paste the Things ID from Arduino Cloud and the MAC from the sketch above (this file can be gitignore'd):
const char THING_ID_G0[] = "c443ac0d-a86A-4f40-a83f-1ebb71b3cbdb";
const char THING_ID_G1[] = "d1f22913-a94c-4228-81d5-8f7374ba1c9e";
const byte MAC_G0[5] = { 0x48, 0x5A, 0x3C, 0x24, 0xBF };
const byte MAC_G1[5] = { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF };
That creates a MAC <-> Thing ID map. Then in the main ino file:
#include <iot_things.h>
...
void initIotProperties() {
byte mac[5];
WiFi.macAddress(mac);
bool doProperties = true;
if (memcmp(mac, MAC_G0, 5) == 0) {
ArduinoCloud.setThingId(THING_ID_G0);
} else if (memcmp(mac, MAC_G1, 5) == 0) {
ArduinoCloud.setThingId(THING_ID_G1);
} else {
doProperties = false; // no match, skip adding properties
}
if (doProperties) {
ArduinoCloud.addProperty(adcGrams, READ, 1 * SECONDS, NULL);
ArduinoCloud.addProperty(motorActive, READ, ON_CHANGE, NULL);
ArduinoCloud.addProperty(killSwitch, READWRITE, ON_CHANGE, onKillSwitchChange);
ArduinoCloud.addProperty(sdCard, READ, ON_CHANGE, NULL);
ArduinoCloud.addProperty(doClosedLoop, READ, ON_CHANGE, NULL);
ArduinoCloud.addProperty(temperature, READ, ON_CHANGE, NULL);
ArduinoCloud.addProperty(humidity, READ, ON_CHANGE, NULL);
ArduinoCloud.addProperty(version, READ, ON_CHANGE, NULL);
}
}
So every time there is a new cloud device, these things need to update, but at least it solves OAD/re-flashing headaches.